Skip to content

Commit 3950de9

Browse files
committed
Update dependencies and add sitemap generation script
- Added `sitemap` package to `devDependencies` in `package.json`. - Introduced a new script `generate-sitemap.js` to create a sitemap for the project. - Updated `vite.config.js` files to use ES module syntax. - Modified `index.html` in the protocol directory to load a script as a module. - Removed outdated `pr.sh` script. - Updated various package versions in `package-lock.json` for improved compatibility and features.
1 parent 1a7c38a commit 3950de9

10 files changed

Lines changed: 5755 additions & 2301 deletions

File tree

package-lock.json

Lines changed: 3895 additions & 981 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "hello-coop",
33
"version": "1.0.0",
4+
"type": "module",
45
"main": "index.js",
56
"license": "MIT",
67
"scripts": {
@@ -14,20 +15,15 @@
1415
"build:pages": "vitepress build src/pages",
1516
"build:proto": "cd src/protocol && npm run build && cd ../../ && shx cp src/protocol/dist/index.html S3/pages/protocol.html && shx cp src/protocol/dist/assets/* S3/pages/assets/",
1617
"build": "run-s build:* && copyfiles src/index.html S3 -f && copyfiles src/assets/* S3/assets/ -f && copyfiles src/assets/scroll-anim-seq/* S3/assets/scroll-anim-seq -f",
18+
"postbuild": "node scripts/generate-sitemap.js",
1719
"preview": "vite preview --open",
1820
"test": "linkinator ./S3 --config linkinator.config.json",
19-
"test:blog": "linkinator https://blog.hello.coop --config linkinator.config.json",
20-
"pr": "./scripts/pr.sh",
21-
"rebase": "git pull origin main --rebase",
22-
"review": "npm run rebase && npm run build && npm run test && npm run pr"
23-
},
24-
"engines": {
25-
"node": "~18",
26-
"npm": "~10"
21+
"test:blog": "linkinator https://blog.hello.coop --config linkinator.config.json"
2722
},
2823
"devDependencies": {
2924
"linkinator": "^5.0.2",
3025
"shx": "^0.3.4",
26+
"sitemap": "^8.0.0",
3127
"vite": "^3.1.1",
3228
"vitepress": "^1.0.0-alpha.4",
3329
"vue": "^3.2.37"

scripts/generate-sitemap.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { SitemapStream, streamToPromise } from 'sitemap';
2+
import { createWriteStream } from 'fs';
3+
import { readdirSync, statSync } from 'fs';
4+
import path from 'path';
5+
6+
const hostname = 'https://www.hello.coop';
7+
const outputFile = 'S3/sitemap.xml';
8+
9+
function getHtmlFiles(dir, base = '') {
10+
const files = readdirSync(dir);
11+
const urls = [];
12+
for (const file of files) {
13+
const fullPath = path.join(dir, file);
14+
const stat = statSync(fullPath);
15+
if (stat.isDirectory()) {
16+
// Only recurse into subdirectories if we're not already in a pages directory
17+
if (dir === 'S3' && file === 'pages') {
18+
// Skip the pages directory when scanning root S3
19+
continue;
20+
}
21+
urls.push(...getHtmlFiles(fullPath, path.join(base, file)));
22+
} else if (file.endsWith('.html')) {
23+
// Skip 404 pages
24+
if (file === '404.html') {
25+
continue;
26+
}
27+
28+
let route;
29+
if (file === 'index.html') {
30+
// For index.html files, use the directory path
31+
route = base;
32+
} else {
33+
// For other HTML files, keep the .html extension and use the full path
34+
route = path.join(base, file);
35+
}
36+
37+
// Clean up the route
38+
route = '/' + route.replace(/\\/g, '/').replace(/^\/+/, '');
39+
if (route === '/') {
40+
route = '/';
41+
}
42+
43+
urls.push(route);
44+
}
45+
}
46+
return urls;
47+
}
48+
49+
async function generateSitemap() {
50+
const stream = new SitemapStream({ hostname });
51+
const writeStream = createWriteStream(outputFile);
52+
stream.pipe(writeStream);
53+
54+
// Collect all URLs and remove duplicates
55+
const allUrls = new Set();
56+
57+
// Process root S3 directory (for index.html and legal pages)
58+
const rootUrls = getHtmlFiles('S3');
59+
for (const url of rootUrls) {
60+
allUrls.add(url);
61+
}
62+
63+
// Process S3/pages directory (for page content)
64+
const pageUrls = getHtmlFiles('S3/pages');
65+
for (const url of pageUrls) {
66+
// Add /pages/ prefix for content pages
67+
const prefixedUrl = url === '/' ? '/pages/' : '/pages' + url;
68+
allUrls.add(prefixedUrl);
69+
}
70+
71+
// Write unique URLs to sitemap
72+
for (const url of allUrls) {
73+
stream.write({ url });
74+
}
75+
76+
stream.end();
77+
await streamToPromise(stream);
78+
console.log(`✅ Sitemap generated at ${outputFile}`);
79+
console.log(`📊 Generated ${allUrls.size} unique URLs`);
80+
}
81+
82+
generateSitemap();

scripts/pr.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/legal/vite.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const { defineConfig } = require('vite');
1+
import { defineConfig } from 'vite';
22

3-
module.exports = defineConfig({});
3+
export default defineConfig({});

src/pages/vite.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const { defineConfig } = require('vite');
1+
import { defineConfig } from 'vite';
22

3-
module.exports = defineConfig({
3+
export default defineConfig({
44
server: {
55
port: 8080
66
},

src/protocol/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<meta name="description" content="Co-operatively Building the Internet Identity Layer" />
2222
<meta name="theme-color" content="#303030">
2323
<script src="https://cdn.hello.coop/js/relative-wc-footer.js" defer></script>
24-
<script defer data-domain="hello.coop" src="/js/script.hash.js"></script>
24+
<script type="module" defer data-domain="hello.coop" src="/js/script.hash.js"></script>
2525
</head>
2626
<body class="bg-white dark:bg-[#151515] text-[#303030] dark:text-[#d4d4d4]">
2727
<div id="app"></div>

0 commit comments

Comments
 (0)