Skip to content

Commit 1a784f3

Browse files
feat: remove trailing slash (#455)
* feat: try change output structure * added redirects
1 parent 792b951 commit 1a784f3

File tree

4 files changed

+350
-294
lines changed

4 files changed

+350
-294
lines changed

apps/blog/project.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@
105105
"options": {
106106
"command": "node apps/blog/scripts/build-routes.mjs"
107107
}
108+
},
109+
"post-prerender": {
110+
"executor": "nx:run-commands",
111+
"options": {
112+
"command": "node apps/blog/scripts/post-prerender.mjs"
113+
}
108114
}
109115
}
110116
}

apps/blog/scripts/post-prerender.mjs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { readdir, rename } from 'node:fs/promises';
2+
import { join } from 'node:path';
3+
4+
const DIST_DIR = 'dist/apps/blog';
5+
const SKIP_FOLDERS = ['assets', 'images', 'styles', 'scripts'];
6+
7+
async function renamePrerenderedFiles(dirPath = DIST_DIR) {
8+
try {
9+
const entries = await readdir(dirPath, { withFileTypes: true });
10+
11+
for (const entry of entries) {
12+
if (entry.isDirectory()) {
13+
const currentDirPath = join(dirPath, entry.name);
14+
15+
if (SKIP_FOLDERS.includes(entry.name)) {
16+
continue;
17+
}
18+
19+
const files = await readdir(currentDirPath);
20+
if (files.length === 0) {
21+
continue;
22+
}
23+
24+
if (files.length > 1) {
25+
console.error(`Multiple files in ${currentDirPath}:`, files);
26+
await renamePrerenderedFiles(currentDirPath);
27+
continue;
28+
}
29+
30+
const indexPath = join(currentDirPath, 'index.html');
31+
32+
try {
33+
await rename(indexPath, join(currentDirPath, `${entry.name}.html`));
34+
console.log(`Renamed ${indexPath} to ${entry.name}.html`);
35+
} catch (error) {
36+
if (error.code !== 'ENOENT') {
37+
console.error(`Error processing ${currentDirPath}:`, error);
38+
}
39+
}
40+
}
41+
}
42+
} catch (error) {
43+
console.error('Error during post-prerender processing:', error);
44+
process.exit(1);
45+
}
46+
}
47+
48+
renamePrerenderedFiles();

0 commit comments

Comments
 (0)