Skip to content

Commit 179a94c

Browse files
committed
Add postbuild script to fix asset paths
1 parent bc42cea commit 179a94c

File tree

4 files changed

+28
-9
lines changed

4 files changed

+28
-9
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,9 @@ jobs:
2222
npm ci
2323
npm run build
2424
25-
- name: Rename _next directory
26-
run: mv build/_next build/static-assets # Rename _next to static-assets
27-
2825
- name: Deploy 🚀
2926
uses: JamesIves/github-pages-deploy-action@v4
3027
with:
3128
branch: gh-pages
32-
folder: build
33-
token: ${{ secrets.GITHUB_TOKEN }}
29+
folder: out
30+
token: ${{ secrets.GITHUB_TOKEN }}

next.config.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
output: 'export',
4-
distDir: 'build',
54
basePath: '',
6-
assetPrefix: 'https://vaqm2.github.io/static-assets/',
5+
assetPrefix: '',
76
images: {
87
unoptimized: true,
98
},
109
};
1110

12-
export default nextConfig;
11+
export default nextConfig;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"dev": "next dev --turbopack",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "next lint",
9+
"lint": "next lint",
10+
"postbuild": "node scripts/fix-paths.js"
11+
},,
1012
"deploy": "gh-pages -d out"
1113
},
1214
"dependencies": {

scripts/fix-paths.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const buildDir = path.join(process.cwd(), 'out');
5+
6+
function fixPaths(dir) {
7+
fs.readdirSync(dir).forEach(file => {
8+
const filePath = path.join(dir, file);
9+
if (fs.statSync(filePath).isDirectory()) {
10+
fixPaths(filePath);
11+
} else if (filePath.endsWith('.html')) {
12+
let content = fs.readFileSync(filePath, 'utf8');
13+
content = content.replace(/_next\/static\/css/g, 'static/css');
14+
content = content.replace(/_next\/static\/media/g, 'static/media');
15+
fs.writeFileSync(filePath, content);
16+
}
17+
});
18+
}
19+
20+
fixPaths(buildDir);
21+
console.log('Fixed asset paths in HTML files.');

0 commit comments

Comments
 (0)