Skip to content

Commit b01ead7

Browse files
committed
Add gh action
1 parent 2418533 commit b01ead7

5 files changed

Lines changed: 112 additions & 1 deletion

File tree

.github/workflows/fetch-medium.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Build & Deploy GH Page
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
schedule:
8+
- cron: "0 3 * * 0" # every Sunday at 03:00 UTC
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: 22
22+
cache: "npm"
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Fetch Medium posts
28+
env:
29+
GH_USERNAME: ${{ github.repository_owner }}
30+
run: node scripts/fetch-medium.js
31+
32+
- name: Build Astro site
33+
run: npm run build
34+
35+
- name: Deploy to GitHub Pages
36+
uses: peaceiris/actions-gh-pages@v6
37+
with:
38+
github_token: ${{ secrets.GITHUB_TOKEN }}
39+
publish_dir: ./dist
40+
commit_message: "Deploy Astro portfolio"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ pnpm-debug.log*
2323
# jetbrains setting folder
2424
.idea/
2525

26-
.vscode
26+
.vscode
27+
src/data/

scripts/fetch-medium.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import Parser from "rss-parser";
4+
import "dotenv/config";
5+
6+
const username = process.env.GH_USERNAME;
7+
if (!username) throw new Error("GH_USERNAME environment variable is required");
8+
9+
const feedUrl = `https://medium.com/feed/@${username}`;
10+
const parser = new Parser();
11+
const outputDir = "src/data";
12+
const outputFile = path.join(outputDir, "posts.json");
13+
14+
async function fetchPosts() {
15+
const feed = await parser.parseURL(feedUrl);
16+
17+
const posts = feed.items.map((item) => ({
18+
title: item.title || "Untitled",
19+
link: item.link || "#",
20+
pubDate: item.pubDate || new Date().toISOString(),
21+
}));
22+
23+
if (!fs.existsSync(outputDir)) {
24+
fs.mkdirSync(outputDir, { recursive: true });
25+
}
26+
27+
fs.writeFileSync(outputFile, JSON.stringify(posts, null, 2));
28+
console.log(`Fetched ${posts.length} posts to ${outputFile}`);
29+
}
30+
31+
fetchPosts().catch((err) => {
32+
console.error(err);
33+
process.exit(1);
34+
});

src/data/posts.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"title": "Danebook Debrief, What I Learned Building a Bigger Rails App",
4+
"link": "https://medium.com/@khopsickle/danebook-debrief-what-i-learned-building-a-bigger-rails-app-c5ec502a48cd?source=rss-cc63be7ad3af------2",
5+
"pubDate": "Sun, 22 Jan 2017 21:02:19 GMT"
6+
},
7+
{
8+
"title": "Palindrome Permutations",
9+
"link": "https://medium.com/@khopsickle/palindrome-permutations-ac2618b1d8c5?source=rss-cc63be7ad3af------2",
10+
"pubDate": "Thu, 05 Jan 2017 21:01:49 GMT"
11+
},
12+
{
13+
"title": "Products of an Array",
14+
"link": "https://medium.com/@khopsickle/products-of-an-array-a42925038c01?source=rss-cc63be7ad3af------2",
15+
"pubDate": "Sun, 27 Nov 2016 19:58:39 GMT"
16+
},
17+
{
18+
"title": "3 weeks of Viking, a post-mortem",
19+
"link": "https://medium.com/@khopsickle/3-weeks-of-viking-a-post-mortem-bdbc27e71e44?source=rss-cc63be7ad3af------2",
20+
"pubDate": "Mon, 21 Nov 2016 15:23:50 GMT"
21+
},
22+
{
23+
"title": "2 Eggs and 100 Floors",
24+
"link": "https://medium.com/@khopsickle/2-eggs-and-100-floors-a032beb77aaa?source=rss-cc63be7ad3af------2",
25+
"pubDate": "Mon, 14 Nov 2016 02:07:08 GMT"
26+
},
27+
{
28+
"title": "WTM Tucson Hackathon 2016",
29+
"link": "https://medium.com/@khopsickle/wtm-tucson-hackathon-2016-ef1727f128d7?source=rss-cc63be7ad3af------2",
30+
"pubDate": "Sat, 05 Nov 2016 19:13:01 GMT"
31+
}
32+
]

src/pages/index.astro

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
---
22
import "./styles/global.css";
3+
import posts from '../data/posts.json';
4+
5+
const firstPost = posts.length > 0 ? posts[0] : null;
36
---
47

58
<html lang="en">
@@ -13,5 +16,6 @@ import "./styles/global.css";
1316
</head>
1417
<body>
1518
<h1>Astro</h1>
19+
<p>Under construction! {firstPost.title}</p>
1620
</body>
1721
</html>

0 commit comments

Comments
 (0)