From b7c1ac781d5d91e3f9adb5adb2944dc42dd0fccb Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Thu, 24 Mar 2022 02:12:12 +0100 Subject: [PATCH] fix(ci): vercel preview (#962) [skip ci] --- .github/scripts/preview.mjs | 7 ++++--- source/app/web/statics/app.placeholder.js | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/scripts/preview.mjs b/.github/scripts/preview.mjs index c2d61a56..8f5a5b65 100644 --- a/.github/scripts/preview.mjs +++ b/.github/scripts/preview.mjs @@ -23,9 +23,10 @@ const { conf, Templates } = await setup({ log: false }) const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true })) const metadata = Object.fromEntries( Object.entries(conf.metadata.plugins) - .map(([key, value]) => [key, Object.fromEntries(Object.entries(value).filter(([key]) => ["name", "icon", "category", "web", "supports"].includes(key)))]) - .map(([key, value]) => [key, key === "core" ? { ...value, web: Object.fromEntries(Object.entries(value.web).filter(([key]) => /^config[.]/.test(key)).map(([key, value]) => [key.replace(/^config[.]/, ""), value])) } : value]), + .map(([key, value]) => [key, Object.fromEntries(Object.entries(value).filter(([key]) => ["name", "icon", "category", "web", "supports", "scopes"].includes(key)))]) + .map(([key, value]) => [key, key === "core" ? {...value, web:Object.fromEntries(Object.entries(value.web).filter(([key]) => /^config[.]/.test(key)).map(([key, value]) => [key.replace(/^config[.]/, ""), value]))} : value]), ) +const enabled = Object.entries(metadata).filter(([_name, {category}]) => category !== "core").map(([name]) => ({name, category:metadata[name]?.category ?? "community", enabled:true})) //Directories await fs.mkdir(__preview, { recursive: true }) @@ -40,7 +41,7 @@ fs.copyFile(paths.join(__web, "index.html"), paths.join(__preview, "index.html") fs.copyFile(paths.join(__web, "favicon.png"), paths.join(__preview, ".favicon.png")) fs.copyFile(paths.join(__web, "opengraph.png"), paths.join(__preview, ".opengraph.png")) //Plugins and templates -fs.writeFile(paths.join(__preview, ".plugins"), JSON.stringify(Object.entries(metadata).filter(([_name, { category }]) => category !== "core").map(([name]) => ({ name, enabled: false })))) +fs.writeFile(paths.join(__preview, ".plugins"), JSON.stringify(enabled)) fs.writeFile(paths.join(__preview, ".plugins.base"), JSON.stringify(conf.settings.plugins.base.parts)) fs.writeFile(paths.join(__preview, ".plugins.metadata"), JSON.stringify(metadata)) fs.writeFile(paths.join(__preview, ".templates__"), JSON.stringify(templates)) diff --git a/source/app/web/statics/app.placeholder.js b/source/app/web/statics/app.placeholder.js index 3369cc4a..272355d8 100644 --- a/source/app/web/statics/app.placeholder.js +++ b/source/app/web/statics/app.placeholder.js @@ -18,6 +18,10 @@ values.push(probability) return values.sort((a, b) => b - a) } + //Escape partial + function escape(partial) { + return encodeURIComponent(partial).replace(/%2F/gi, "/") + } //Static complex placeholder async function staticPlaceholder(condition, name) { if (!condition) @@ -28,7 +32,7 @@ globalThis.placeholder = async function(set) { //Load templates informations let { image, style, fonts, partials } = await load(`/.templates/${set.templates.selected}`) - await Promise.all(partials.map(async partial => await load(`/.templates/${set.templates.selected}/partials/${partial}.ejs`))) + await Promise.all(partials.map(async partial => await load(`/.templates/${set.templates.selected}/partials/${escape(partial)}.ejs`))) //Trap includes image = image.replace(/<%-\s*await include[(](`.*?[.]ejs`)[)]\s*%>/g, (m, g) => `<%- await $include(${g}) %>`) //Faked data @@ -53,7 +57,7 @@ }, //Trap for includes async $include(path) { - const partial = await load(`/.templates/${set.templates.selected}/${path}`) + const partial = await load(`/.templates/${set.templates.selected}/${escape(path)}`) return await ejs.render(partial, data, { async: true, rmWhitespace: true }) }, //Meta-data