nextui/apps/docs/contentlayer.config.js
աӄա 765dac53cf
refactor(docs): dx improvement in accordion (#3856)
* refactor: improve dx for writing a docs component (#2544)

* refactor: improve dx for write a docs component

Signed-off-by: Innei <i@innei.in>

* refactor(docs): switch to contentlayer2

* chore(docs): rename to avoid conflict

* refactor(docs): switch to next-contentlayer2

* refactor(docs): revise docs lib

* chore(deps): bump docs related dependencies

* fix(use-aria-multiselect): type issue due to ts version bump

---------

Signed-off-by: Innei <i@innei.in>
Co-authored-by: WK Wong <wingkwong.code@gmail.com>

* refactor(docs): accordion codes

* feat(docs): declare module `*.jsx?raw`

* feat(docs): include `**/*.jsx`

* fix(docs): incorrect content

* chore(docs): add new lines

* refactor(docs): lint

---------

Signed-off-by: Innei <i@innei.in>
Co-authored-by: Innei <tukon479@gmail.com>
2024-10-20 00:54:13 +08:00

103 lines
2.8 KiB
JavaScript

import {defineDocumentType, defineNestedType, makeSource} from "contentlayer2/source-files";
import remarkGfm from "remark-gfm";
import rehypeSlug from "rehype-slug";
import {visit} from "unist-util-visit";
import RawPlugin from 'esbuild-plugin-raw'
import pluginCodeBlock from "./plugins/codeBlock";
/** @type {import('contentlayer2/source-files').ComputedFields} */
const computedFields = {
slug: {
type: "string",
resolve: (doc) => `/${doc._raw.flattenedPath}`,
},
slugAsParams: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
},
url: {type: "string", resolve: (doc) => `/${doc._raw.flattenedPath}`},
};
export const Doc = defineDocumentType(() => ({
name: "Doc",
filePathPattern: `docs/**/*.mdx`,
contentType: "mdx",
fields: {
title: {type: "string", required: true},
description: {type: "string", required: false},
date: {type: "date", required: false},
},
computedFields,
}));
const AuthorProperties = defineNestedType(() => ({
name: "AuthorProperties",
fields: {
name: {type: "string", required: true},
link: {type: "string", required: false},
avatar: {type: "string", required: false},
username: {type: "string", required: false},
},
}));
export const BlogPost = defineDocumentType(() => ({
name: "BlogPost",
filePathPattern: `blog/**/*.mdx`,
contentType: "mdx",
fields: {
title: {type: "string", required: true},
description: {type: "string", required: true},
date: {type: "date", required: true},
draft: {type: "boolean", required: false},
tags: {type: "list", of: {type: "string"}},
author: {type: "nested", of: AuthorProperties, required: false},
image: {type: "string", required: false},
},
computedFields: {
...computedFields,
// Date format June 22nd 2023
formattedDate: {
type: "string",
resolve: (doc) => {
const date = new Date(doc.date);
const options = {year: "numeric", month: "long", day: "numeric"};
return date.toLocaleDateString("en-US", options);
},
},
// add https://nextui.org to the image path
imageAsParams: {
type: "string",
resolve: (doc) => {
const image = doc.image;
if (image) {
return `https://nextui.org${image}`;
}
},
},
},
}));
export default makeSource({
contentDirPath: "./content",
documentTypes: [Doc, BlogPost],
mdx: {
remarkPlugins: [remarkGfm, pluginCodeBlock],
esbuildOptions(options) {
options.plugins ||= [];
options.plugins.unshift(RawPlugin());
return options;
},
rehypePlugins: [
rehypeSlug,
() => (tree) => {
visit(tree, "element", (node) => {
if (node.tagName === "code" && node.data && node.data.meta) {
node.properties.meta = node.data.meta;
}
});
},
],
},
});