Skip to content

Commit

Permalink
fix(builder): script not included in dedicated page
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Jun 10, 2024
1 parent 344226d commit 2e2e31f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/build/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ export async function html_builder() {
highlight(builder)
section.innerHTML = builder.querySelector("details")!.innerHTML
document.querySelector("main")!.append(section)
// Include scripts
await Promise.all(
Array.from(document.querySelectorAll("script[data-script]")).map(async (_element) => {
const element = _element as unknown as HTMLScriptElement
element.innerText = `{\n${await Deno.readTextFile(new URL(element.dataset.script!.slice(1), root))}\n}`
element.removeAttribute("data-script")
}),
)
return `<!DOCTYPE html>${document.documentElement!.outerHTML}`
}

Expand Down Expand Up @@ -165,6 +173,7 @@ export async function html_builder_demo() {

/** Template mod.html */
async function template({ remove }: { remove?: { parent?: string[]; selectors?: string[] } } = {}) {
// Generate HTML
let html = await Deno.readTextFile(new URL("app/mod.html", root))
for (const _ of [1, 2]) {
for (const match of html.matchAll(/<!--\/(?<path>[\s\S]+?\/.*\.html)-->/g)) {
Expand All @@ -175,13 +184,15 @@ async function template({ remove }: { remove?: { parent?: string[]; selectors?:
}
const document = new DOMParser().parseFromString(html, "text/html")!
highlight(document)
// Include scripts
await Promise.all(
Array.from(document.querySelectorAll("script[data-script]")).map(async (_element) => {
const element = _element as unknown as HTMLScriptElement
element.innerText = `{\n${await Deno.readTextFile(new URL(element.dataset.script!.slice(1), root))}\n}`
element.removeAttribute("data-script")
}),
)
// Clean up
if (remove?.parent) {
for (const selector of remove.parent) {
document.querySelector(selector)?.parentElement?.remove()
Expand Down

0 comments on commit 2e2e31f

Please sign in to comment.