|
1 | 1 | // This file is auto-generated by scripts/generate-metadata.mjs |
2 | 2 | // DO NOT EDIT MANUALLY |
3 | 3 |
|
4 | | -import { articlesMetadata } from './metadata'; |
| 4 | +import { articlesMetadata } from './metadata' |
5 | 5 |
|
6 | 6 | export type ArticleMetadata = { |
7 | | - title: string; |
8 | | - description: string; |
9 | | - date: string; |
10 | | - slug: string; |
11 | | -}; |
| 7 | + title: string |
| 8 | + description: string |
| 9 | + date: string |
| 10 | + slug: string |
| 11 | +} |
12 | 12 |
|
13 | 13 | // Get articles for a specific locale with fallback to English |
14 | 14 | export function getArticles(locale: string = 'en'): ArticleMetadata[] { |
15 | | - return articlesMetadata[locale] || articlesMetadata['en'] || []; |
| 15 | + return articlesMetadata[locale] || articlesMetadata.en || [] |
16 | 16 | } |
17 | 17 |
|
18 | 18 | // Get all articles (backward compatibility) |
19 | | -export const articles: ArticleMetadata[] = getArticles('en'); |
| 19 | +export const articles: ArticleMetadata[] = getArticles('en') |
20 | 20 |
|
21 | 21 | // Get a specific article by slug for a given locale |
22 | 22 | export function getArticleBySlug(slug: string, locale: string = 'en'): ArticleMetadata | undefined { |
23 | | - const localeArticles = getArticles(locale); |
24 | | - return localeArticles.find((article) => article.slug === slug); |
| 23 | + const localeArticles = getArticles(locale) |
| 24 | + return localeArticles.find(article => article.slug === slug) |
25 | 25 | } |
26 | 26 |
|
27 | 27 | // MDX components mapping for all locales (dynamic imports) |
28 | | -const articleComponents: Record<string, Record<string, () => Promise<{ default: React.ComponentType }>>> = { |
29 | | - 'en': { |
30 | | - 'getting-started-with-ai-coding': () => import('@content/articles/en/getting-started-with-ai-coding.mdx'), |
| 28 | +const articleComponents: Record< |
| 29 | + string, |
| 30 | + Record<string, () => Promise<{ default: React.ComponentType }>> |
| 31 | +> = { |
| 32 | + en: { |
| 33 | + 'getting-started-with-ai-coding': () => |
| 34 | + import('@content/articles/en/getting-started-with-ai-coding.mdx'), |
31 | 35 | 'mcp-servers-explained': () => import('@content/articles/en/mcp-servers-explained.mdx'), |
32 | 36 | }, |
33 | 37 | 'zh-Hans': { |
34 | | - 'getting-started-with-ai-coding': () => import('@content/articles/zh-Hans/getting-started-with-ai-coding.mdx'), |
| 38 | + 'getting-started-with-ai-coding': () => |
| 39 | + import('@content/articles/zh-Hans/getting-started-with-ai-coding.mdx'), |
35 | 40 | 'mcp-servers-explained': () => import('@content/articles/zh-Hans/mcp-servers-explained.mdx'), |
36 | 41 | }, |
37 | | - 'de': { |
38 | | - 'getting-started-with-ai-coding': () => import('@content/articles/de/getting-started-with-ai-coding.mdx'), |
| 42 | + de: { |
| 43 | + 'getting-started-with-ai-coding': () => |
| 44 | + import('@content/articles/de/getting-started-with-ai-coding.mdx'), |
39 | 45 | 'mcp-servers-explained': () => import('@content/articles/de/mcp-servers-explained.mdx'), |
40 | 46 | }, |
41 | | -}; |
| 47 | +} |
42 | 48 |
|
43 | 49 | // Get a specific article component for a given locale and slug |
44 | | -export async function getArticleComponent(locale: string = 'en', slug: string): Promise<React.ComponentType | null> { |
45 | | - const loaders = articleComponents[locale] || articleComponents['en']; |
46 | | - const loader = loaders?.[slug]; |
47 | | - if (!loader) return null; |
48 | | - const mdxModule = await loader(); |
49 | | - return mdxModule.default; |
| 50 | +export async function getArticleComponent( |
| 51 | + locale: string = 'en', |
| 52 | + slug: string |
| 53 | +): Promise<React.ComponentType | null> { |
| 54 | + const loaders = articleComponents[locale] || articleComponents.en |
| 55 | + const loader = loaders?.[slug] |
| 56 | + if (!loader) return null |
| 57 | + const mdxModule = await loader() |
| 58 | + return mdxModule.default |
50 | 59 | } |
0 commit comments