diff --git a/examples/zkapps/04-zkapp-browser-ui/ui/ghp-postbuild.js b/examples/zkapps/04-zkapp-browser-ui/ui/ghp-postbuild.js index c3d722993..c678dfbc0 100644 --- a/examples/zkapps/04-zkapp-browser-ui/ui/ghp-postbuild.js +++ b/examples/zkapps/04-zkapp-browser-ui/ui/ghp-postbuild.js @@ -3,33 +3,23 @@ const path = require('path'); // This script modifies the built CSS files and prepends the repo-name to the asset URLs. // to be compatible with github pages deployment. -const cssDir = path.join(__dirname, '/.next/static/css'); -// Add your repository name here. +const cssDir = path.join(__dirname, '/out/_next/static/css'); +// Update your repository name here if it is different from the project name. let repoURL = '04-zkapp-browser-ui'; -fs.readdir(cssDir, (err, files) => { - if (err) { - console.error(err); - process.exit(1); - } +const files = fs.readdirSync(cssDir); + +files.forEach((file) => { + if (path.extname(file) === '.css') { + const filePath = path.join(cssDir, file); + + const data = fs.readFileSync(filePath, 'utf8'); - files.forEach(file => { - if (path.extname(file) === '.css') { - const filePath = path.join(cssDir, file); - fs.readFile(filePath, 'utf8', (err, data) => { - if (err) { - console.error(err); - process.exit(1); - } - - const result = data.replace(/url\(\//g, `url(/${repoURL}/`); + const singleQuoteRegex = new RegExp(`url\\(\\s*'\\/(?!${repoURL})`, 'g'); + const doubleQuoteRegex = new RegExp(`url\\(\\s*"\\/(?!${repoURL})`, 'g'); - fs.writeFile(filePath, result, 'utf8', err => { - if (err) { - console.error(err); - process.exit(1); - } - }); - }); - } - }); -}); + let result = data.replace(singleQuoteRegex, `url('/${repoURL}/`); + result = result.replace(doubleQuoteRegex, `url("/${repoURL}/`); + + fs.writeFileSync(filePath, result, 'utf8'); + } +}); \ No newline at end of file