Skip to content

Commit a7a0f31

Browse files
committed
update docs
1 parent d66ee94 commit a7a0f31

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

scripts/add-frontmatter.mjs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,30 @@ function addFrontmatter(filePath, navOrder) {
1212
// Skip if file already has frontmatter
1313
if (content.startsWith("---")) return;
1414

15+
const relPath = path.relative(DOCS_DIR, filePath);
16+
const parts = relPath.split(path.sep);
1517
const baseName = path.basename(filePath, ".md");
1618

17-
// Handle title generation
18-
let title;
19-
if (/^index$/i.test(baseName)) {
20-
// Use parent folder name for index.md files
21-
title = path.basename(path.dirname(filePath));
19+
let title, parent;
20+
if (relPath.toLowerCase() === "index.md") {
21+
// Root index.md
22+
title = "React18 Loaders"; // or "Home"
23+
} else if (/^index$/i.test(baseName)) {
24+
// index.md inside a subfolder → use folder name as title
25+
title = capitalize(parts[parts.length - 2]);
26+
if (parts.length > 2) parent = capitalize(parts[parts.length - 3] || ""); // parent folder’s parent
2227
} else {
23-
title = baseName;
28+
// Regular file
29+
title = capitalize(baseName);
30+
if (parts.length > 1) {
31+
parent = capitalize(parts[parts.length - 2]);
32+
}
2433
}
2534

26-
// Capitalize each word
27-
title = title
28-
.split(/ |-/)
29-
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
30-
.join(" ");
31-
32-
// Create YAML frontmatter
3335
const frontmatter = `---
3436
layout: default
3537
title: ${title}
36-
nav_order: ${navOrder}
38+
${parent ? `parent: ${parent}\n` : ""}nav_order: ${navOrder}
3739
---
3840
3941
`;
@@ -42,6 +44,10 @@ nav_order: ${navOrder}
4244
console.log(`✅ Added frontmatter to: ${filePath}`);
4345
}
4446

47+
function capitalize(str) {
48+
return str.replace(/[-_]/g, " ").replace(/\b\w/g, c => c.toUpperCase());
49+
}
50+
4551
/**
4652
* Recursively process directory contents, sorting so:
4753
* 1. Files before directories

0 commit comments

Comments
 (0)