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.
Merge pull request #34 from p12-sandbox/refactor/ESlint-error
Refactor/e slint error
- Loading branch information
Showing
27 changed files
with
1,329 additions
and
1,767 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
"extends": ["next", "next/core-web-vitals"] | ||
} |
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,5 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
singleQuote: true, | ||
semi: false, | ||
} |
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,9 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"[javascript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
} |
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
Empty file.
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 |
---|---|---|
@@ -1,82 +1,81 @@ | ||
import fs from "fs-extra"; | ||
import Parser from "rss-parser"; | ||
import { members } from "../../members"; | ||
import { PostItem, Member } from "../types"; | ||
export default {}; | ||
import fs from 'fs-extra' | ||
import Parser from 'rss-parser' | ||
import { members } from '../../members' | ||
import { PostItem, Member } from '../types' | ||
|
||
type FeedItem = { | ||
title: string; | ||
link: string; | ||
contentSnippet?: string; | ||
isoDate?: string; | ||
dateMiliSeconds: number; | ||
}; | ||
title: string | ||
link: string | ||
contentSnippet?: string | ||
isoDate?: string | ||
dateMiliSeconds: number | ||
} | ||
|
||
const parser = new Parser(); | ||
let allPostItems: PostItem[] = []; | ||
const parser = new Parser() | ||
let allPostItems: PostItem[] = [] | ||
|
||
async function fetchFeedItems(url: string) { | ||
const feed = await parser.parseURL(url); | ||
if (!feed?.items?.length) return []; | ||
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, ""), | ||
contentSnippet: contentSnippet?.replace(/\n/g, ''), | ||
link, | ||
isoDate, | ||
dateMiliSeconds: isoDate ? new Date(isoDate).getTime() : 0, | ||
}; | ||
} | ||
}) | ||
.filter(({ title, link }) => title && link) as FeedItem[]; | ||
.filter(({ title, link }) => title && link) as FeedItem[] | ||
} | ||
|
||
async function getFeedItemsFromSources(sources: undefined | string[]) { | ||
if (!sources?.length) return []; | ||
let feedItems: FeedItem[] = []; | ||
if (!sources?.length) return [] | ||
let feedItems: FeedItem[] = [] | ||
for (const url of sources) { | ||
const items = await fetchFeedItems(url); | ||
if (items) feedItems = [...feedItems, ...items]; | ||
const items = await fetchFeedItems(url) | ||
if (items) feedItems = [...feedItems, ...items] | ||
} | ||
return feedItems; | ||
return feedItems | ||
} | ||
|
||
async function getMemberFeedItems(member: Member): Promise<PostItem[]> { | ||
const { id, sources, name, includeUrlRegex, excludeUrlRegex } = member; | ||
const feedItems = await getFeedItemsFromSources(sources); | ||
if (!feedItems) return []; | ||
const { id, sources, name, includeUrlRegex, excludeUrlRegex } = member | ||
const feedItems = await getFeedItemsFromSources(sources) | ||
if (!feedItems) return [] | ||
|
||
let postItems = feedItems.map((item) => { | ||
return { | ||
...item, | ||
authorName: name, | ||
authorId: id, | ||
}; | ||
}); | ||
} | ||
}) | ||
// remove items which not matches includeUrlRegex | ||
if (includeUrlRegex) { | ||
postItems = postItems.filter((item) => { | ||
return item.link.match(new RegExp(includeUrlRegex)); | ||
}); | ||
return item.link.match(new RegExp(includeUrlRegex)) | ||
}) | ||
} | ||
// remove items which matches excludeUrlRegex | ||
if (excludeUrlRegex) { | ||
postItems = postItems.filter((item) => { | ||
return !item.link.match(new RegExp(excludeUrlRegex)); | ||
}); | ||
return !item.link.match(new RegExp(excludeUrlRegex)) | ||
}) | ||
} | ||
|
||
return postItems; | ||
return postItems | ||
} | ||
|
||
(async function () { | ||
;(async function () { | ||
for (const member of members) { | ||
const items = await getMemberFeedItems(member); | ||
if (items) allPostItems = [...allPostItems, ...items]; | ||
const items = await getMemberFeedItems(member) | ||
if (items) allPostItems = [...allPostItems, ...items] | ||
} | ||
allPostItems.sort((a, b) => b.dateMiliSeconds - a.dateMiliSeconds); | ||
fs.ensureDirSync(".contents"); | ||
fs.writeJsonSync(".contents/posts.json", allPostItems); | ||
})(); | ||
allPostItems.sort((a, b) => b.dateMiliSeconds - a.dateMiliSeconds) | ||
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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
export const ContentWrapper: React.FC<{ children: React.ReactNode }> = ( | ||
props | ||
) => { | ||
return <div className="content-wrapper">{props.children}</div>; | ||
}; | ||
export const ContentWrapper: React.FC<{ children: React.ReactNode }> = (props) => { | ||
return <div className="content-wrapper">{props.children}</div> | ||
} | ||
|
||
export const UndoWrapForScroll: React.FC<{ | ||
children: React.ReactNode; | ||
children: React.ReactNode | ||
}> = (props) => { | ||
return <div className="undo-wrap-for-scroll">{props.children}</div>; | ||
}; | ||
return <div className="undo-wrap-for-scroll">{props.children}</div> | ||
} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Link from "next/link"; | ||
import Link from 'next/link' | ||
|
||
export const LinkBackHome: React.FC = () => ( | ||
<Link href="/" passHref> | ||
<a className="link-back-home">Back Home</a> | ||
</Link> | ||
); | ||
) |
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
Oops, something went wrong.