-
Hi there, I am wondering how to control the multiple-tree right under the root directory (/content) structure when combining next-docs-zeta & contentlayer. (Pattern 1) Or for simplicity, I should just go with Pattern 2 but have some confusions. Pattern 1I have existing contentlayer based project for our docs, blogs and legal documents in mdx files. The current folder structure is like Here is my current // Same for Docs, Blogs and etc
const Docs = defineDocumentType(() => ({
name: "Docs",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {
type: "string",
required: true,
},
description: {
type: "string",
},
date: {
type: "date",
required: true,
},
},
computedFields,
}))
const Blogs = defineDocumentType(() => ({
name: "Blogs",
filePathPattern: `blogs/**/*.mdx`,
contentType: "mdx",
...
}))
const computedFields: ComputedFields = {
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
lang: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/")[1],
},
}
export default makeSource({
contentDirPath: "content",
disableImportAliasWarning: true,
documentTypes: [Blogs, Docs, Terms, CommercialAct, PrivacyPolicy],
mdx: {some configs..}
}) To integrate the next-docs-zeta, I believe I should customize the code from the official configuration.ts (for example, we should change docsPattern type from string to string[] to accept multiple pages?) and then call the function within the file. // contentlayer.config.ts
const customConfig = createConfig()
export default makeSource({
...customConfig,
}) Is there any practical way to write the custom createConfig function (like defined in configuration.ts) for my purposes? Pattern 2Or, I am fine with just create another And then in my contentlayer.config.ts file export default makeSource(
createConfig({
docsComputedFields: {
structuredData: {
type: "json",
resolve: (page) => structure(page.body.raw),
},
},
})
) And in my app/source.ts import { allDocs, allMeta } from "@contentlayer/generated"
import { createContentlayer } from "next-docs-zeta/contentlayer"
export const { tree, getPage, getPages } = createContentlayer(allMeta, allDocs) But I am not sure how things work from here - let's say we have {
title: 'Docs Top'
description: "ABCD (omitted)",
body: "SOMETHING (omitted) "
_id: 'docs/docs/index.mdx',
_raw: {
sourceFilePath: 'docs/docs/index.mdx',
sourceFileName: 'index.mdx',
sourceFileDir: 'docs/docs',
contentType: 'mdx',
flattenedPath: 'docs/docs'
},
type: 'Docs',
slug: 'docs',
url: '/docs/docs',
structuredData: {
contents: [
{
heading: '',
content:
'This site is a work in progress.'
}
],
headings: []
}
} Also, because everything is under the Anyways, I would like to know how to handle these things in the simplest way. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Additionally - according to the official docs, it seems like we can generate multiple trees but how this work with contentlayer? Should this solve the above problems?😨 https://next-docs-zeta.vercel.app/docs/headless/utils/build-page-tree#pages-structure |
Beta Was this translation helpful? Give feedback.
-
Both patterns looks bad to me, the default pattern of Docs is In pattern 2 You can check the options of |
Beta Was this translation helpful? Give feedback.
-
I figured it out how to generate the all contentlayer contents, in this way it generates the all sources under the contents (Docs and Blogs). But please let me know if this is not ideal way to handle the things! const config = createConfig({
docFields: {
title: {
type: "string",
},
description: {
type: "string",
},
date: {
type: "date",
},
},
docsComputedFields: {
structuredData: {
type: "json",
resolve: (doc) => structure(page.body.raw),
},
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
lang: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/")[1],
},
},
})
const existingDocumentTypes = config.documentTypes
const existingDocumentTypesArray = Array.isArray(existingDocumentTypes)
? existingDocumentTypes
: Object.values(existingDocumentTypes)
const allDocumentTypes = [...existingDocumentTypesArray, Blogs, Terms, CommercialAct, PrivacyPolicy]
const customConfig: Args = {
...config,
documentTypes: allDocumentTypes,
} |
Beta Was this translation helpful? Give feedback.
-
The Source API has been released since v.7.0.0, you can take a look at the new docs. |
Beta Was this translation helpful? Give feedback.
The Source API has been released since v.7.0.0, you can take a look at the new docs.