Skip to content

Commit

Permalink
feat: add authors to page
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantotone committed Jan 29, 2024
1 parent ddddcaf commit 2c60eb9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/app/article/[slug]/article.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@

.content img {
max-width: 100%;
}

.authors {
display: flex;
gap: 25px;
flex-wrap: wrap;
margin: 30px 0;
}
7 changes: 7 additions & 0 deletions src/app/article/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { articleTypes, getArticle } from '@/utils/news';
import { NEWS_DEFAULT_BANNER, NEWS_IMAGES_URL } from '@/utils/constants';
import Footer from '@/components/Footer';
import Markdown from 'react-markdown';
import Author from '@/components/News/Author';

type Props = {
params: {
Expand All @@ -30,6 +31,12 @@ const ArticlePage: React.FC<Props> = async ({ params }) => {
</Header>

<main className={styles.main}>
<div className={styles.authors}>
{
article.authors.map(author => <Author key={author.displayName} {...author} />)
}
</div>

<div className={styles.content}>
<Markdown>{article.content}</Markdown>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
--maxWidth: 1200px;

--background: white;
--foreground: #333;
--foreground: #7A7A7A;;

--heroBackground: #060811;
--headerBackground: #05060B;
Expand Down Expand Up @@ -37,6 +37,6 @@ a {
main {
position: relative;
margin: 0 auto;
width: 90%;
width: 80%;
max-width: var(--max-width);
}
22 changes: 22 additions & 0 deletions src/components/News/Author/author.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.author {
display: flex;
gap: 15px;
align-items: center;
}

.author .avatar {
display: flex;
align-items: center;

border-radius: 100%;
width: 48px;
aspect-ratio: 1;
}

.author .info .name {
font-weight: 600;
}

.author .info .role {
font-size: 0.7em;
}
23 changes: 23 additions & 0 deletions src/components/News/Author/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { NEWS_IMAGES_URL } from "@/utils/constants";
import styles from "./author.module.css";
import Image from "next/image";

type Props = {
displayName: string,
avatar?: string,
role?: string,
}

const Author: React.FC<Props> = ({ displayName, avatar, role }) => {
return <div className={styles.author}>
<div className={styles.avatar}>
<Image src={`${NEWS_IMAGES_URL}/avatars/${avatar}`} alt={`${displayName}'s avatar`} width={48} height={48} />
</div>
<div className={styles.info}>
<div className={styles.name}>{ displayName }</div>
<div className={styles.role}>{ role }</div>
</div>
</div>;
}

export default Author;
4 changes: 2 additions & 2 deletions src/utils/news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ArticleTypes = z.infer<typeof ValidArticleTypes>;

export const ArticleAuthor = z.object({
displayName: z.string(),
avatar: z.string().url().optional(),
avatar: z.string().optional(), // TO-DO: create a refine for checking if string = `filename.{png|jpg|jpeg|webp}`
role: z.string().optional(),
});

Expand Down Expand Up @@ -100,5 +100,5 @@ export const getArticle = async (slug: string): Promise<Article> => {

export const getAuthorData = async (id: string) => {
const raw: ArticleAuthor = await fetch(`${NEWS_SOURCE}/authors/${id}.json`, { next: { tags: ["articles", `article-author-${id}`] } }).then(res => res.json());
return raw;
return ArticleAuthor.parse(raw);
}

0 comments on commit 2c60eb9

Please sign in to comment.