Skip to content

Commit 4c37504

Browse files
feat(metadata): add it
1 parent bc829dc commit 4c37504

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

app/apple-icon.jpg

30.7 KB
Loading

app/article/[[...categories]]/page.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ArticleCard } from '~/components/Post/ArticleCard/index.tsx';
33
import { getPostsMetadata } from '~/lib/post.ts';
44
import styles from './page.module.css';
55
import type { FC } from 'react';
6+
import type { Metadata } from 'next';
67

78
type CategoriesParams = {
89
categories?: string[];
@@ -43,6 +44,17 @@ export const generateStaticParams = () => {
4344
return params;
4445
};
4546

47+
export const generateMetadata = async ({
48+
params,
49+
}: PageProps): Promise<Metadata> => {
50+
const currentCategories = (await params).categories || [];
51+
52+
return {
53+
title: `Articles${currentCategories.length > 0 ? ` - ${currentCategories.join(', ')}` : ''}`,
54+
description: 'Here you can find all the articles available on the website.',
55+
};
56+
};
57+
4658
const Page: FC<PageProps> = async ({ params }) => {
4759
const currentCategories = (await params).categories || [];
4860
const postsMetadata = await getPostsMetadata(currentCategories[0]);

app/article/post/[article]/page.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getAllPosts } from '~/lib/post.ts';
44
import { ArticleHeader } from '~/components/Post/ArticleHeader/index.tsx';
55
import styles from './page.module.css';
66
import type { FC } from 'react';
7+
import type { Metadata } from 'next';
78
import type { PostFrontmatter } from '~/types/frontmatter';
89
import '~/styles/markdown.css';
910

@@ -24,6 +25,24 @@ export async function generateStaticParams() {
2425
});
2526
}
2627

28+
export async function generateMetadata({
29+
params,
30+
}: PageProps): Promise<Metadata> {
31+
const article = (await params).article;
32+
const slugs = ['post', article];
33+
34+
const mdxResult = await getContent<PostFrontmatter>(slugs);
35+
36+
if (!mdxResult) notFound();
37+
38+
const { frontmatter } = mdxResult;
39+
40+
return {
41+
title: frontmatter.title,
42+
description: frontmatter.description,
43+
};
44+
}
45+
2746
const Page: FC<PageProps> = async ({ params }) => {
2847
const article = (await params).article;
2948
const slugs = ['post', article];

app/icon.svg

+6
Loading

app/layout.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ import { GeistSans } from 'geist/font/sans';
33
import { GeistMono } from 'geist/font/mono';
44
import { Header } from '~/components/Sections/Header/index.tsx';
55
import type { FC, PropsWithChildren } from 'react';
6+
import type { Metadata } from 'next';
67
import '~/styles/globals.css';
78

9+
const metadata: Metadata = {
10+
title: 'Nodejs-Loaders',
11+
description: 'A collection of loaders for Node.js',
12+
};
13+
814
const RootLayout: FC<PropsWithChildren> = ({ children }) => (
915
<html lang="en">
1016
<body className={classNames(GeistSans.className, GeistMono.className)}>
@@ -14,4 +20,5 @@ const RootLayout: FC<PropsWithChildren> = ({ children }) => (
1420
</html>
1521
);
1622

23+
export { metadata };
1724
export default RootLayout;

app/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Hero } from '~/components/Landing/Hero/index.tsx';
2-
import { LatestArticleSection } from '~/components/Landing/LatestArticleSection/index.tsx';
2+
import { LatestArticleSection } from '~/components/Landing/LastestArticleSection/index.tsx';
33
import type { FC } from 'react';
44

55
const Page: FC = () => (

0 commit comments

Comments
 (0)