Inline noise.png as base64 data URI to allow file:// access
This commit is contained in:
1 parent
fcf431470a
commit
a82d6cce3d
3 files changed
+15
-12
No files matched your search
@@ -9,7 +9,7 @@ If output is not given, defaults to 'background-final.html'.
|
||||
|
||||
This reads config.js to pick the active theme and inlines all CSS,
|
||||
JS, and the noise.png texture into a single HTML document. After
|
||||
building, the resulting double-standalone HTML can be opened directly in
|
||||
building, the resulting standalone HTML can be opened directly in
|
||||
a browser (file://) because all external resources are inlined.
|
||||
"""
|
||||
|
||||
@@ -51,6 +51,16 @@ def main():
|
||||
|
||||
html = read('background.html')
|
||||
|
||||
# Read noise.png and inline as base64 data URI
|
||||
with open(os.path.join(ROOT, 'noise.png'), 'rb') as f:
|
||||
noise_b64 = base64.b64encode(f.read()).decode('ascii')
|
||||
|
||||
# Replace noiseDataUri placeholder with the actual data URI
|
||||
html = html.replace(
|
||||
"'data:image/png;base64,PLACEHOLDER'",
|
||||
"'data:image/png;base64," + noise_b64 + "'"
|
||||
)
|
||||
|
||||
# Resolve active theme css
|
||||
theme_css = read(theme + '.css')
|
||||
# Inline the active theme stylesheet at the end of <head>
|
||||
@@ -71,15 +81,6 @@ def main():
|
||||
'<script>\n' + body + '\n</script>',
|
||||
1)
|
||||
|
||||
# Inline noise.png as data URI in the Vanta init script.
|
||||
with open(os.path.join(ROOT, 'noise.png'), 'rb') as f:
|
||||
noise_b64 = base64.b64encode(f.read()).decode('ascii')
|
||||
noise_uri = 'data:image/png;base64,' + noise_b64
|
||||
html = re.sub(
|
||||
r"texturePath:\s*'[^']*'",
|
||||
"texturePath: '" + noise_uri + "'",
|
||||
html)
|
||||
|
||||
with open(os.path.join(ROOT, out), 'w', encoding='utf-8') as f:
|
||||
f.write(html)
|
||||
|
||||
|
||||
Reference in new issue
Block a user