Skip to content

Commit b2c6da4

Browse files
committed
refactor(components): improve Markdown rendering and enhance post metadata
- Updated Li component to handle checked prop more robustly - Enhanced Img component to return null if src is not provided - Modified post metadata to dynamically use the author's name - Adjusted label handling in fetchPostsByTag for better array management
1 parent 7650105 commit b2c6da4

5 files changed

Lines changed: 22 additions & 24 deletions

File tree

components/markdown.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ const Code: CodeComponent = ({
116116
}
117117

118118
const Li: LiComponent = ({
119-
checked = '',
119+
checked,
120120
children = ''
121-
}) => {
122-
// ordered represents the order of the list item
123-
if (checked !== null) {
121+
}: { checked?: boolean | null; children?: React.ReactNode }) => {
122+
// task list item (has checked prop); render without list marker
123+
if (checked !== undefined && checked !== null) {
124124
return (
125125
<li className="list-none my-1">
126126
{children}
@@ -206,12 +206,15 @@ const Img: React.FC<Pick<DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>,
206206
src,
207207
title,
208208
alt
209-
}) => (
210-
// eslint-disable-next-line @next/next/no-img-element
211-
<img src={src!} className="w-11/12 lg:w-2/3 mx-auto my-3 rounded-lg" loading="lazy" alt={alt}
212-
title={title}
213-
/>
214-
)
209+
}) => {
210+
if (!src) return null
211+
return (
212+
// eslint-disable-next-line @next/next/no-img-element
213+
<img src={src} className="w-11/12 lg:w-2/3 mx-auto my-3 rounded-lg" loading="lazy" alt={alt ?? ''}
214+
title={title ?? undefined}
215+
/>
216+
)
217+
}
215218

216219
const Table: React.FC<Pick<DetailedHTMLProps<TableHTMLAttributes<HTMLTableElement>, HTMLTableElement>, 'key' | keyof TableHTMLAttributes<HTMLTableElement>> & ReactMarkdownProps> = ({
217220
children,

lib/post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const fetchPostsByTag = async (tag: string) => {
9292
const {data} = await cli.rest.issues.listForRepo({
9393
owner: process.env.OWNER!,
9494
repo: process.env.REPO!,
95-
labels: [process.env.LABELS!.split(','), tag].join(','),
95+
labels: [...process.env.LABELS!.split(','), tag].join(','),
9696
per_page: 100,
9797
state: 'all'
9898
})

pages/_app.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ const Gossip = ({ Component, pageProps }: AppPropertiesWithLayout) => {
2121
<title>{title}</title>
2222
</Head>
2323

24-
<ThemeProvider>
24+
<ThemeProvider attribute="class" defaultTheme="system" enableSystem>
2525
{getLayout(<Component {...pageProps} />)}
2626
</ThemeProvider>
2727

28-
<GoogleAnalytics gaId={process.env.GOOGLE_ANALYTICS_ID!}/>
28+
{process.env.GOOGLE_ANALYTICS_ID && (
29+
<GoogleAnalytics gaId={process.env.GOOGLE_ANALYTICS_ID} />
30+
)}
2931
</>
3032
);
3133
};

pages/_document.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { isGithubChannel, isSpecialRepo } from '../lib';
22

33
import { Head, Html, Main, NextScript } from 'next/document';
44

5-
import type { NextPage } from 'next';
6-
7-
const Document: NextPage = () => {
5+
const Document = () => {
86
let href = '/favicon.ico';
97
if (isGithubChannel() && !isSpecialRepo()) href = './favicon.ico';
108

pages/post/[id].tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const PostDetail: NextPageWithLayout<{ post: Post }> = ({ post }) => (
1515
<title>{post.title}</title>
1616
<meta name="description" content={post.content.slice(0, 150)} />
1717
<meta name="keywords" content={post.title} />
18-
<meta name="author" content="zoffy" />
18+
<meta name="author" content={post.author} />
1919
<meta property="og:title" content={post.title} />
2020
<meta property="og:description" content={post.content.slice(0, 150)} />
2121
<meta property="og:type" content="article" />
@@ -73,14 +73,9 @@ export const getStaticPaths = async () => ({
7373

7474
export const getStaticProps = async ({ params }: { params: { id: string } }) => {
7575
const { id } = params;
76-
7776
const post = await fetchPost(id);
78-
79-
return {
80-
props: {
81-
post,
82-
},
83-
};
77+
if (!post) return { notFound: true };
78+
return { props: { post } };
8479
};
8580

8681
export default PostDetail;

0 commit comments

Comments
 (0)