Skip to content

Commit c5ef0c7

Browse files
authored
Merge pull request #27 from oriverk/dev
Dev
2 parents 92b90e3 + 2571775 commit c5ef0c7

29 files changed

+3072
-1867
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ jobs:
1717
name: build and deploy to Cloudflare Pages
1818
steps:
1919
- name: checkout
20-
uses: actions/checkout@v3
20+
uses: actions/checkout@v4
2121

2222
# Run a build step here if your project requires
2323
- name: setup node
24-
uses: actions/setup-node@v3
24+
uses: actions/setup-node@v4
2525
with:
26-
node-version: 18
26+
node-version: 20
27+
28+
- name: create dotenv
29+
run: |
30+
touch .env
31+
echo "SECRET_GH_PAT={{ secrets.SECRET_GH_PAT }}" >> .env
2732
2833
- name: install packages and build
2934
run: |
@@ -33,6 +38,7 @@ jobs:
3338
env:
3439
MODE: production
3540
SECRET_GH_PAT: ${{ secrets.SECRET_GH_PAT }}
41+
3642
- name: deploy to Cloudflare Pages
3743
uses: cloudflare/pages-action@v1
3844
with:

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
- Svelte
88
- unified, remark, rehype ...
99
- @octokit/graphql
10-
- algoliasearch
1110
- devDependencies
1211
- husky
1312
- biomejs

package-lock.json

