Skip to content

Commit 5d91953

Browse files
authored
chore: Added support for generating a toc file for docs (#1304)
1 parent 70d830b commit 5d91953

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed

docgen/post-process.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ async function fixTitles() {
6363
for (const file of files) {
6464
await fixTitleOf(path.join(markdownDir, file));
6565
}
66+
67+
const tocFile = path.join(markdownDir, 'toc.yaml');
68+
await fixTocTitles(tocFile);
6669
}
6770

6871
async function fixTitleOf(file) {
@@ -92,6 +95,25 @@ async function fixTitleOf(file) {
9295
}
9396
}
9497

98+
async function fixTocTitles(file) {
99+
const reader = readline.createInterface({
100+
input: fs.createReadStream(file),
101+
});
102+
103+
const buffer = [];
104+
for await (let line of reader) {
105+
if (line.includes('- title: firebase-admin.')) {
106+
line = line.replace(/firebase-admin\./, 'firebase-admin/');
107+
}
108+
109+
buffer.push(line);
110+
}
111+
112+
console.log(`Updating titles in ${file}`);
113+
const content = Buffer.from(buffer.join('\r\n'));
114+
await fs.writeFile(file, content);
115+
}
116+
95117
async function getExtraFiles() {
96118
const extrasPath = path.join(__dirname, 'extras');
97119
const files = await fs.readdir(extrasPath);

package-lock.json

Lines changed: 28 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
"test:coverage": "nyc npm run test:unit",
2121
"lint:src": "eslint src/ --ext .ts",
2222
"lint:test": "eslint test/ --ext .ts",
23-
"apidocs": "run-s api-extractor:local api-documenter api-documenter:post",
23+
"apidocs": "run-s api-extractor:local api-documenter api-documenter:toc api-documenter:post",
2424
"api-extractor": "node generate-reports.js",
2525
"api-extractor:local": "npm run build && node generate-reports.js --local",
2626
"esm-wrap": "node generate-esm-wrapper.js",
2727
"api-documenter": "api-documenter-fire markdown --input temp --output docgen/markdown -s",
28+
"api-documenter:toc": "api-documenter-fire toc --input temp --output docgen/markdown -p /docs/reference/admin/node -s",
2829
"api-documenter:post": "node docgen/post-process.js"
2930
},
3031
"nyc": {
@@ -155,7 +156,7 @@
155156
"@google-cloud/storage": "^5.3.0"
156157
},
157158
"devDependencies": {
158-
"@firebase/api-documenter": "^0.1.1",
159+
"@firebase/api-documenter": "^0.1.2",
159160
"@firebase/app": "^0.6.13",
160161
"@firebase/auth": "^0.16.2",
161162
"@firebase/auth-types": "^0.10.1",

0 commit comments

Comments
 (0)