forked from railwayapp/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontentlayer.config.ts
More file actions
49 lines (47 loc) · 1.28 KB
/
contentlayer.config.ts
File metadata and controls
49 lines (47 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { defineDocumentType, makeSource } from "contentlayer/source-files";
import remarkAutoLinkHeadings from "remark-autolink-headings";
import remarkGfm from "remark-gfm";
import remarkSlug from "remark-slug";
import { execSync } from "child_process";
const Page = defineDocumentType(() => ({
name: "Page",
filePathPattern: `**/*.md`,
contentType: "mdx",
fields: {
title: {
type: "string",
description: "The title of the page",
required: true,
},
description: {
type: "string",
description: "The description of the page",
required: true,
},
},
computedFields: {
url: {
type: "string",
resolve: doc => `/${doc._raw.flattenedPath}`,
},
lastModified: {
type: "date",
resolve: doc => {
const filePath = `src/docs/${doc._raw.flattenedPath}.md`;
try {
const result = execSync(`git log -1 --format=%cI -- "${filePath}"`, {
encoding: "utf-8",
}).trim();
return result || new Date().toISOString();
} catch {
return new Date().toISOString();
}
},
},
},
}));
export default makeSource({
contentDirPath: "src/docs",
documentTypes: [Page],
mdx: { remarkPlugins: [remarkSlug, remarkAutoLinkHeadings, remarkGfm] },
});