Skip to content

Commit b8ba67b

Browse files
ericyangpanclaude
andcommitted
refactor(lib): move generated files to lib/generated directory
Restructure auto-generated files to improve code organization: - Move articles.ts and docs.ts to src/lib/generated/ - Auto-generate MDX component imports in articles.ts and docs.ts - Update metadata.ts import paths to reference sibling files - Update all imports across the codebase to use @/lib/generated/ - Delete old manually maintained src/lib/articles.ts and src/lib/docs.ts This change: - Eliminates hardcoded MDX file paths - Makes the generated code layer more explicit - Reduces manual maintenance when adding new content 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 10848bb commit b8ba67b

File tree

6 files changed

+248
-88
lines changed

6 files changed

+248
-88
lines changed

src/app/sitemap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { MetadataRoute } from 'next';
2-
import { articles } from '@/lib/articles';
3-
import { docSections } from '@/lib/docs';
2+
import { articles } from '@/lib/generated/articles';
3+
import { docSections } from '@/lib/generated/docs';
44
import { locales } from '@/i18n/config';
55
import {
66
idesData,

src/components/sidebar/DocsSidebar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import Sidebar, { SidebarItem } from './Sidebar';
4-
import type { DocSection } from '@/lib/docs';
4+
import type { DocSection } from '@/lib/generated/docs';
55
import { useTranslations, useLocale } from 'next-intl';
66

77
type DocsSidebarProps = {

src/lib/generated/articles.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is auto-generated by scripts/generate-metadata.mjs
2+
// DO NOT EDIT MANUALLY
3+
4+
import { articlesMetadata } from './metadata';
5+
6+
export type ArticleMetadata = {
7+
title: string;
8+
description: string;
9+
date: string;
10+
slug: string;
11+
};
12+
13+
// Get articles for a specific locale with fallback to English
14+
export function getArticles(locale: string = 'en'): ArticleMetadata[] {
15+
return articlesMetadata[locale] || articlesMetadata['en'] || [];
16+
}
17+
18+
// Get all articles (backward compatibility)
19+
export const articles: ArticleMetadata[] = getArticles('en');
20+
21+
// Get a specific article by slug for a given locale
22+
export function getArticleBySlug(slug: string, locale: string = 'en'): ArticleMetadata | undefined {
23+
const localeArticles = getArticles(locale);
24+
return localeArticles.find((article) => article.slug === slug);
25+
}
26+
27+
// MDX components mapping for all locales (webpack will handle this at build time)
28+
const articleComponents: Record<string, Record<string, React.ComponentType>> = {
29+
'en': {
30+
'getting-started-with-ai-coding': require('@content/articles/en/getting-started-with-ai-coding.mdx').default,
31+
'mcp-servers-explained': require('@content/articles/en/mcp-servers-explained.mdx').default,
32+
},
33+
'zh-Hans': {
34+
'getting-started-with-ai-coding': require('@content/articles/zh-Hans/getting-started-with-ai-coding.mdx').default,
35+
'mcp-servers-explained': require('@content/articles/zh-Hans/mcp-servers-explained.mdx').default,
36+
},
37+
'de': {
38+
'getting-started-with-ai-coding': require('@content/articles/de/getting-started-with-ai-coding.mdx').default,
39+
'mcp-servers-explained': require('@content/articles/de/mcp-servers-explained.mdx').default,
40+
},
41+
};
42+
43+
// Get components for a specific locale with fallback to English
44+
export function getArticleComponents(locale: string = 'en'): Record<string, React.ComponentType> {
45+
return articleComponents[locale] || articleComponents['en'] || {};
46+
}

src/lib/generated/docs.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file is auto-generated by scripts/generate-metadata.mjs
2+
// DO NOT EDIT MANUALLY
3+
4+
import { docsMetadata } from './metadata';
5+
6+
export type DocSection = {
7+
id: string;
8+
title: string;
9+
slug: string;
10+
};
11+
12+
// Get doc sections for a specific locale with fallback to English
13+
export function getDocSections(locale: string): DocSection[] {
14+
return docsMetadata[locale] || docsMetadata['en'] || [];
15+
}
16+
17+
// Get all doc sections (backward compatibility)
18+
export const docSections: DocSection[] = getDocSections('en');
19+
20+
// Get a specific doc by slug for a given locale
21+
export function getDocBySlug(slug: string, locale: string = 'en'): DocSection | undefined {
22+
const sections = getDocSections(locale);
23+
return sections.find((doc) => doc.slug === slug);
24+
}
25+
26+
// MDX components mapping for all locales (webpack will handle this at build time)
27+
const docComponents: Record<string, Record<string, React.ComponentType>> = {
28+
'en': {
29+
'getting-started': require('@content/docs/en/getting-started.mdx').default,
30+
'welcome': require('@content/docs/en/welcome.mdx').default,
31+
},
32+
'zh-Hans': {
33+
'getting-started': require('@content/docs/zh-Hans/getting-started.mdx').default,
34+
'welcome': require('@content/docs/zh-Hans/welcome.mdx').default,
35+
},
36+
'de': {
37+
'getting-started': require('@content/docs/de/getting-started.mdx').default,
38+
'welcome': require('@content/docs/de/welcome.mdx').default,
39+
},
40+
};
41+
42+
// Get components for a specific locale with fallback to English
43+
export function getDocComponents(locale: string = 'en'): Record<string, React.ComponentType> {
44+
return docComponents[locale] || docComponents['en'] || {};
45+
}

0 commit comments

Comments
 (0)