forked from webpack/webpack.js.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch-footer.mjs
More file actions
56 lines (44 loc) · 1.56 KB
/
fetch-footer.mjs
File metadata and controls
56 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { writeFile, mkdir } from 'fs/promises';
import path from 'path';
const ARTWORK_README_URL =
'https://raw.githubusercontent.com/openjs-foundation/artwork/main/README.md';
const OUTPUT_PATH = path.resolve(
'src/components/Footer/_footer-legal.json'
);
async function fetchFooter() {
console.log('Fetching OpenJS Foundation footer template...');
const response = await fetch(ARTWORK_README_URL);
if (!response.ok) {
throw new Error(`Failed to fetch artwork README: ${response.status}`);
}
const readme = await response.text();
// Extract the HTML block under "### HTML"
const htmlSectionMatch = readme.match(
/### HTML\s*\n+```html\s*\n([\s\S]*?)\n```/
);
if (!htmlSectionMatch) {
throw new Error(
'Could not find HTML footer template in artwork README'
);
}
const html = htmlSectionMatch[1].trim();
// Parse links from the footer HTML
const linkRegex = /<a\s+href="([^"]+)">([^<]+)<\/a>/g;
const paragraphs = html.split('</p>');
// Second paragraph contains the links bar
const linksSection = paragraphs.length > 1 ? paragraphs[1] : '';
const links = [];
let match;
while ((match = linkRegex.exec(linksSection)) !== null) {
links.push({ url: match[1], label: match[2] });
}
const data = { links };
await mkdir(path.dirname(OUTPUT_PATH), { recursive: true });
await writeFile(OUTPUT_PATH, JSON.stringify(data, null, 2));
console.log(`Footer data written to ${OUTPUT_PATH}`);
console.log(`Found ${links.length} footer links`);
}
fetchFooter().catch((err) => {
console.error('Error fetching footer:', err);
process.exit(1);
});