diff --git a/app/documentation/docs/[version]/[slug]/page.tsx b/app/documentation/docs/[version]/[slug]/page.tsx index 1b3ab80..4417146 100644 --- a/app/documentation/docs/[version]/[slug]/page.tsx +++ b/app/documentation/docs/[version]/[slug]/page.tsx @@ -4,7 +4,7 @@ import VersionSidebar from '@/components/VersionSidebar' import { compareSemanticVersions } from '@/utils/misc' import Link from 'next/link' import styles from '@/styles/accordion.module.scss' -import { cleanTags, getVersionIndex, readAndConcatMarkdownFiles } from '@/lib/utils' +import { cleanTags, getVersionIndex } from '@/lib/utils' import availableVersions from '@/_content/docs'; import Error from '@/components/Error' import { DocAnchorLinksType, MarkdownFileMetadata } from '@/types/types' @@ -14,12 +14,16 @@ import '@fortawesome/fontawesome-free/css/fontawesome.min.css'; import '@fortawesome/fontawesome-free/css/solid.min.css'; import ApiDocContentWrapper from '@/app/documentation/api/components/ApiDocContentWrapper' +let indexJSON: MarkdownFileMetadata[] | null = null; + export const generateMetadata = async ({ params, }: { params: { slug: string; version: string } }) => { - const indexJSON = await getVersionIndex(params.version); + if (!indexJSON) { + indexJSON = await getVersionIndex(params.version, true); + } const section = indexJSON?.find((item: MarkdownFileMetadata) => item.slug === params.slug); if (section) { @@ -52,21 +56,17 @@ export default async function SingleDocPage({ params: { slug: string; version: string } }) { - const indexJSON = await getVersionIndex(params.version); + const { version } = params; + if (!indexJSON) { + indexJSON = await getVersionIndex(version, true); + } + const activeSection = indexJSON?.find((item: MarkdownFileMetadata) => item.slug === params.slug); const path = activeSection?.children[0].path; - - const imagesRuntimePath = '/assets/docs/' + params.version + '/resources/'; if (!activeSection || !path) { return ; } - await indexJSON.forEach(async (element: MarkdownFileMetadata) => { - const { html, anchorLinks } = await readAndConcatMarkdownFiles(element, imagesRuntimePath, indexJSON, element.title); - element.anchorLinks = anchorLinks; - element.html = html; - }); - const versions = [ ...new Set( availableVersions diff --git a/lib/utils.ts b/lib/utils.ts index 8c16f9a..a9074f6 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -17,14 +17,23 @@ function compileMarkdownToHTML(markdown: string, startingSectionNumber: string): anchorLinks, } } - -export async function getVersionIndex(version: string) { +export async function getVersionIndex(version: string, fetchHtmlContent: boolean = false) { const rootFolder = `_content/docs/${version}`; if (!fs.existsSync(rootFolder) || !fs.statSync(rootFolder).isDirectory()) { return null; } - const allDocs = (await import(`_content/docs/${version}/index.js`)).default; - return allDocs; + const indexJSON = (await import(`_content/docs/${version}/index.js`)).default; + + if (fetchHtmlContent) { + const imagesRuntimePath = '/assets/docs/' + version + '/resources/'; + await indexJSON.forEach(async (element: MarkdownFileMetadata) => { + const { html, anchorLinks } = await readAndConcatMarkdownFiles(element, imagesRuntimePath, indexJSON, element.title); + element.anchorLinks = anchorLinks; + element.html = html; + }); + } + + return indexJSON; } export const readMarkdownFile = async function(filePath: string, imagesPath: string = '') {