Skip to content

feat(metadata): add it #20

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

Merged
merged 2 commits into from
Feb 12, 2025
Merged
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
Binary file added app/apple-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions app/article/[[...categories]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CategoriesSelector } from '~/components/Common/CategoriesSelector/index.tsx';
import { ArticleCard } from '~/components/Post/ArticleCard/index.tsx';
import { getPostsMetadata } from '~/lib/post.ts';
import styles from './page.module.css';

Check failure on line 4 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

Cannot find module './page.module.css' or its corresponding type declarations.
import type { FC } from 'react';

Check failure on line 5 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

Cannot find module 'react' or its corresponding type declarations.
import type { Metadata } from 'next';

Check failure on line 6 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

Cannot find module 'next' or its corresponding type declarations.

type CategoriesParams = {
categories?: string[];
Expand Down Expand Up @@ -43,23 +44,34 @@
return params;
};

export const generateMetadata = async ({
params,
}: PageProps): Promise<Metadata> => {
const currentCategories = (await params).categories || [];

return {
title: `Articles${currentCategories.length > 0 ? ` - ${currentCategories.join(', ')}` : ''}`,
description: 'Here you can find all the articles available on the website.',
};
};

const Page: FC<PageProps> = async ({ params }) => {

Check failure on line 58 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

Binding element 'params' implicitly has an 'any' type.
const currentCategories = (await params).categories || [];
const postsMetadata = await getPostsMetadata(currentCategories[0]);

return (
<main className={styles.page}>

Check failure on line 63 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
<h1>Article list</h1>

Check failure on line 64 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.

Check failure on line 64 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
<p>

Check failure on line 65 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
Here you can find all the articles available on the website. You can
filter them by category using the dropdown below.
</p>

Check failure on line 68 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
<CategoriesSelector
currentCategories={currentCategories}
categories={CATEGORIES}
/>
{postsMetadata.length === 0 ? (
<div className={styles.noArticles}>

Check failure on line 74 in app/article/[[...categories]]/page.tsx

View workflow job for this annotation

GitHub Actions / quality

JSX element implicitly has type 'any' because no interface 'JSX.IntrinsicElements' exists.
<p>No articles here for now</p>
</div>
) : (
Expand Down
19 changes: 19 additions & 0 deletions app/article/post/[article]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getAllPosts } from '~/lib/post.ts';
import { ArticleHeader } from '~/components/Post/ArticleHeader/index.tsx';
import styles from './page.module.css';
import type { FC } from 'react';
import type { Metadata } from 'next';
import type { PostFrontmatter } from '~/types/frontmatter';
import '~/styles/markdown.css';

Expand All @@ -24,6 +25,24 @@ export async function generateStaticParams() {
});
}

export async function generateMetadata({
params,
}: PageProps): Promise<Metadata> {
const article = (await params).article;
const slugs = ['post', article];

const mdxResult = await getContent<PostFrontmatter>(slugs);

if (!mdxResult) notFound();

const { frontmatter } = mdxResult;

return {
title: frontmatter.title,
description: frontmatter.description,
};
}

const Page: FC<PageProps> = async ({ params }) => {
const article = (await params).article;
const slugs = ['post', article];
Expand Down
6 changes: 6 additions & 0 deletions app/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ import { GeistSans } from 'geist/font/sans';
import { GeistMono } from 'geist/font/mono';
import { Header } from '~/components/Sections/Header/index.tsx';
import type { FC, PropsWithChildren } from 'react';
import type { Metadata } from 'next';
import '~/styles/globals.css';

const metadata: Metadata = {
title: 'Nodejs-Loaders',
description: 'A collection of loaders for Node.js',
};

const RootLayout: FC<PropsWithChildren> = ({ children }) => (
<html lang="en">
<body className={classNames(GeistSans.className, GeistMono.className)}>
Expand All @@ -14,4 +20,5 @@ const RootLayout: FC<PropsWithChildren> = ({ children }) => (
</html>
);

export { metadata };
export default RootLayout;
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hero } from '~/components/Landing/Hero/index.tsx';
import { LatestArticleSection } from '~/components/Landing/LatestArticleSection/index.tsx';
import { LatestArticleSection } from '~/components/Landing/LastestArticleSection/index.tsx';
import type { FC } from 'react';

const Page: FC = () => (
Expand Down
88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@radix-ui/react-avatar": "~1.1.2",
"classnames": "~2.5.1",
"next": "15.1.6",
"next": "15.1.7",
"next-mdx-remote": "~5.0.0",
"react": "19.0.0",
"react-dom": "19.0.0"
Expand All @@ -33,7 +33,7 @@
"@nodejs-loaders/css-module": "1.0.1",
"@nodejs-loaders/tsx": "1.0.2",
"@testing-library/react": "~16.2.0",
"@types/node": "~22.12.0",
"@types/node": "~22.13.1",
"@types/react": "~19.0.8",
"@types/react-dom": "~19.0.3",
"autoprefixer": "~10.4.20",
Expand Down