Skip to content

Commit 0317d51

Browse files
committed
Move standalone favicon logic to generate-standalone.js
1 parent 956a9d8 commit 0317d51

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/build/generate-standalone.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ const jsPath = pathUtil.join(dist, indexContent.match(/<script src="(.*)"><\/scr
2323
console.log(`packager.js: ${jsPath}`);
2424
const jsContent = fs.readFileSync(jsPath, 'utf-8');
2525

26+
const faviconPath = pathUtil.join(__dirname, '../../static/favicon.ico');
27+
const faviconData = fs.existsSync(faviconPath) ? fs.readFileSync(faviconPath) : null;
28+
console.log(`favicon.ico: ${faviconData ? faviconPath : 'none'}`);
29+
2630
const makeSafeForInlineScript = (content) => content.replace(/<\/script>/g, '\\u003c/script>');
2731
let standaloneJS = '';
2832
standaloneJS += Object.entries(scaffoldingAssets).map(([name, content]) => (
@@ -35,7 +39,12 @@ for (const el of Array.from(document.querySelectorAll('script[type="p4-standalon
3539
el.remove();
3640
}
3741
</script>`;
38-
const newContent = indexContent.replace(/<script src=".*"><\/script>/, () => (
42+
43+
let newContent = indexContent;
44+
if (faviconData) {
45+
newContent = newContent.replace(/<\/head>/, `<link rel="shortcut icon" href="data:image/vnd.microsoft.icon;base64,${faviconData.toString('base64')}"></head>`);
46+
}
47+
newContent = newContent.replace(/<script src=".*"><\/script>/, () => (
3948
`${standaloneJS}<script>${makeSafeForInlineScript(jsContent)}</script>`
4049
));
4150

src/p4/template.ejs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,6 @@
66
<% const {LONG_NAME, WEBSITE} = require('../packager/brand.js'); %>
77
<title><%= LONG_NAME %></title>
88
<meta name="description" content="Converts Scratch projects into HTML files, zip archives, or executable programs for Windows, macOS, and Linux.">
9-
<% if (process.env.STANDALONE) { %>
10-
<%
11-
const fs = require('fs');
12-
const path = require('path');
13-
const faviconPath = path.resolve('static/favicon.ico');
14-
if (fs.existsSync(faviconPath)) {
15-
%>
16-
<link rel="shortcut icon" href="data:image/vnd.microsoft.icon;base64,<%= fs.readFileSync('static/favicon.ico').toString('base64') %>">
17-
<% } %>
18-
<% } %>
199
<style>
2010
body[p4-splash-theme="dark"]:not([p4-loaded]) {
2111
background-color: #111;

0 commit comments

Comments
 (0)