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
13 changed files
with
124 additions
and
25 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
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,49 @@ | ||
import Link from "next/link"; | ||
import dayjs from "dayjs"; | ||
import relativeTime from "dayjs/plugin/relativeTime"; | ||
|
||
import { PostItem } from "@src/types"; | ||
import { getMemberByName, getHostFromURL } from "@src/utils/helper"; | ||
|
||
dayjs.extend(relativeTime); | ||
|
||
const PostLink: React.FC<{ item: PostItem }> = (props) => { | ||
const { authorName, title, isoDate, link } = props.item; | ||
const member = getMemberByName(authorName); | ||
if (!member) return null; | ||
|
||
return ( | ||
<article className="post-link"> | ||
<Link href={`/members/${member.name}`} passHref> | ||
<a className="post-link__author"> | ||
<img | ||
src={member.avatarSrc} | ||
className="post-link__author-img" | ||
width={35} | ||
height={35} | ||
/> | ||
<div className="post-link__author-name"> | ||
<div className="post-link__author-name">{member.name}</div> | ||
<time dateTime={isoDate} className="post-link__date"> | ||
{dayjs(isoDate).fromNow()} | ||
</time> | ||
</div> | ||
</a> | ||
</Link> | ||
<a href={link}> | ||
<h2 className="post-link__title">{title}</h2> | ||
<div className="post-link__host">{getHostFromURL(link)}</div> | ||
</a> | ||
</article> | ||
); | ||
}; | ||
|
||
export const PostList: React.FC<{ items: PostItem[] }> = (props) => { | ||
return ( | ||
<div className="post-list"> | ||
{props.items.map((item, i) => ( | ||
<PostLink key={`post-item-${i}`} item={item} /> | ||
))} | ||
</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
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
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
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,38 @@ | ||
.post-link { | ||
padding: 1.9rem 1.3rem; | ||
background: var(--color-base-background-lighter); | ||
} | ||
.post-link__author { | ||
display: flex; | ||
align-items: center; | ||
font-size: 13px; | ||
line-height: 1.4; | ||
} | ||
.post-link__date { | ||
color: var(--color-base-text-lighter); | ||
font-size: 12px; | ||
} | ||
.post-link__author-img { | ||
border-radius: 25%; | ||
margin-right: 0.7rem; | ||
} | ||
.post-link__title { | ||
margin-top: 1.2rem; | ||
font-size: 1.1rem; | ||
} | ||
|
||
.post-link__host { | ||
margin-top: 0.5em; | ||
color: var(--color-base-text-lighter); | ||
font-size: 0.85rem; | ||
} | ||
|
||
.post-list { | ||
display: flex; | ||
justify-content: space-between; | ||
flex-wrap: wrap; | ||
.post-link { | ||
margin-top: 4%; | ||
width: 31%; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
export type Member = { | ||
name: string; | ||
avatarFileName: string; | ||
avatarSrc: string; | ||
role?: string; | ||
bio?: string; | ||
sources?: string[]; | ||
}; | ||
|
||
export type PostItem = { | ||
authorName: string; | ||
title?: string; | ||
title: string; | ||
link: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { members } from "@members"; | ||
export function getMemberByName(name: string) { | ||
return members.find((member) => member.name === name); | ||
} | ||
export function getHostFromURL(str: string) { | ||
const url = new URL(str); | ||
return url?.hostname || "blog"; | ||
} |
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 |
---|---|---|
|
@@ -2333,6 +2333,11 @@ [email protected]: | |
dependencies: | ||
buffer-from "^1.1.1" | ||
|
||
dayjs@^1.9.3: | ||
version "1.9.3" | ||
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.9.3.tgz#b7f94b22ad2a136a4ca02a01ab68ae893fe1a268" | ||
integrity sha512-V+1SyIvkS+HmNbN1G7A9+ERbFTV9KTXu6Oor98v2xHmzzpp52OIJhQuJSTywWuBY5pyAEmlwbCi1Me87n/SLOw== | ||
|
||
debug@4, debug@^4.1.0, debug@^4.1.1: | ||
version "4.2.0" | ||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1" | ||
|