2023-04-09 12:52:32 -05:00
|
|
|
import { versionTwo } from '@/docs/version_002/docsStructure';
|
|
|
|
|
import Markdoc from '@markdoc/markdoc';
|
|
|
|
|
import fs from 'fs';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import Section from './components/Section';
|
2023-04-07 23:18:45 -05:00
|
|
|
import styles from './page.module.css';
|
2023-04-09 12:52:32 -05:00
|
|
|
import { DocsStructure } from './types/types';
|
|
|
|
|
|
|
|
|
|
type Section = {
|
|
|
|
|
title: string;
|
|
|
|
|
copy: string;
|
|
|
|
|
example: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function loadSections(
|
|
|
|
|
docs: DocsStructure[],
|
|
|
|
|
sections: Section[] = []
|
|
|
|
|
): Section[] {
|
|
|
|
|
for (const doc of docs) {
|
|
|
|
|
try {
|
|
|
|
|
const copyPath = path.join(
|
|
|
|
|
process.cwd(),
|
|
|
|
|
'src/docs',
|
|
|
|
|
'version_002',
|
|
|
|
|
doc.folder,
|
|
|
|
|
doc.copy!
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const examplePath = path.join(
|
|
|
|
|
process.cwd(),
|
|
|
|
|
'src/docs',
|
|
|
|
|
'version_002',
|
|
|
|
|
doc.folder,
|
|
|
|
|
doc.example!
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const copySource = fs.readFileSync(copyPath, 'utf8');
|
|
|
|
|
const exampleSource = fs.readFileSync(
|
|
|
|
|
examplePath,
|
|
|
|
|
'utf8'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const copyAst = Markdoc.parse(copySource);
|
|
|
|
|
const exampleAst = Markdoc.parse(exampleSource);
|
|
|
|
|
const copyContent = Markdoc.transform(copyAst);
|
|
|
|
|
const exampleContent = Markdoc.transform(exampleAst);
|
|
|
|
|
const copyHtml = Markdoc.renderers.html(copyContent);
|
|
|
|
|
const exampleHtml =
|
|
|
|
|
Markdoc.renderers.html(exampleContent);
|
|
|
|
|
|
|
|
|
|
sections.push({
|
|
|
|
|
title: doc.title,
|
|
|
|
|
copy: copyHtml,
|
|
|
|
|
example: exampleHtml,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (doc.children && doc.children.length > 0) {
|
|
|
|
|
loadSections(doc.children, sections);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sections;
|
|
|
|
|
}
|
2023-04-07 21:33:32 -05:00
|
|
|
|
|
|
|
|
export default function Home() {
|
2023-04-09 12:52:32 -05:00
|
|
|
const versionTwoSections = loadSections(versionTwo);
|
|
|
|
|
console.log(versionTwoSections);
|
2023-04-07 21:33:32 -05:00
|
|
|
return (
|
2023-04-09 00:24:42 -05:00
|
|
|
<main className={styles.container}>
|
2023-04-09 12:52:32 -05:00
|
|
|
{versionTwoSections.map(article => (
|
|
|
|
|
<Section
|
|
|
|
|
key={article.title}
|
|
|
|
|
copy={article.copy}
|
|
|
|
|
example={article.example}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2023-04-09 00:24:42 -05:00
|
|
|
</main>
|
2023-04-07 23:18:45 -05:00
|
|
|
);
|
2023-04-07 21:33:32 -05:00
|
|
|
}
|