Skip to content

Commit 4c51f76

Browse files
committed
added link of other markdown files
1 parent abd9ef2 commit 4c51f76

File tree

1 file changed

+69
-4
lines changed

1 file changed

+69
-4
lines changed

src/utilities/fetch-governance.mjs

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,30 @@ function generateTitle(filename) {
3737
.replace(/\b\w/g, (c) => c.toUpperCase());
3838
}
3939

40+
// --- Helpers for index link generation ---
41+
42+
function destSlugFromFilename(destFile) {
43+
const name = path.basename(destFile, path.extname(destFile));
44+
if (name.toLowerCase() === 'index') return '/';
45+
return `/${name}/`;
46+
}
47+
48+
function replaceRelatedSection(indexContent, relatedBlock) {
49+
const startMarker = '{/* GOV-RELATED-START */}';
50+
const endMarker = '{/* GOV-RELATED-END */}';
51+
const regex = new RegExp(`${startMarker}[\\s\\S]*?${endMarker}`, 'm');
52+
const wrappedBlock = `${startMarker}\n${relatedBlock}\n${endMarker}`;
53+
54+
if (regex.test(indexContent)) {
55+
return indexContent.replace(regex, wrappedBlock);
56+
} else {
57+
return `${indexContent}\n\n${wrappedBlock}\n`;
58+
}
59+
}
60+
4061
async function fetchGovernanceDocs() {
4162
console.log(
42-
'📦 Fetching governance markdown files from webpack/governance...\n'
63+
'Fetching governance markdown files from webpack/governance...\n'
4364
);
4465

4566
await mkdirp(outputDir);
@@ -67,11 +88,23 @@ async function fetchGovernanceDocs() {
6788
const rawUrl = file.download_url;
6889
const response = await fetch(rawUrl);
6990
const content = await response.text();
70-
71-
// Add YAML frontmatter
91+
// Add YAML frontmatter for better sidebar integration
7292
const title = generateTitle(filename);
93+
94+
// Optional ordering logic for sidebar
95+
const sortOrder =
96+
{
97+
'README.md': 0,
98+
'CHARTER.md': 1,
99+
'MEMBER_EXPECTATIONS.md': 2,
100+
'MODERATION_POLICY.md': 3,
101+
'WORKING_GROUPS.md': 4,
102+
}[filename] ?? 10;
103+
73104
const frontmatter = yamlHeadmatter({
74105
title,
106+
group: 'Governance',
107+
sort: sortOrder,
75108
source: `https://github.com/${owner}/${repo}/blob/main/${filename}`,
76109
edit: `https://github.com/${owner}/${repo}/edit/main/${filename}`,
77110
});
@@ -86,7 +119,39 @@ async function fetchGovernanceDocs() {
86119
);
87120
}
88121

89-
console.log('\n Governance content successfully synced!');
122+
// After all files are written: update index with related document links
123+
try {
124+
const indexPath = path.resolve(outputDir, 'index.mdx');
125+
let indexContent = '';
126+
127+
try {
128+
indexContent = fs.readFileSync(indexPath, 'utf8');
129+
} catch (err) {
130+
indexContent =
131+
'---\ntitle: Governance Overview\n---\n\n# Governance Overview\n\n';
132+
console.log(err);
133+
}
134+
135+
const relatedItems = Object.entries(fileMap)
136+
.filter(([key]) => key !== 'README.md')
137+
.map(([key, dest]) => {
138+
const title = generateTitle(key);
139+
const slug = destSlugFromFilename(dest);
140+
const url = `/contribute/governance${slug}`;
141+
return `- [${title}](${url})`;
142+
})
143+
.join('\n');
144+
145+
const relatedBlock = `## Related Documents\n\n${relatedItems}\n`;
146+
const newIndex = replaceRelatedSection(indexContent, relatedBlock);
147+
148+
fs.writeFileSync(indexPath, newIndex, 'utf8');
149+
console.log('Updated index.mdx with related governance links.');
150+
} catch (err) {
151+
console.error('Failed to update index links:', err);
152+
}
153+
154+
console.log('\nGovernance content successfully synced!');
90155
} catch (error) {
91156
console.error('Error fetching governance files:', error.message);
92157
process.exitCode = 1;

0 commit comments

Comments
 (0)