Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a directory page to show authors #99

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const Header = () => {
<Link href="/page/random" passHref>
<Button>Đọc ngẫu nhiên</Button>
</Link>

<Link href="/author" passHref>
<Button>Về chúng tôi</Button>
</Link>

<Button
onClick={onToggleTheme}
icon={theme === 'light' ? HiOutlineMoon : HiOutlineSun}
Expand Down
42 changes: 42 additions & 0 deletions pages/author/Author.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,48 @@
box-shadow: var(--shadow-1);
}

.blogPage h3 {
color: var(--text-normal);
margin-bottom: 40px;
}

.blogPage {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

.blogAuthors {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: flex-start;
align-items: center;
gap: 20px 0px;
}

.blogAuthor {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: var(--spacing-base);
}

.blogAvatar {
width: 60px;
height: 60px;
border: 1px solid var(--gray-1);
border-radius: 50%;
margin-right: 10px;
overflow: hidden;
}

.blogInfo a {
font-size: 14px;
font-weight: 300;
}

.profileDetails {
color: var(--text-normal);
display: flex;
Expand Down
68 changes: 68 additions & 0 deletions pages/author/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import channelsData from '@/channels.json';
import Layout from '@/components/Layout';
import { Author } from '@/types/sharedTypes';
import { getAvatarUrl, getHostName } from '@/utils/url';
import { GetStaticProps } from 'next';
import Image from 'next/image';
import Link from 'next/link';
import styles from './Author.module.css';

export const getStaticProps: GetStaticProps = async (context) => {
return {
props: {
authors: channelsData.channels
}
};
};

interface AuthorProps {
authors: Author[];
}

const AuthorPage = ({ authors }: AuthorProps) => {
const renderAuthor = (author: Author) => {
const { name, avatar_url, url } = author;
const hostName = getHostName(url);
const blogUrl = `https://${hostName}`;

return (
<div className={styles.blogAuthor}>
<div className={styles.blogAvatar}>
<Image
alt={name}
src={getAvatarUrl(avatar_url)}
width={60}
height={60}
/>
</div>
<div className={styles.blogInfo}>
<Link href={blogUrl} passHref>
<a>{name}</a>
</Link>
</div>
</div>
);
};

return (
<Layout>
<div className={styles.blogPage}>
<h3>Xin cảm ơn sự đóng góp của các tác giả</h3>
<div className={styles.blogAuthors}>
{authors.map((author, idx) => (
<div
key={idx}
style={{
width: '20%'
}}
>
{renderAuthor(author)}
</div>
))}
</div>
</div>
</Layout>
);
};

export default AuthorPage;