MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / fetchMDXContent

Function fetchMDXContent

apps/baseai.dev/src/scripts/generate-content.js:23–87  ·  view source on GitHub ↗
({ slug, section, dirPath, baseUrl })

Source from the content-addressed store, hash-verified

21}
22
23async function fetchMDXContent({ slug, section, dirPath, baseUrl }) {
24 const { serialize } = await import('next-mdx-remote/serialize');
25 const { recmaPlugins } = await import('../mdx/recma.mjs');
26 const { rehypePlugins } = await import('../mdx/rehype.mjs');
27 const { remarkPlugins } = await import('../mdx/remark.mjs');
28
29 const markdownWithMeta = section
30 ? fs.readFileSync(`${dirPath}/${section}/${slug}.mdx`, 'utf-8')
31 : fs.readFileSync(`${dirPath}/${slug}.mdx`, 'utf-8');
32
33 const { data: frontmatter, content } = matter(markdownWithMeta);
34 const mdxSource = await serialize(content, {
35 mdxOptions: {
36 recmaPlugins: [...recmaPlugins],
37 rehypePlugins: [...rehypePlugins],
38 remarkPlugins: [...remarkPlugins]
39 },
40 blockJS: false
41 });
42
43 const docsSection = await formatString(section);
44 let title = `${frontmatter.title}`;
45 let url = baseUrl;
46 let imageUrl = `${BASE_URL}/api/og?title=${frontmatter.title}`;
47
48 if (section) {
49 title = `${frontmatter.title} - ${frontmatter.section ?? docsSection} - BaseAI`;
50 imageUrl = `${BASE_URL}/api/og?title=${frontmatter.title}&section=${docsSection}`;
51
52 const isAppPath = APPS.includes(section);
53 const isIndexPath = slug === 'index';
54
55 // if app path but the slug is not index, then we need to add the slug to the url
56 if (isAppPath && !isIndexPath) {
57 url = `${baseUrl}/${slug}`;
58 }
59
60 // if not app path but the slug is index, then we need to add the section to the url
61 // EXAMPLE: /docs/getting-started OR /docs/pipe
62 if (!isAppPath && isIndexPath) {
63 url = `${baseUrl}/${section}`;
64 }
65
66 // If not app path and not index, then we need to add the section and slug to the url
67 // EXAMPLE: /docs/getting-started/project-structure
68 if (!isAppPath && !isIndexPath) {
69 url = `${baseUrl}/${section}/${slug}`;
70 }
71 }
72
73 return {
74 frontmatter: {
75 url,
76 slug,
77 title,
78 imageUrl,
79 tags: frontmatter.tags ?? [],
80 section: frontmatter.section || '',

Callers 2

generateDocsContentFunction · 0.85
generateLearnContentFunction · 0.85

Calls 1

formatStringFunction · 0.70

Tested by

no test coverage detected