Skip to content

Commit e960e1f

Browse files
committed
Added a custom documentation title: Create a post-processing script to replace JSDoc default title with 'Notes API Documentation'
1 parent fab3768 commit e960e1f

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

jsdoc.config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"opts": {
88
"destination": "./docs/",
99
"recurse": true,
10-
"readme": "./README.md"
10+
"readme": "./README.md",
11+
"title": "Notes API Documentation"
1112
},
1213
"plugins": ["plugins/markdown"],
1314
"templates": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
1212
"test:coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
1313
"start": "node src/notes-api-server.js",
14-
"docs": "jsdoc -c jsdoc.config.json",
14+
"docs": "jsdoc -c jsdoc.config.json && node scripts/fix-docs-title.js",
1515
"docs:watch": "jsdoc -c jsdoc.config.json --watch",
1616
"docs:version": "node scripts/version-docs.js",
1717
"docs:serve": "cd docs && python3 -m http.server 8080",

scripts/fix-docs-title.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Post-processing script to fix JSDoc HTML titles
5+
* Updates "JSDoc: Home" to a more meaningful title
6+
*/
7+
8+
import fs from 'fs';
9+
import path from 'path';
10+
11+
const DOCS_DIR = 'docs';
12+
const OLD_TITLE = 'JSDoc: Home';
13+
const NEW_TITLE = 'Notes API Documentation';
14+
15+
/**
16+
* Recursively find and update HTML files in the docs directory
17+
*/
18+
function updateHTMLTitles(dir) {
19+
const files = fs.readdirSync(dir);
20+
21+
for (const file of files) {
22+
const filePath = path.join(dir, file);
23+
const stat = fs.statSync(filePath);
24+
25+
if (stat.isDirectory()) {
26+
updateHTMLTitles(filePath);
27+
} else if (file.endsWith('.html')) {
28+
updateHTMLFile(filePath);
29+
}
30+
}
31+
}
32+
33+
/**
34+
* Update title in a single HTML file
35+
*/
36+
function updateHTMLFile(filePath) {
37+
const content = fs.readFileSync(filePath, 'utf8');
38+
39+
// Replace the title tag
40+
const updatedContent = content.replace(
41+
`<title>${OLD_TITLE}</title>`,
42+
`<title>${NEW_TITLE}</title>`
43+
);
44+
45+
// Also update page title heading if it's the home page
46+
const finalContent = updatedContent.replace(
47+
'<h1 class="page-title">Home</h1>',
48+
'<h1 class="page-title">Notes API Documentation</h1>'
49+
);
50+
51+
if (content !== finalContent) {
52+
fs.writeFileSync(filePath, finalContent);
53+
console.log(`✅ Updated title in ${filePath}`);
54+
}
55+
}
56+
57+
// Run if called directly
58+
if (import.meta.url === `file://${process.argv[1]}`) {
59+
console.log('🔧 Fixing documentation titles...');
60+
61+
if (!fs.existsSync(DOCS_DIR)) {
62+
console.error(`❌ Documentation directory '${DOCS_DIR}' not found`);
63+
process.exit(1);
64+
}
65+
66+
updateHTMLTitles(DOCS_DIR);
67+
console.log('✅ Documentation titles updated successfully');
68+
}

0 commit comments

Comments
 (0)