slug i18n
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
import { mapSlugToFileSlug } from './slugs';
|
||||
|
||||
export interface PostFrontmatter {
|
||||
title: string;
|
||||
@@ -18,8 +19,10 @@ export interface PostMdx {
|
||||
}
|
||||
|
||||
export async function getPostBySlug(slug: string, locale: string): Promise<PostMdx | null> {
|
||||
// Map translated slug to file slug
|
||||
const fileSlug = await mapSlugToFileSlug(slug, locale);
|
||||
const postsDir = path.join(process.cwd(), 'data', 'blog', locale);
|
||||
const filePath = path.join(postsDir, `${slug}.mdx`);
|
||||
const filePath = path.join(postsDir, `${fileSlug}.mdx`);
|
||||
|
||||
if (!fs.existsSync(filePath)) {
|
||||
return null;
|
||||
@@ -29,7 +32,7 @@ export async function getPostBySlug(slug: string, locale: string): Promise<PostM
|
||||
const { data, content } = matter(fileContent);
|
||||
|
||||
return {
|
||||
slug,
|
||||
slug: fileSlug,
|
||||
frontmatter: data as PostFrontmatter,
|
||||
content,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user