-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdocs.config.js
153 lines (148 loc) · 4.82 KB
/
docs.config.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const path = require("node:path");
const {
frontMatterFileReader,
navigationFileReader,
vueFileReader,
} = require("@forsakringskassan/docs-generator");
/**
* Set document attributes.
*
* @param {import("@forsakringskassan/docs-generator").Document} doc
* @param {string} name
* @param {{ layout?: string, sortorder?: number}} [attributes]
*/
function transformAttributes(doc, name, attributes = {}) {
const { layout, sortorder } = attributes;
doc.name = name;
doc.template = layout ?? "default";
doc.attributes.layout = layout;
doc.attributes.sortorder = sortorder;
}
/**
* Extracts the h1 heading and sets the document title.
*
* @param {import("@forsakringskassan/docs-generator").Document} doc
*/
function transformHeading(doc) {
doc.body = doc.body.replace(/^# ([^\n]*)[\n]+/, (_, title) => {
doc.attributes.title = title;
return "";
});
doc.outline = doc.outline[0].subheadings;
}
/**
* Rewrite the document path, i.e. where the document should be written relative
* to the output folder. Must start with `./`.
*
* @param {import("@forsakringskassan/docs-generator").Document} doc
* @param {string} filePath
*/
function transformPath(doc, filePath) {
const parsed = path.parse(filePath);
doc.fileInfo.path = parsed.dir;
doc.fileInfo.name = parsed.name;
doc.fileInfo.outputName = parsed.base;
}
module.exports = {
site: {
name: "FK Designsystem",
lang: "sv",
},
outputFolder: "./public",
cacheFolder: "./temp/docs",
exampleFolders: ["./packages/vue/src", "./docs"],
templateFolders: ["./docs/templates"],
setupPath: path.resolve("docs/src/setup.ts"),
sourceFiles: [
{
include: "docs/**/*.md",
exclude: ["docs/node_modules/**", "docs/examples/**"],
basePath: "docs",
fileReader: frontMatterFileReader,
transform(doc) {
const { fullPath } = doc.fileInfo;
const dirname = path.dirname(fullPath);
const basename = path.basename(dirname);
const filename = path.basename(fullPath, ".md");
/* transform output path from "FoobarComponent/FoobarComponent-method.md" to "FoobarComponent/method.html" */
if (filename.startsWith(`${basename}-`)) {
const n = basename.length + 1;
doc.fileInfo.outputName = doc.fileInfo.outputName.slice(n);
}
return doc;
},
},
{
include: "docs/*/**/*.json",
exclude: ["docs/node_modules/**", "docs/examples/**"],
basePath: "docs",
fileReader: navigationFileReader,
},
{
include: "./CHANGELOG.md",
basePath: "./",
fileReader: frontMatterFileReader,
transform(doc) {
transformAttributes(doc, "changelog");
transformHeading(doc);
return doc;
},
},
{
include: "./CONTRIBUTING.md",
basePath: "./",
fileReader: frontMatterFileReader,
transform(doc) {
transformAttributes(doc, "contributing", {
layout: "pattern",
sortorder: 1,
});
transformHeading(doc);
transformPath(
doc,
"./gettingstarted/contribute-to-fkds/index.html",
);
return doc;
},
},
{
include: "./TESTING.md",
basePath: "./",
fileReader: frontMatterFileReader,
transform(doc) {
transformAttributes(doc, "testing", {
layout: "pattern",
sortorder: 3,
});
transformHeading(doc);
transformPath(
doc,
"./gettingstarted/contribute-to-fkds/testing.html",
);
return doc;
},
},
{
include: "docs-alt/**/*.md",
basePath: "docs-alt",
fileReader: frontMatterFileReader,
transform(doc) {
// Do not write to file. Equivalent to frontmatter `include: false`.
doc.fileInfo.outputName = false;
return doc;
},
},
{
include: [
"./packages/vue/src/components/**/*.vue",
"./packages/vue/src/internal-components/**/*.vue",
"./packages/vue/src/design-components-test/**/*.vue",
],
exclude: [
"./packages/vue/src/**/examples/*.vue",
"./packages/vue/src/**/ct/*.vue",
],
fileReader: vueFileReader,
},
],
};