Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ out
/pages/loaders
/pages/plugins
/generated
/pages/about/governance
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build:md": "npm-run-all build:md:*",
"build:md:api": "node scripts/markdown/api.mjs",
"build:md:readmes": "node scripts/markdown/readmes.mjs",
"build:md:governance": "node scripts/markdown/governance.mjs",
"build:html": "node scripts/html/index.mjs",
"build": "npm-run-all build:*",
"lint": "npm-run-all \"lint:!(fix)\"",
Expand Down
5 changes: 5 additions & 0 deletions pages/site.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { sidebar as _sidebar } from './site.json' with { type: 'json' };
import loaders from './loaders/site.json' with { type: 'json' };
import plugins from './plugins/site.json' with { type: 'json' };
import contribute from './about/governance/site.json' with { type: 'json' };
Comment on lines 1 to +4

Comment on lines 2 to 5
export * from './site.json' with { type: 'json' };

Expand All @@ -10,4 +11,8 @@ export const sidebar = [
groupName: 'Loaders & Plugins',
items: [...loaders.sidebar, ...plugins.sidebar],
},
{
groupName: 'About',
items: contribute.sidebar,
},
];
95 changes: 95 additions & 0 deletions scripts/markdown/governance.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { mkdir, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const { GH_TOKEN } = process.env;

const BASE_HEADERS = {
...(GH_TOKEN && { Authorization: `Bearer ${GH_TOKEN}` }),
};
Comment on lines +4 to +8

// Maps source filenames in webpack/governance repo to their output slug and sidebar label.
// Insertion order determines sidebar order, this could be changed as per need.
const FILE_MAP = {
Comment on lines +10 to +12
'README.md': { output: 'index', label: 'Governance Overview' },
'CHARTER.md': { output: 'charter', label: 'Charter' },
'MEMBER_EXPECTATIONS.md': {
output: 'member-expectations',
label: 'Member Expectations',
},
'MODERATION_POLICY.md': {
output: 'moderation-policy',
label: 'Moderation Policy',
},
'WORKING_GROUPS.md': { output: 'working-groups', label: 'Working Groups' },
'AI_POLICY.md': { output: 'ai-policy', label: 'AI Policy' },
};

// Derived from FILE_MAP - stays in sync automatically if entries are added/removed.
const LINK_REWRITE_MAP = Object.fromEntries(
Object.entries(FILE_MAP).map(([source, { output }]) => [
source,
`/about/governance/${output}`,
])
);
Comment on lines +27 to +33

// Rewrites relative cross-references between governance docs.
// Covers both inline [text](./FILE.md) and reference-style [label]: ./FILE.md.
// Negative lookaheads prevent rewriting absolute URLs that happen to end in a known filename.
const rewriteLinks = content =>
content.replace(
/(\]\(|\]:\s*)(?!https?:\/\/)(?!\/)(\.\/)?([A-Z_]+\.md)/g,
(match, prefix, _dot, filename) =>
LINK_REWRITE_MAP[filename]
? `${prefix}${LINK_REWRITE_MAP[filename]}`
: match
);

const outputDir = join(
import.meta.dirname,
'..',
'..',
'pages',
'about',
'governance'
);
Comment on lines +51 to +54
await mkdir(outputDir, { recursive: true });

const results = await Promise.all(
Object.entries(FILE_MAP).map(async ([source, { output, label }]) => {
const url = `https://raw.githubusercontent.com/webpack/governance/HEAD/${source}`;
const res = await fetch(url, { headers: BASE_HEADERS });

if (!res.ok) {
console.error(`Failed: ${source} -> ${res.status} ${res.statusText}`);
return null;
}
Comment thread
avivkeller marked this conversation as resolved.

const content = `---\nsource: ${url}\n---\n\n${rewriteLinks(await res.text())}`;
await writeFile(join(outputDir, `${output}.md`), content, 'utf8');
console.log(`Fetched: ${source} -> ${output}.md`);
return { output, label };
})
);

const fetched = results.filter(Boolean);

const siteJson = {
sidebar: [
{
label: 'Governance',
items: fetched.map(({ output, label }) => ({
link: `/about/governance/${output}`,
label,
})),
},
],
};
Comment on lines +76 to +86

await writeFile(
join(outputDir, 'site.json'),
JSON.stringify(siteJson, null, 2) + '\n',
'utf8'
);
console.log(
`Written: pages/about/governance/site.json (${fetched.length} pages)`
);