@@ -17,7 +17,6 @@ import rehypeAutolinkHeadings from "rehype-autolink-headings";
1717
1818import { highlight } from "./src/utils/shiki" ;
1919import { rehypeShikiOptions } from "./src/mdx/plugins/rehypeShiki" ;
20- import { getTableOfContents } from "./src/mdx/plugins/generateToC" ;
2120import { rehypeComponent } from "./src/mdx/plugins/rehypeComponent" ;
2221import { rehypeReactDoc } from "./src/mdx/plugins/rehypeReactDoc" ;
2322import { HEADING_LINK_ANCHOR } from "./src/components/ui/headings" ;
@@ -26,22 +25,29 @@ import { HEADING_LINK_ANCHOR } from "./src/components/ui/headings";
2625const docSchema = z . object ( {
2726 title : z . string ( ) ,
2827 description : z . string ( ) ,
29- category : z . string ( ) ,
28+ category : z . string ( ) . array ( ) ,
3029 content : z . string ( ) ,
3130} ) ;
3231
3332type DocSchema = z . infer < typeof docSchema > ;
3433type DocsDocument = Document & DocSchema ;
3534
35+ interface DocTransformParams {
36+ folder : string ;
37+ subFolder ?: string ;
38+ document : DocsDocument ;
39+ context : Context ;
40+ }
41+
3642// Transform:
37- const docTransform = async (
38- folder : string ,
39- document : DocsDocument ,
40- context : Context ,
41- ) => {
43+ const docTransform = async ( {
44+ folder,
45+ subFolder,
46+ document,
47+ context,
48+ } : DocTransformParams ) => {
4249 const highlighter = await highlight ( ) ;
43- const tableOfContents = getTableOfContents ( document . content ) ;
44- const mdx = await compileMDX ( context , document , {
50+ const code = await compileMDX ( context , document , {
4551 remarkPlugins : [ remarkGfm ] ,
4652 rehypePlugins : [
4753 rehypeComponent ,
@@ -62,18 +68,24 @@ const docTransform = async (
6268 return {
6369 ...document ,
6470 folder,
65- tableOfContents ,
66- mdx,
71+ subFolder ,
72+ mdx : code ,
6773 } ;
6874} ;
6975
7076// Collections:
7177const generalDocs = defineCollection ( {
7278 name : "general" ,
7379 directory : "src/docs" ,
74- include : "**/* .mdx" ,
80+ include : "*.mdx" ,
7581 schema : docSchema ,
76- transform : ( document , context ) => docTransform ( "general" , document , context ) ,
82+ transform : ( document , context ) =>
83+ docTransform ( { folder : "general" , document, context } ) ,
84+ onSuccess : ( docs ) => {
85+ console . log (
86+ `|- (content-collections) ✅ generalDocs Collection - Successfully processed ${ docs . length } documents.` ,
87+ ) ;
88+ } ,
7789} ) ;
7890
7991const gstartedDocs = defineCollection ( {
@@ -82,26 +94,62 @@ const gstartedDocs = defineCollection({
8294 include : "**/*.mdx" ,
8395 schema : docSchema ,
8496 transform : ( document , context ) =>
85- docTransform ( "getting-started" , document , context ) ,
97+ docTransform ( { folder : "getting-started" , document, context } ) ,
98+ onSuccess : ( docs ) => {
99+ console . log (
100+ `|- (content-collections) ✅ getting-started Collection - Successfully processed ${ docs . length } documents.` ,
101+ ) ;
102+ } ,
86103} ) ;
87104
88- const componentsDocs = defineCollection ( {
89- name : "components " ,
90- directory : "src/docs/components " ,
105+ const reactDocs = defineCollection ( {
106+ name : "react " ,
107+ directory : "src/docs/react " ,
91108 include : "**/*.mdx" ,
92109 schema : docSchema ,
93110 transform : ( document , context ) =>
94- docTransform ( "components" , document , context ) ,
111+ docTransform ( { folder : "react" , document, context } ) ,
112+ onSuccess : ( docs ) => {
113+ console . log (
114+ `|- (content-collections) ✅ react Collection - Successfully processed ${ docs . length } documents.` ,
115+ ) ;
116+ } ,
95117} ) ;
96118
97119const shikiDocs = defineCollection ( {
98120 name : "shiki" ,
99121 directory : "src/docs/shiki" ,
100122 include : "**/*.mdx" ,
101123 schema : docSchema ,
102- transform : ( document , context ) => docTransform ( "shiki" , document , context ) ,
124+ transform : ( document , context ) =>
125+ docTransform ( { folder : "shiki" , document, context } ) ,
126+ onSuccess : ( docs ) => {
127+ console . log (
128+ `|- (content-collections) ✅ shiki Collection - Successfully processed ${ docs . length } documents.` ,
129+ ) ;
130+ } ,
131+ } ) ;
132+
133+ const sugarHighDocs = defineCollection ( {
134+ name : "shigh" ,
135+ directory : "src/docs/sugar-high" ,
136+ include : "**/*.mdx" ,
137+ schema : docSchema ,
138+ transform : ( document , context ) =>
139+ docTransform ( { folder : "sugar-high" , document, context } ) ,
140+ onSuccess : ( docs ) => {
141+ console . log (
142+ `|- (content-collections) ✅ sugar-high Collection - Successfully processed ${ docs . length } documents.` ,
143+ ) ;
144+ } ,
103145} ) ;
104146
105147export default defineConfig ( {
106- collections : [ generalDocs , gstartedDocs , componentsDocs , shikiDocs ] ,
148+ collections : [
149+ generalDocs ,
150+ gstartedDocs ,
151+ reactDocs ,
152+ shikiDocs ,
153+ sugarHighDocs ,
154+ ] ,
107155} ) ;
0 commit comments