1- import  {  defineDocumentType ,  makeSource  }  from  'contentlayer2/source-files' 
1+ import  { 
2+   ComputedFields , 
3+   defineDocumentType , 
4+   defineNestedType , 
5+   FieldDefs , 
6+   makeSource , 
7+ }  from  'contentlayer2/source-files' 
28import  {  extractTocHeadings  }  from  './src/mdx/remark-toc-headings.mjs' 
39import  path  from  'path' 
410import  fs  from  'fs' 
@@ -7,87 +13,126 @@ const contentDirPath = 'docs'
713
814const  branch  =  process . env . NEXT_PUBLIC_GITHUB_BRANCH  ||  'main' 
915
16+ const  baseFields : FieldDefs  =  { 
17+   title_seo : { 
18+     type : 'string' , 
19+     description :
20+       'The meta title of the doc, this will override the title extracted from the markdown and the nav title' , 
21+   } , 
22+   description : { 
23+     type : 'string' , 
24+     description : 'The description of the doc' , 
25+   } , 
26+   image : { 
27+     type : 'string' , 
28+     description : 'The image of the doc' , 
29+   } , 
30+   image_alt : { 
31+     type : 'string' , 
32+     description : 'The image alt of the doc' , 
33+   } , 
34+   disable_edit : { 
35+     type : 'boolean' , 
36+     description : 'Disable the github edit button' , 
37+   } , 
38+ } 
39+ 
40+ const  computedFields : ComputedFields  =  { 
41+   slug : { 
42+     type : 'string' , 
43+     resolve : ( doc )  =>  doc . _raw . flattenedPath , 
44+   } , 
45+   toc : {  type : 'json' ,  resolve : ( doc )  =>  extractTocHeadings ( doc . body . raw )  } , 
46+   title : { 
47+     type : 'string' , 
48+     resolve : async  ( doc )  =>  { 
49+       const  headings  =  await  extractTocHeadings ( doc . body . raw ,  [ 1 ] ) 
50+ 
51+       return  headings [ 0 ] ?. value 
52+     } , 
53+   } , 
54+   editUrl : { 
55+     type : 'string' , 
56+     resolve : ( doc )  => 
57+       `https://github.com/nitrictech/docs/edit/${ branch }  /docs/${ doc . _raw . sourceFilePath }  ` , 
58+   } , 
59+   lastModified : { 
60+     type : 'date' , 
61+     resolve : ( doc )  =>  { 
62+       // Get the full path to the markdown file 
63+       const  filePath  =  path . join ( 
64+         process . cwd ( ) , 
65+         contentDirPath , 
66+         doc . _raw . sourceFilePath , 
67+       ) 
68+       // Extract and return the last modified date 
69+       const  stats  =  fs . statSync ( filePath ) 
70+       return  stats . mtime  // This is the last modified date 
71+     } , 
72+   } , 
73+ } 
74+ 
1075const  Doc  =  defineDocumentType ( ( )  =>  ( { 
1176  name : 'Doc' , 
12-   filePathPattern : '**/*.mdx' , 
77+   filePathPattern : '!**/guides/**/*.mdx' , 
78+   fields : baseFields , 
79+   computedFields, 
80+ } ) ) 
81+ 
82+ const  Featured  =  defineNestedType ( ( )  =>  ( { 
83+   name : 'Featured' , 
1384  fields : { 
14-     title_seo : { 
15-       type : 'string' , 
16-       description :
17-         'The meta title of the doc, this will override the title extracted from the markdown and the nav title' , 
18-     } , 
19-     description : { 
20-       type : 'string' , 
21-       description : 'The description of the doc' , 
22-     } , 
2385    image : { 
2486      type : 'string' , 
25-       description : 'The image of the doc' , 
87+       description : 'The featured image of the post, not the same as og image' , 
88+       required : true , 
2689    } , 
2790    image_alt : { 
2891      type : 'string' , 
29-       description : 'The image alt of the doc' , 
92+       description : 'The featured image alt of the post' , 
93+       required : true , 
94+     } , 
95+   } , 
96+ } ) ) 
97+ 
98+ const  Guide  =  defineDocumentType ( ( )  =>  ( { 
99+   name : 'Guide' , 
100+   filePathPattern : '**/guides/**/*.mdx' , 
101+   fields : { 
102+     ...baseFields , 
103+     published_at : { 
104+       type : 'date' , 
105+       description : 'The date the guide was published' , 
106+       required : false , 
30107    } , 
31-     disable_edit : { 
32-       type : 'boolean ' , 
33-       description :  'Disable the github edit button' , 
108+     featured : { 
109+       type : 'nested ' , 
110+       of :  Featured , 
34111    } , 
35112    tags : { 
36113      type : 'list' , 
37114      of : { 
38115        type : 'string' , 
39116      } , 
40-       description : 'The tags of the post, used by guides' , 
117+       description : 'The tags of the post' , 
118+       required : true , 
41119    } , 
42120    languages : { 
43121      type : 'list' , 
44122      of : { 
45123        type : 'string' , 
46124      } , 
47-       description : 'The languages of the content, used by guides ' , 
125+       description : 'The languages of the content' , 
48126    } , 
49127    start_steps : { 
50128      type : 'markdown' , 
51-       description : 'The start steps of the doc, used by guides' , 
52-     } , 
53-   } , 
54-   computedFields : { 
55-     slug : { 
56-       type : 'string' , 
57-       resolve : ( doc )  =>  doc . _raw . flattenedPath , 
58-     } , 
59-     toc : {  type : 'json' ,  resolve : ( doc )  =>  extractTocHeadings ( doc . body . raw )  } , 
60-     title : { 
61-       type : 'string' , 
62-       resolve : async  ( doc )  =>  { 
63-         const  headings  =  await  extractTocHeadings ( doc . body . raw ,  [ 1 ] ) 
64- 
65-         return  headings [ 0 ] ?. value 
66-       } , 
67-     } , 
68-     editUrl : { 
69-       type : 'string' , 
70-       resolve : ( doc )  => 
71-         `https://github.com/nitrictech/docs/edit/${ branch }  /docs/${ doc . _raw . sourceFilePath }  ` , 
72-     } , 
73-     lastModified : { 
74-       type : 'date' , 
75-       resolve : ( doc )  =>  { 
76-         // Get the full path to the markdown file 
77-         const  filePath  =  path . join ( 
78-           process . cwd ( ) , 
79-           contentDirPath , 
80-           doc . _raw . sourceFilePath , 
81-         ) 
82-         // Extract and return the last modified date 
83-         const  stats  =  fs . statSync ( filePath ) 
84-         return  stats . mtime  // This is the last modified date 
85-       } , 
129+       description : 'The start steps of the doc' , 
86130    } , 
87131  } , 
132+   computedFields, 
88133} ) ) 
89134
90135export  default  makeSource ( { 
91136  contentDirPath, 
92-   documentTypes : [ Doc ] , 
137+   documentTypes : [ Doc ,   Guide ] , 
93138} ) 
0 commit comments