diff --git a/packages/contented-example/contented.config.mjs b/packages/contented-example/contented.config.mjs index 277209f3..d81a8f15 100644 --- a/packages/contented-example/contented.config.mjs +++ b/packages/contented-example/contented.config.mjs @@ -42,6 +42,11 @@ const config = { type: 'Lorem', pattern: ['contented-example-lorem/**/*.md'], processor: MarkdownPipeline, + transform: (file) => { + file.path = file.path.replaceAll(/^\/contented-example-lorem\/?/g, '/'); + file.sections = file.sections.slice(1); + return file; + }, }, { type: 'Contented', diff --git a/packages/contented-preview/src/pages/[[...slug]].page.jsx b/packages/contented-preview/src/pages/[type]/[[...slug]].page.jsx similarity index 79% rename from packages/contented-preview/src/pages/[[...slug]].page.jsx rename to packages/contented-preview/src/pages/[type]/[[...slug]].page.jsx index a3fdd008..de8d34ac 100644 --- a/packages/contented-preview/src/pages/[[...slug]].page.jsx +++ b/packages/contented-preview/src/pages/[type]/[[...slug]].page.jsx @@ -6,25 +6,29 @@ import Head from 'next/head'; import { useRouter } from 'next/router'; import { useEffect } from 'react'; -import { Index } from '../../../index.js'; -import ContentHeadings from './_components/ContentHeadings'; -import ContentNavigation, { computeContentSections } from './_components/ContentNavigation'; -import ContentProse from './_components/ContentProse'; -import { useMenu } from './_components/MenuContext'; -import { useTheme } from './_components/ThemeContext'; +import { Index } from '../../../../index.js'; +import ContentHeadings from '../_components/ContentHeadings'; +import ContentNavigation, { computeContentSections } from '../_components/ContentNavigation'; +import ContentProse from '../_components/ContentProse'; +import { useMenu } from '../_components/MenuContext'; +import { useTheme } from '../_components/ThemeContext'; export async function getStaticPaths() { return { - paths: ['/', ...Index.map((file) => file.path)], + paths: Index.map((file) => { + return `/${file.type.toLowerCase()}${file.path}`; + }), fallback: false, }; } export async function getStaticProps({ params }) { const path = `/${params?.slug?.join('/') ?? ''}`; - const ContentIndex = Index.find((file) => file.path === path) ?? Index[0]; - const Content = require(`../../../${ContentIndex.type}/${ContentIndex.fileId}.json`); - const TypeCollection = require(`../../../${ContentIndex.type}/index.json`); + const ContentIndex = Index.find((file) => { + return file.path === path && file.type.toLowerCase() === params?.type; + }); + const Content = require(`../../../../${ContentIndex.type}/${ContentIndex.fileId}.json`); + const TypeCollection = require(`../../../../${ContentIndex.type}/index.json`); return { props: { @@ -34,7 +38,7 @@ export async function getStaticProps({ params }) { }; } -export default function SlugPage({ content, sections }) { +export default function IndexPage({ content, sections }) { const siteTitle = getSiteTitle(content); const canonicalUrl = `${process.env.CONTENTED_PREVIEW_SITE_URL}${content.path}`; const description = truncate(content?.description, { length: 220 }); diff --git a/packages/contented-preview/src/pages/_components/ContentNavigation.jsx b/packages/contented-preview/src/pages/_components/ContentNavigation.jsx index cfcdbb92..1a73f775 100644 --- a/packages/contented-preview/src/pages/_components/ContentNavigation.jsx +++ b/packages/contented-preview/src/pages/_components/ContentNavigation.jsx @@ -25,34 +25,40 @@ export default function ContentNavigation({ sections, className }) {