Skip to content

Commit f93682b

Browse files
Merge pull request #149 from alvin000009238/fix-css-for-privacy-policy-page-2026-04-07-02-03-54
Fix privacy page stylesheet hash syncing
2 parents 74061ea + 9e9ac02 commit f93682b

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

public/privacy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<link
1515
href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Noto+Sans+TC:wght@400;500;700&display=swap"
1616
rel="stylesheet">
17-
<link rel="stylesheet" href="/dist/main-BitnWYKi.css">
17+
<link rel="stylesheet" href="/dist/main-bt8E1vXG.css" id="vite-css">
1818
<link rel="icon" type="image/x-icon" href="/favicon.ico">
1919
<style>
2020
.privacy-container {

scripts/inject-hash.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const __dirname = path.dirname(__filename);
77

88
const projectRoot = path.resolve(__dirname, '..');
99
const manifestPath = path.resolve(projectRoot, 'public/dist/.vite/manifest.json');
10-
const htmlPath = path.resolve(projectRoot, 'public/index.html');
10+
const htmlPaths = [
11+
path.resolve(projectRoot, 'public/index.html'),
12+
path.resolve(projectRoot, 'public/privacy.html')
13+
];
1114

1215
try {
1316
// 1. Read manifest.json
@@ -18,10 +21,15 @@ try {
1821

1922
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf-8'));
2023

21-
let html = fs.readFileSync(htmlPath, 'utf-8');
22-
23-
// Iterate over manifest keys to find entry points and inject their new names
24-
Object.keys(manifest).forEach(key => {
24+
htmlPaths.forEach(htmlPath => {
25+
if (!fs.existsSync(htmlPath)) {
26+
return;
27+
}
28+
29+
let html = fs.readFileSync(htmlPath, 'utf-8');
30+
31+
// Iterate over manifest keys to find entry points and inject their new names
32+
Object.keys(manifest).forEach(key => {
2533
const entryData = manifest[key];
2634
if (entryData && (entryData.isEntry || entryData.isDynamicEntry) && entryData.file) {
2735
// chunk name could be 'main.js' or 'frontend/main.js'
@@ -41,11 +49,12 @@ try {
4149
html = html.replace(cssRegex, `<link rel="stylesheet" href="/dist/${cssFile}" id="vite-css">`);
4250
}
4351
}
52+
});
53+
54+
fs.writeFileSync(htmlPath, html, 'utf-8');
55+
console.log(`[Hash Injector] Successfully updated ${path.relative(projectRoot, htmlPath)}`);
4456
});
4557

46-
fs.writeFileSync(htmlPath, html, 'utf-8');
47-
console.log(`[Hash Injector] Successfully updated public/index.html`);
48-
4958
} catch (error) {
5059
console.error('[Hash Injector] Error:', error);
5160
process.exit(1);

0 commit comments

Comments
 (0)