contentlayer.config.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import { defineDocumentType, makeSource } from "contentlayer/source-files"
  2. // import rehypeAutolinkHeadings from "rehype-autolink-headings"
  3. // import rehypePrettyCode from "rehype-pretty-code"
  4. // import rehypeSlug from "rehype-slug"
  5. // import remarkGfm from "remark-gfm"
  6. import { remarkPlugins } from './mdx/remark'
  7. import { rehypePlugins } from './mdx/rehype'
  8. import { recmaPlugins } from './mdx/recma'
  9. /** @type {import('contentlayer/source-files').ComputedFields} */
  10. const computedFields = {
  11. slug: {
  12. type: "string",
  13. resolve: (doc) => `/${doc._raw.flattenedPath}`,
  14. },
  15. slugAsParams: {
  16. type: "string",
  17. resolve: (doc) => doc._raw.flattenedPath.split("/").slice(1).join("/"),
  18. }
  19. }
  20. export const Doc = defineDocumentType(() => ({
  21. name: "Doc",
  22. filePathPattern: `docs/**/*.mdx`,
  23. contentType: "mdx",
  24. fields: {
  25. title: {
  26. type: "string",
  27. required: true,
  28. },
  29. description: {
  30. type: "string",
  31. },
  32. published: {
  33. type: "boolean",
  34. default: true,
  35. },
  36. bootstrapLink: {
  37. type: "string",
  38. },
  39. libs: {
  40. type: "string"
  41. },
  42. banner: {
  43. type: "string"
  44. },
  45. plugin: {
  46. type: "string"
  47. },
  48. new: {
  49. type: "boolean",
  50. default: false,
  51. }
  52. },
  53. computedFields
  54. }))
  55. export const Guide = defineDocumentType(() => ({
  56. name: "Guide",
  57. filePathPattern: `guides/**/*.mdx`,
  58. contentType: "mdx",
  59. fields: {
  60. title: {
  61. type: "string",
  62. required: true,
  63. },
  64. description: {
  65. type: "string",
  66. },
  67. date: {
  68. type: "date",
  69. required: true,
  70. },
  71. published: {
  72. type: "boolean",
  73. default: true,
  74. },
  75. featured: {
  76. type: "boolean",
  77. default: false,
  78. },
  79. seoTitle: {
  80. type: "string",
  81. },
  82. imageTitle: {
  83. type: "string",
  84. },
  85. summary: {
  86. type: "string",
  87. },
  88. imageEmail: {
  89. type: "string",
  90. },
  91. done: {
  92. type: "boolean",
  93. default: false,
  94. },
  95. image: {
  96. type: "string",
  97. },
  98. tags: {
  99. type: "list",
  100. of: { type: "string" },
  101. default: [],
  102. }
  103. },
  104. computedFields
  105. }))
  106. export const Post = defineDocumentType(() => ({
  107. name: "Post",
  108. filePathPattern: `blog/*.mdx`,
  109. contentType: "mdx",
  110. fields: {
  111. title: {
  112. type: "string",
  113. required: true,
  114. },
  115. description: {
  116. type: "string",
  117. },
  118. date: {
  119. type: "date",
  120. required: true,
  121. },
  122. published: {
  123. type: "boolean",
  124. default: true,
  125. },
  126. image: {
  127. type: "string",
  128. required: false,
  129. },
  130. summary: {
  131. type: "string",
  132. },
  133. product: {
  134. type: "string",
  135. },
  136. author: {
  137. type: "string",
  138. required: false,
  139. default: "codecalm",
  140. },
  141. video: {
  142. type: "string",
  143. },
  144. keywords: {
  145. type: "list",
  146. of: { type: "string" },
  147. default: [],
  148. }
  149. },
  150. computedFields,
  151. }))
  152. export const Changelog = defineDocumentType(() => ({
  153. name: "Changelog",
  154. filePathPattern: `changelog/*.mdx`,
  155. contentType: "mdx",
  156. fields: {
  157. date: {
  158. type: "date",
  159. required: true,
  160. },
  161. version: {
  162. type: "string",
  163. required: true,
  164. },
  165. title: {
  166. type: "string"
  167. },
  168. },
  169. }))
  170. // export const Author = defineDocumentType(() => ({
  171. // name: "Author",
  172. // filePathPattern: `authors/**/*.mdx`,
  173. // contentType: "mdx",
  174. // fields: {
  175. // title: {
  176. // type: "string",
  177. // required: true,
  178. // },
  179. // description: {
  180. // type: "string",
  181. // },
  182. // avatar: {
  183. // type: "string",
  184. // required: true,
  185. // },
  186. // twitter: {
  187. // type: "string",
  188. // required: true,
  189. // },
  190. // },
  191. // computedFields,
  192. // }))
  193. export const Page = defineDocumentType(() => ({
  194. name: "Page",
  195. filePathPattern: `pages/**/*.mdx`,
  196. contentType: "mdx",
  197. fields: {
  198. title: {
  199. type: "string",
  200. required: true,
  201. },
  202. description: {
  203. type: "string",
  204. },
  205. bodyClassName: {
  206. type: "string",
  207. },
  208. hidden: {
  209. type: "boolean",
  210. default: false,
  211. }
  212. },
  213. computedFields,
  214. }))
  215. export default makeSource({
  216. contentDirPath: "./content",
  217. documentTypes: [
  218. Page,
  219. Doc,
  220. Guide,
  221. Post,
  222. Changelog,
  223. // Author
  224. ],
  225. mdx: {
  226. remarkPlugins,
  227. rehypePlugins,
  228. recmaPlugins,
  229. },
  230. })