contentlayer.config.js 4.2 KB

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