fix(ci): vercel preview (#962) [skip ci]

This commit is contained in:
Simon Lecoq
2022-03-24 02:12:12 +01:00
committed by GitHub
parent 7c09b71c76
commit b7c1ac781d
2 changed files with 10 additions and 5 deletions

View File

@@ -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, 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))

View File

@@ -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