From 70fb1a8c2ef0cf1c2f814d78c92df721036ed2cf Mon Sep 17 00:00:00 2001 From: SukkaW Date: Tue, 18 Jun 2024 20:19:25 +0800 Subject: [PATCH] Chore: improve HTML template DX --- Build/build-public.ts | 100 +++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/Build/build-public.ts b/Build/build-public.ts index 1ba94d3d..fd888035 100644 --- a/Build/build-public.ts +++ b/Build/build-public.ts @@ -35,8 +35,8 @@ export const buildPublic = task(import.meta.main, import.meta.path)(async (span) const filesToBeCopied = folderAndFilesToBeDeployed.flatMap(folderOrFile => trie.find(folderOrFile)); return Promise.all(filesToBeCopied.map(file => { - const src = path.resolve(rootPath, file); - const dest = path.resolve(publicPath, file); + const src = path.join(rootPath, file); + const dest = path.join(publicPath, file); return Bun.write(dest, Bun.file(src)); })); @@ -67,67 +67,69 @@ const priorityOrder: Record<'default' | string & {}, number> = { const prioritySorter = (a: TreeType, b: TreeType) => { return ((priorityOrder[a.name] || priorityOrder.default) - (priorityOrder[b.name] || priorityOrder.default)) || a.name.localeCompare(b.name); }; + +const html = (string: TemplateStringsArray, ...values: any[]) => string.reduce((acc, str, i) => acc + str + (values[i] ?? ''), ''); + const walk = (tree: TreeTypeArray) => { let result = ''; sort(tree, prioritySorter); for (let i = 0, len = tree.length; i < len; i++) { const entry = tree[i]; if (entry.type === 'directory') { - result += `
  • ${entry.name}`; - result += ''; + result += html` +
  • + ${entry.name} + +
  • + `; } else if (/* entry.type === 'file' && */ entry.name !== 'index.html') { - result += `
  • ${entry.name}
  • `; + result += html`
  • ${entry.name}
  • `; } } return result; }; function generateHtml(tree: TreeTypeArray) { - let html = ` - + return html` + + - - - Surge Ruleset Server | Sukka (@SukkaW) - - - - - - - - - - - - - - - - - - `; + + + Surge Ruleset Server | Sukka (@SukkaW) + + + + + + + - html += ` -
    -

    Sukka Ruleset Server

    -

    - Made by Sukka | Source @ GitHub | Licensed under AGPL-3.0 -

    -

    Last Build: ${new Date().toISOString()}

    -
    `; + - html += ''; - - html += `
    - - `; - - return html; + + + + + + + + + +
    +

    Sukka Ruleset Server

    +

    + Made by Sukka | Source @ GitHub | Licensed under AGPL-3.0 +

    +

    Last Build: ${new Date().toISOString()}

    +
    + +
    + + + `; }