Rename some files; also finish some work from prev commit

This commit is contained in:
Adrian Vollmer 2024-04-21 16:59:19 +02:00
parent 54fda10acc
commit 8aa570030b
5 changed files with 20 additions and 16 deletions

View File

@ -116,9 +116,7 @@ monkeyPatch();
// Set up message listener // Set up message listener
window.addEventListener("message", (evnt) => { window.addEventListener("message", (evnt) => {
console.log("Received message in iframe", evnt); console.log("Received message in iframe", evnt);
if (evnt.data.action == 'set_data') { if (evnt.data.action == 'scroll_to_anchor') {
onSetData(evnt.data.argument);
} else if (evnt.data.action == 'scroll_to_anchor') {
onScrollToAnchor(evnt.data.argument); onScrollToAnchor(evnt.data.argument);
} }
}, false); }, false);

View File

@ -17,4 +17,5 @@ GC = pako.inflate(GC);
GC = new TextDecoder("utf-8").decode(GC); GC = new TextDecoder("utf-8").decode(GC);
GC = JSON.parse(GC); GC = JSON.parse(GC);
window.globalContext = GC; window.globalContext = GC;
eval(window.globalContext.main); eval(window.globalContext.utils.zundler_common);
eval(window.globalContext.utils.zundler_main);

View File

@ -58,11 +58,11 @@ var prepare = function(html) {
`; `;
const commonTag = doc.createElement("script"); const commonTag = doc.createElement("script");
commonTag.textContent = retrieveFile("common.js").data commonTag.textContent = window.globalContext.utils.zundler_common;
const injectPreTag = doc.createElement("script"); const injectPreTag = doc.createElement("script");
injectPreTag.textContent = retrieveFile("inject_pre.js").data injectPreTag.textContent = window.globalContext.utils.inject_pre;
const injectPostTag = doc.createElement("script"); const injectPostTag = doc.createElement("script");
injectPostTag.textContent = retrieveFile("inject_post.js").data injectPostTag.textContent = window.globalContext.utils.inject_post;
doc.head.prepend(commonTag); doc.head.prepend(commonTag);
doc.head.prepend(gcTag); doc.head.prepend(gcTag);

View File

@ -45,8 +45,9 @@ def embed_assets(index_file, output_path=None, append_pre="", append_post=""):
for filename in [ for filename in [
"init.css", "init.css",
"init.html", "init.html",
"bootstrap.js", "zundler_bootstrap.js",
"main.js", "zundler_common.js",
"zundler_main.js",
"inject_pre.js", "inject_pre.js",
"inject_post.js", "inject_post.js",
"pako.min.js", "pako.min.js",
@ -58,6 +59,8 @@ def embed_assets(index_file, output_path=None, append_pre="", append_post=""):
init_files[filename] = append_pre + init_files[filename] init_files[filename] = append_pre + init_files[filename]
if filename == "inject_post.js": if filename == "inject_post.js":
init_files[filename] += append_post init_files[filename] += append_post
if filename.lower().endswith(".js"):
init_files[filename] += "\n\n//# sourceURL=%s" % filename
if not os.path.exists(index_file): if not os.path.exists(index_file):
raise FileNotFoundError("no such file: %s" % index_file) raise FileNotFoundError("no such file: %s" % index_file)
@ -74,13 +77,15 @@ def embed_assets(index_file, output_path=None, append_pre="", append_post=""):
exclude_pattern=new_base_name, exclude_pattern=new_base_name,
) )
remote_resources = []
global_context = { global_context = {
"current_path": base_name, "current_path": base_name,
"file_tree": file_tree, "fileTree": file_tree,
"remote_resources": remote_resources, "utils": {
"main": init_files["main.js"] + "\n//# sourceURL=main.js", "zundler_main": init_files["zundler_main.js"],
"zundler_common": init_files["zundler_common.js"],
"inject_pre": init_files["inject_pre.js"],
"inject_post": init_files["inject_post.js"],
},
} }
global_context = json.dumps(global_context) global_context = json.dumps(global_context)
@ -100,13 +105,13 @@ https://github.com/AdrianVollmer/Zundler
<body>{body} <body>{body}
<script>window.globalContext = "{global_context}"</script> <script>window.globalContext = "{global_context}"</script>
<script>{pako} \n//# sourceURL=pako.js</script> <script>{pako} \n//# sourceURL=pako.js</script>
<script>{bootstrap} \n//# sourceURL=boostrap.js</script> <script>{bootstrap} \n//# sourceURL=zundler_boostrap.js</script>
</body><!-- {license} --></html> </body><!-- {license} --></html>
""".format( """.format(
style=init_files["init.css"], style=init_files["init.css"],
body=init_files["init.html"], body=init_files["init.html"],
pako=init_files["pako.min.js"], pako=init_files["pako.min.js"],
bootstrap=init_files["bootstrap.js"], bootstrap=init_files["zundler_bootstrap.js"],
global_context=global_context, global_context=global_context,
license=init_files["LICENSE"], license=init_files["LICENSE"],
version=__version__, version=__version__,