|
| 1 | +import articleStyle from 'components/articles/article.module.css'; |
| 2 | +import articleContentStyle from 'components/articles/content/content.module.css'; |
| 3 | +import ArticlePageClient from './page-client'; |
| 4 | +import meta from 'lib/config/metadata.js'; |
| 5 | +import config from 'lib/config'; |
| 6 | +import { getArticle } from 'lib/articles/parser'; |
| 7 | + |
| 8 | +export async function generateMetadata({ params }) { |
| 9 | + const { slug } = await params; |
| 10 | + const { frontmatter } = await getArticle({ slug }); |
| 11 | + const baseUrl = new URL(config.baseUrl); |
| 12 | + const imagePath = frontmatter.image.startsWith('/') ? frontmatter.image : `/${frontmatter.image}`; |
| 13 | + const imageUrl = new URL(imagePath, baseUrl).toString(); |
| 14 | + |
| 15 | + const dynamicMetadata = { |
| 16 | + ...meta, |
| 17 | + title: frontmatter.title, |
| 18 | + description: frontmatter.description, |
| 19 | + keywords: frontmatter.tags, |
| 20 | + openGraph: { |
| 21 | + ...meta.openGraph, |
| 22 | + title: frontmatter.title, |
| 23 | + description: frontmatter.description, |
| 24 | + type: 'article', |
| 25 | + article: { |
| 26 | + authors: [frontmatter.author.name], |
| 27 | + tags: frontmatter.tags, |
| 28 | + publishedTime: frontmatter.date, |
| 29 | + modifiedTime: frontmatter.date, |
| 30 | + }, |
| 31 | + images: [ |
| 32 | + { |
| 33 | + url: imageUrl, |
| 34 | + alt: frontmatter.title, |
| 35 | + }, |
| 36 | + ], |
| 37 | + }, |
| 38 | + }; |
| 39 | + return dynamicMetadata; |
| 40 | +} |
| 41 | + |
| 42 | +export default async function ArticlePage({ params }) { |
| 43 | + const { slug } = await params; |
| 44 | + const { compiledSource, frontmatter } = await getArticle({ slug }); |
| 45 | + return ( |
| 46 | + <div className={articleStyle.root}> |
| 47 | + <div className={articleContentStyle.root}> |
| 48 | + <ArticlePageClient source={compiledSource} frontmatter={frontmatter} /> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + ); |
| 52 | +} |
0 commit comments