티스토리 깃헙 연동하기
티스토리에 글을 쓸때 깃헙에 잔디를 심기위해 연동했다.
1. Tistory RSS 설정
우선 Tistory RSS를 설정해준다.
설정해주는 방법은
Tistory 관리자 > 관리 > 블로그 > 기타 설정 항목으로 들어가서
아래와 같이 해주면 된다.
제대로 됐는지 확인하려면
https://leejaehoon.tistory.com/rss와 같이
자기주소 뒤에 /rss를 넣어서 아래와 같이 접속이 된다면 성공.
2. 로컬파일 만들기
2-1 이제 로컬에 원하는 폴더에 아래 코드를 순서대로 입력한다.
npm init -y
npm i rss-parser
2-2 만들어진 package.json을 아래와 같이 작성한다.
{
"name": "tistory_github",
"version": "1.0.0",
"description": "",
"main": "readmeUpdate.js",
"type": "module",
"scripts": {
"start": "node readmeUpdate.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"rss-parser": "^3.13.0"
}
}
2-3 이제 폴더안에 readmeUpdate.js를 만들고 아래 코드를 입력한다.(34번째줄 본인주소로 변경)
import { writeFileSync } from "node:fs";
import Parser from "rss-parser";
/**
* README.MD에 작성될 페이지 텍스트
* @type {string}
*/
let text = `# Hi there 👋
## 이런 환경에 익숙해요✍🏼
## 언어
<p>
<img alt="" src= "https://img.shields.io/badge/JavaScript-F7DF1E?style=flat-square&logo=JavaScript&logoColor=white"/>
<img alt="" src= "https://img.shields.io/badge/TypeScript-black?logo=typescript&logoColor=blue"/>
</p>
## Contact me
## 📕 Latest Blog Posts
`;
// rss-parser 생성
const parser = new Parser({
headers: {
Accept: "application/rss+xml, application/xml, text/xml; q=0.1",
},
});
(async () => {
// 피드 목록
const feed = await parser.parseURL("https://leejaehoon.tistory.com/rss");
// 최신 5개의 글의 제목과 링크를 가져온 후 text에 추가
for (let i = 0; i < 5; i++) {
const { title, link } = feed.items[i];
console.log(`${i + 1}번째 게시물`);
console.log(`추가될 제목: ${title}`);
console.log(`추가될 링크: ${link}`);
text += `<a href=${link}>${title}</a></br>`;
}
// README.md 파일 작성
writeFileSync("README.md", text, "utf8", (e) => {
console.log(e);
});
console.log("업데이트 완료");
})();
2-4 루트에 .github 이라는 폴더를 생성하고 그안에 workflows라는 폴더를 만들고 안에 main.yaml파일을 생성한다.
2-4 main.yaml파일에 아래와 같이 입력한다. (코드 27~28줄 본인 깃헙 주소로 변경)
# This is a basic workflow to help you get started with Actions
name: Readme Update
# Controls when the workflow will run
on:
# 1시간에 한번씩 아래 스크립트를 실행한다.
schedule:
- cron: "0 0 * * *"
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install dependencies
run: npm ci
- name: Update README
run: npm start
- name: Commit README
run: |
git add .
git config --local user.email "kaak2203@naver.com"
git config --local user.name "ejehoon"
git commit -m "Update README.md"
git push
2-4 이제 깃헙에 레포지를 만들고 push하면 완료.
오류해결
성공한지 알았는데 실패했다는 네이버 메일이 왔다. 사진과 같은 오류고 권한문제로 아래는 해결방법이다.
우선 내가 만들었던 레퍼지토리로 간다.
그 후 Settings > Actions > general로 들어가면
제일 마지막에 Workflow permissions를 Read and write permissions로 바꿔주면 된다.
그렇게하면 완료~
반응형
'IT > Github' 카테고리의 다른 글
[github]error: origin 리모트가 이미 있습니다. (0) | 2024.02.02 |
---|