Lines changed: 2760 additions & 1588 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
"scripts": {
2020
"clean": "rm -r ./contents/*.json ./src/content/static/cv.md",
2121
"script": "run-s script:*",
22-
"script:feed": "node script/getFeed.mjs",
23-
"script:github": "node -r dotenv/config script/getGitHubUserContent.mjs",
24-
"script:cv": "node -r dotenv/config script/getGitHubRepositoryContent.mjs",
22+
"script:feed": "npx tsx script/getFeed.mts",
23+
"script:github": "npx tsx --env-file=.env script/getGitHubUserContent.mts",
24+
"script:cv": "npx tsx --env-file=.env script/getGitHubRepositoryContent.mts",
2525
"astro": "astro",
2626
"sync": "astro sync",
2727
"dev": "astro dev",
@@ -41,16 +41,15 @@
4141
"prepare": "husky"
4242
},
4343
"dependencies": {
44-
"@astrojs/mdx": "^4.0.0-beta.1",
45-
"@astrojs/rss": "^4.0.7",
46-
"@astrojs/svelte": "^6.0.0-beta.0",
44+
"@astrojs/mdx": "^4.0.0-beta.2",
45+
"@astrojs/rss": "^4.0.8",
46+
"@astrojs/svelte": "^6.0.0-beta.1",
4747
"@expressive-code/plugin-line-numbers": "^0.37.0",
4848
"@octokit/graphql": "^8.1.1",
49-
"astro": "^5.0.0-beta.2",
49+
"astro": "^5.0.0-beta.4",
5050
"astro-expressive-code": "^0.37.0",
5151
"clsx": "^2.1.1",
5252
"date-fns": "^4.1.0",
53-
"dotenv": "^16.4.5",
5453
"fetch-site-metadata": "^0.2.0",
5554
"gray-matter": "^4.0.3",
5655
"hast": "^1.0.0",
@@ -61,7 +60,7 @@
6160
"remark-comment": "^1.0.0",
6261
"remark-github-alerts": "^0.1.0-beta.3",
6362
"rss-parser": "^3.13.0",
64-
"satori": "^0.11.1",
63+
"satori": "^0.11.2",
6564
"sharp": "^0.33.5",
6665
"strip-markdown": "^6.0.0",
6766
"svelte": "^5.0.0-next.259",
@@ -72,19 +71,18 @@
7271
"url-join": "^5.0.0"
7372
},
7473
"devDependencies": {
75-
"@biomejs/biome": "1.9.2",
74+
"@biomejs/biome": "1.9.3",
7675
"@commitlint/cli": "^19.5.0",
7776
"@commitlint/config-conventional": "^19.5.0",
78-
"@octokit/graphql-schema": "^15.25.0",
7977
"@proofdict/textlint-rule-proofdict": "^3.1.2",
80-
"@textlint/textlint-plugin-markdown": "^14.2.0",
78+
"@textlint/textlint-plugin-markdown": "^14.2.1",
8179
"@types/fs-extra": "^11.0.4",
82-
"@types/node": "^22.7.0",
80+
"@types/node": "^22.7.5",
8381
"fs-extra": "^11.2.0",
8482
"husky": "^9.1.6",
8583
"markdownlint-cli": "^0.42.0",
8684
"npm-run-all2": "^6.2.3",
87-
"textlint": "^14.2.0",
85+
"textlint": "^14.2.1",
8886
"textlint-filter-rule-allowlist": "^4.0.0",
8987
"textlint-plugin-latex2e": "^1.2.1",
9088
"textlint-rule-aws-service-name": "^1.11.0",
@@ -94,7 +92,7 @@
9492
"textlint-rule-period-in-list-item": "^1.0.1",
9593
"textlint-rule-preset-ja-spacing": "^2.4.3",
9694
"textlint-rule-preset-ja-technical-writing": "^10.0.1",
97-
"ts-node": "^10.9.2"
95+
"tsx": "^4.19.1"
9896
},
9997
"overrides": {
10098
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6"

public/assets/qiita-icon.png

8.94 KB
Loading

script/getFeed.mjs renamed to script/getFeed.mts

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
import fs from "node:fs";
22
import Parser from 'rss-parser'
33

4-
/**
5-
* @typedef {Object} Source
6-
* @property {string} id
7-
* @property {string} url
8-
* @property {string} includeUrlRegex
9-
*/
4+
type Source = {
5+
id: string;
6+
url: string;
7+
includeUrlRegex?: string;
8+
}
9+
10+
// [rbren/rss-parser: A lightweight RSS parser, for Node and the browser](https://github.com/rbren/rss-parser?tab=readme-ov-file#typescript)
11+
type CustomFeed = {
12+
foo: string;
13+
}
1014

11-
/**
12-
* @typedef {Object} FeedItem
13-
* @property {string} title
14-
* @property {string} link
15-
* @property {string} contentSnippet
16-
* @property {string} isoDate
17-
* @property {number} dateMiliSeconds
18-
*/
15+
type FeedItem = {
16+
id: string;
17+
title: string;
18+
link: string;
19+
contentSnippet: string;
20+
isoDate: string;
21+
dateMiliSeconds: number;
22+
}
1923

2024
const sources = [
2125
{
@@ -24,11 +28,7 @@ const sources = [
2428
},
2529
];
2630

27-
/**
28-
* @param {string} url
29-
* @returns {boolean}
30-
*/
31-
function isValidUrl(url) {
31+
function isValidUrl(url: string) {
3232
try {
3333
const {protocol} = new URL(url);
3434
return protocol === 'http:' || protocol === 'https:';
@@ -37,47 +37,41 @@ function isValidUrl(url) {
3737
}
3838
}
3939

40-
const parser = new Parser();
4140

42-
/**
43-
* @param {string} url
44-
* @returns {FeedItem[]}
45-
*/
46-
async function fetchFeedItems(url) {
41+
const parser: Parser<CustomFeed,FeedItem> = new Parser();
42+
43+
async function fetchFeedItems(url: string) {
4744
const feed = await parser.parseURL(url);
4845

4946
if(!feed?.items?.length) return []
5047

51-
return feed.items
48+
const results = feed.items
49+
.filter(({link}) => link && isValidUrl(link))
5250
.map(({ title, contentSnippet, link, isoDate }) => {
5351
return {
52+
id: link,
5453
title,
5554
contentSnippet: contentSnippet?.replace(/\n/g, ""),
5655
link,
5756
isoDate,
5857
dateMiliSeconds: isoDate ? new Date(isoDate).getTime() : 0,
5958
};
6059
})
61-
.filter(
62-
({ title, link }) => title && link && isValidUrl(link)
63-
)
60+
61+
return results
6462
}
6563

66-
/**
67-
* @param {Source[]} sources
68-
* @returns {FeedItem[]}
69-
*/
70-
async function getFeedItemsFromSources(sources) {
64+
async function getFeedItemsFromSources(sources: Source[]) {
7165
if (!sources.length) return [];
7266

73-
let feedItems = [];
67+
let feedItems: FeedItem[] = [];
7468
for (const source of sources) {
7569
const { url, includeUrlRegex } = source;
7670
let items = await fetchFeedItems(url);
7771

7872
if (includeUrlRegex) {
7973
items = items.filter(item => {
80-
return item.link.match(new RegExp(includeUrlRegex))
74+
return item.link?.match(new RegExp(includeUrlRegex))
8175
})
8276
}
8377

script/getGitHubRepositoryContent.mjs renamed to script/getGitHubRepositoryContent.mts

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { format } from 'date-fns'
33
import fs from "node:fs"
44

55
/**
6-
* @param {string} birthdate '2020-01-01'
7-
* @returns {number}
6+
* @param birthdate '2020-01-01'
7+
* @returns
88
*/
9-
function getAge(birthdate) {
9+
function getAge(birthdate: string) {
1010
const today = new Date()
1111
const birthDate = new Date(birthdate)
1212
let age = today.getFullYear() - birthDate.getFullYear()
@@ -17,37 +17,30 @@ function getAge(birthdate) {
1717
return age
1818
}
1919

20+
type Content = {
21+
repository: {
22+
object: {
23+
text: string;
24+
}
25+
}
26+
}
27+
2028
/**
21-
* @param {string} githubToken
22-
* @param {string} owner userid
23-
* @param {number} pinnedItemsNum
24-
* @param {string} calendarFrom new Date().toISOString().split(".")[0]
25-
* @param {string} calendarTo "2023-04-01T00:00:00"
26-
* @returns {import("@octokit/graphql-schema").Repository}
29+
* @param githubToken
30+
* @param owner userid
31+
* @param repo userid-docs
32+
* @param expression HEAD:cv/index.md
33+
* @returns
2734
*/
28-
async function fetchRepositoryContent(githubToken, owner, repo, expression) {
35+
async function fetchRepositoryContent(githubToken: string, owner: string, repo: string, expression: string) {
2936
try {
30-
if (!githubToken) {
31-
throw new Error('Token is Not Found')
32-
}
33-
34-
const { repository } = await graphql(`
37+
const { repository } = await graphql<Content>(`
3538
query content($owner: String!, $repo: String!, $expression: String!) {
3639
repository(owner: $owner, name: $repo) {
3740
object(expression: $expression) {
3841
... on Blob {
3942
text
4043
}
41-
# ... on Tree {
42-
# entries {
43-
# name
44-
# object {
45-
# ... on Blob {
46-
# text
47-
# }
48-
# }
49-
# }
50-
# }
5144
}
5245
}
5346
}
@@ -84,9 +77,9 @@ async function fetchRepositoryContent(githubToken, owner, repo, expression) {
8477
}
8578

8679
const repository = await fetchRepositoryContent(token, owner, repositoryName, repositoryExpression)
87-
/** @type import("@octokit/graphql-schema").Blob */
88-
const { text } = repository.object;
89-
80+
if(!repository) return;
81+
82+
const { text } = repository.object
9083
const replacedMd = text
9184
.replace('{{ age }}', getAge('1993-09-11').toString())
9285
.replace('{{ date }}', format(new Date(), 'yyyy年MM月dd日'))

script/getGitHubUserContent.mjs renamed to script/getGitHubUserContent.mts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import { graphql, GraphqlResponseError } from '@octokit/graphql'
22
import { subYears, startOfWeek, format } from 'date-fns'
33
import fs from "node:fs"
4+
import type { PinnedItem, ContributionCalendar } from '@/types/github';
5+
6+
type UserContent = {
7+
user: {
8+
pinnedItems: {
9+
nodes: PinnedItem[]
10+
};
11+
contributionsCollection: {
12+
contributionCalendar: ContributionCalendar;
13+
};
14+
};
15+
};
416

517
/**
6-
* @param {string} githubToken
7-
* @param {string} owner userid
8-
* @param {number} pinnedItemsNum
9-
* @param {string} calendarFrom new Date().toISOString().split(".")[0]
10-
* @param {string} calendarTo "2023-04-01T00:00:00"
11-
* @returns {import("@octokit/graphql-schema").User}
18+
* @param githubToken
19+
* @param owner userid
20+
* @param pinnedItemsNum
21+
* @param calendarFrom new Date().toISOString().split(".")[0]
22+
* @param calendarTo "2023-04-01T00:00:00"
23+
* @returns
1224
*/
13-
async function fetchUserContent(githubToken, owner, pinnedItemsNum, calendarFrom, calendarTo,) {
25+
async function fetchUserContent(githubToken: string, owner: string, pinnedItemsNum: number, calendarFrom: string, calendarTo: string) {
1426
try {
15-
if (!githubToken) {
16-
throw new Error('githubToken is not defined')
17-
}
18-
19-
const { user } = await graphql(`
27+
const { user } = await graphql<UserContent>(`
2028
query userContent($owner: String!, $pinnedItemsNum: Int = 4, $calendarFrom: DateTime!, $calendarTo: DateTime!) {
2129
user(login: $owner) {
2230
pinnedItems(first: $pinnedItemsNum) {
@@ -38,7 +46,6 @@ async function fetchUserContent(githubToken, owner, pinnedItemsNum, calendarFrom
3846
contributionsCollection(from: $calendarFrom, to: $calendarTo) {
3947
contributionCalendar {
4048
totalContributions
41-
isHalloween
4249
weeks {
4350
firstDay
4451
contributionDays {
@@ -79,12 +86,11 @@ async function fetchUserContent(githubToken, owner, pinnedItemsNum, calendarFrom
7986

8087
;(async () => {
8188
const token = process.env.SECRET_GH_PAT || "";
82-
const owner = "oriverk"
83-
8489
if (!token) {
8590
return console.log('Env is Not Found.')
8691
}
8792

93+
const owner = "oriverk"
8894
const lastYear = subYears(new Date(), 1)
8995
const start = startOfWeek(lastYear, { weekStartsOn: 0 })
9096
const from = `${format(start, 'yyyy-MM-dd')}T00:00:00`
@@ -96,14 +102,22 @@ async function fetchUserContent(githubToken, owner, pinnedItemsNum, calendarFrom
96102
return;
97103
}
98104

99-
/** @type {import("@octokit/graphql-schema").User} */
100105
const { pinnedItems, contributionsCollection } = user
101106
if (!fs.existsSync(".contents")) {
102107
fs.mkdirSync(".contents");
103108
}
109+
110+
const repositories = []
111+
for (const {url, ...rest} of pinnedItems.nodes) {
112+
repositories.push({
113+
id: url,
114+
url,
115+
...rest
116+
})
117+
}
104118
fs.writeFileSync(
105119
".contents/repository.json",
106-
JSON.stringify(pinnedItems.nodes || [], null, 2)
120+
JSON.stringify(repositories, null, 2)
107121
);
108122
fs.writeFileSync(
109123
".contents/contributions.json",

0 commit comments

Comments
 (0)