forked from catnose99/team-blog-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
478 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,3 +32,6 @@ yarn-error.log* | |
|
||
# vercel | ||
.vercel | ||
|
||
# generated data | ||
/.contents |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Member } from "@src/types"; | ||
|
||
export const members: Member[] = [ | ||
{ | ||
name: "CatNose", | ||
role: "CTO", | ||
bio: | ||
"デザインが好きなプログラマー。開発者向けの情報共有プラットフォームzenn.devを開発しています。", | ||
avatarFileName: "catnose.jpg", | ||
sources: [ | ||
"https://zenn.dev/catnose99/feed", | ||
"https://note.com/catnose/rss", | ||
], | ||
}, | ||
{ | ||
name: "John Doe", | ||
role: "SRE", | ||
bio: "Site Reliability Engineer.", | ||
avatarFileName: "doe.jpg", | ||
sources: ["https://zenn.dev/zenn/feed"], | ||
}, | ||
{ | ||
name: "Amanda", | ||
role: "Frontend dev", | ||
bio: "Frontend developer,", | ||
avatarFileName: "amanda.jpg", | ||
sources: ["https://medium.com/feed/@Medium"], | ||
}, | ||
{ | ||
name: "Takada Junji", | ||
role: "Designer", | ||
bio: "Designing all of the apps in Foo company.", | ||
avatarFileName: "junji.jpg", | ||
sources: [], | ||
}, | ||
{ | ||
name: "Ota Naoko", | ||
role: "Researcher", | ||
bio: "Some texts here", | ||
avatarFileName: "naoko.jpg", | ||
sources: [], | ||
}, | ||
{ | ||
name: "Alexandria", | ||
role: "Tech Lead", | ||
bio: "IT professional with 3 years of experience", | ||
avatarFileName: "alexandria.jpg", | ||
sources: [], | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const config = { | ||
siteMeta: { | ||
title: "Foo Tech Blog", | ||
description: "A RSS based blog template for teams.", | ||
}, | ||
headerLinks: [ | ||
{ | ||
title: "About", | ||
href: "/about", | ||
}, | ||
{ | ||
title: "Company", | ||
href: "https://zenn.dev", | ||
}, | ||
{ | ||
title: "GitHub", | ||
href: "https://rss-based-blog.com", | ||
}, | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import fs from "fs-extra"; | ||
import Parser from "rss-parser"; | ||
import { members } from "../../members"; | ||
import { PostItem, Member } from "../types"; | ||
export default {}; | ||
|
||
type FeedItem = { | ||
title: string; | ||
link: string; | ||
contentSnippet?: string; | ||
isoDate?: string; | ||
}; | ||
|
||
const parser = new Parser(); | ||
let allPostItems: PostItem[] = []; | ||
|
||
async function fetchFeedItems(url: string) { | ||
const feed = await parser.parseURL(url); | ||
if (!feed?.items?.length) return []; | ||
|
||
// return item which has title and link | ||
return feed.items | ||
.map(({ title, contentSnippet, link, isoDate }) => { | ||
return { | ||
title, | ||
contentSnippet: contentSnippet?.replace(/\n/g, ""), | ||
link, | ||
isoDate, | ||
}; | ||
}) | ||
.filter(({ title, link }) => title && link) as FeedItem[]; | ||
} | ||
|
||
async function getFeedItemsFromSources(sources: undefined | string[]) { | ||
if (!sources?.length) return []; | ||
let feedItems: FeedItem[] = []; | ||
for (const url of sources) { | ||
const items = await fetchFeedItems(url); | ||
if (items) feedItems = [...feedItems, ...items]; | ||
} | ||
return feedItems; | ||
} | ||
|
||
async function getMemberFeedItems(member: Member): Promise<PostItem[]> { | ||
const feedItems = await getFeedItemsFromSources(member.sources); | ||
if (!feedItems) return []; | ||
|
||
return feedItems.map((item) => { | ||
return { | ||
...item, | ||
authorName: member.name, | ||
}; | ||
}); | ||
} | ||
|
||
(async function () { | ||
for (const member of members) { | ||
const items = await getMemberFeedItems(member); | ||
if (items) allPostItems = [...allPostItems, ...items]; | ||
} | ||
fs.ensureDirSync(".contents"); | ||
fs.writeJsonSync(".contents/posts.json", allPostItems); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export type Member = { | ||
name: string; | ||
avatarFileName: string; | ||
role?: string; | ||
bio?: string; | ||
sources?: string[]; | ||
}; | ||
|
||
export type PostItem = { | ||
authorName: string; | ||
title?: string; | ||
contentSnippet?: string; | ||
link?: string; | ||
isoDate?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"outDir": "dist", | ||
"noEmit": false | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["src/rss-builder/*.ts"] | ||
} |
Oops, something went wrong.