Skip to content

Commit 6065944

Browse files
feat(metadata): add it (#20)
1 parent bc829dc commit 6065944

File tree

8 files changed

+91
-47
lines changed

8 files changed

+91
-47
lines changed

Diff for: app/apple-icon.jpg

30.7 KB
Loading

Diff for: 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]);

Diff for: 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];

Diff for: app/icon.svg

+6
Loading

Diff for: 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;

Diff for: 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 = () => (

Diff for: package-lock.json

+44-44
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"dependencies": {
2323
"@radix-ui/react-avatar": "~1.1.2",
2424
"classnames": "~2.5.1",
25-
"next": "15.1.6",
25+
"next": "15.1.7",
2626
"next-mdx-remote": "~5.0.0",
2727
"react": "19.0.0",
2828
"react-dom": "19.0.0"
@@ -33,7 +33,7 @@
3333
"@nodejs-loaders/css-module": "1.0.1",
3434
"@nodejs-loaders/tsx": "1.0.2",
3535
"@testing-library/react": "~16.2.0",
36-
"@types/node": "~22.12.0",
36+
"@types/node": "~22.13.1",
3737
"@types/react": "~19.0.8",
3838
"@types/react-dom": "~19.0.3",
3939
"autoprefixer": "~10.4.20",

0 commit comments

Comments
 (0)