Skip to content

Commit 9d1a76b

Browse files
Update createDocs.js
Adjust auto-generated MD heading levels to create a clean table of contents in GitBook. Refer to inline comments for more information.
1 parent 5df9cf8 commit 9d1a76b

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

docs/createDocs.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function createFile(filePath, options, outputDir) {
6565
//const template = `{{#class name="${className}"}}{{>docs}}{{/class}}`
6666
console.log(`rendering ${filePath}`)
6767
const output = jsdoc2md.renderSync(options)
68-
fs.writeFileSync(path.resolve(outputDir, `${fileName}.md`), output)
68+
fs.writeFileSync(path.resolve(outputDir, `${fileName}.md`), setHeadings(fileName, output))
6969
}
7070
////([\w-]+)(.js)/
7171
function getFileName(filePath) {
@@ -128,6 +128,52 @@ function formatDataOrder(dataProvider, orderMenu) {
128128
return tt
129129
}
130130

131+
function setHeadings(sFileNm, sMD) {
132+
133+
/**
134+
* Adjust MD heading levels to create a clean
135+
* table of contents in GitBook. This method
136+
* replaces the docsify _sidebar.md file.
137+
*
138+
* Notes:
139+
*
140+
* 1. This is a quick-fix for basic compliance with the GitBook framework.
141+
* 2. Expression "~~" renders text as strikethrough for highlighting deprecations.
142+
* 3. Inconsistent use of constants requires a fix.
143+
*/
144+
145+
const cHdrLv = "##### ";
146+
const cWOQL = "WOQL.";
147+
const cWOQLClient = "woqlClient.";
148+
const cWOQLLib = "woqlLibrary.";
149+
const cAccessCtrl = "accessControl.";
150+
151+
// No action for sidebar (code to create sidebar can be deprecated.)
152+
153+
if (sFileNm.match("sidebar"))
154+
return sMD;
155+
156+
// Simplified pattern for type definitions.
157+
158+
if (sFileNm.match("typedef.js"))
159+
return sMD.
160+
replace(/## /g, "# ").
161+
replace(/### /g, cHdrLv);
162+
163+
// All other patterns.
164+
165+
return sMD.
166+
replace(/##/g, "#").
167+
replace(/## ~~WOQL\./g, `${cHdrLv}~~${cWOQL}`).
168+
replace(/## ~~woqlClient\./g, `${cHdrLv}~~${cWOQLClient}`).
169+
replace(/## ~~woqlLibrary\./g, `${cHdrLv}~~${cWOQLLib}`).
170+
replace(/## ~~accessControl\./g, `${cHdrLv}~~${cAccessCtrl}`).
171+
replace(/## WOQL\./g, `${cHdrLv}${cWOQL}`).
172+
replace(/## woqlClient\./g, `${cHdrLv}${cWOQLClient}`).
173+
replace(/## woqlLibrary\./g, `${cHdrLv}${cWOQLLib}`).
174+
replace(/## accessControl\./g, `${cHdrLv}${cAccessCtrl}`);
175+
}
176+
131177
/*
132178
{
133179
"id": "WOQLClient",

0 commit comments

Comments
 (0)