fix(ci): vercel preview (#962) [skip ci]
This commit is contained in:
7
.github/scripts/preview.mjs
vendored
7
.github/scripts/preview.mjs
vendored
@@ -23,9 +23,10 @@ const { conf, Templates } = await setup({ log: false })
|
|||||||
const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true }))
|
const templates = Object.entries(Templates).map(([name]) => ({ name, enabled: true }))
|
||||||
const metadata = Object.fromEntries(
|
const metadata = Object.fromEntries(
|
||||||
Object.entries(conf.metadata.plugins)
|
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]),
|
.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
|
//Directories
|
||||||
await fs.mkdir(__preview, { recursive: true })
|
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, "favicon.png"), paths.join(__preview, ".favicon.png"))
|
||||||
fs.copyFile(paths.join(__web, "opengraph.png"), paths.join(__preview, ".opengraph.png"))
|
fs.copyFile(paths.join(__web, "opengraph.png"), paths.join(__preview, ".opengraph.png"))
|
||||||
//Plugins and templates
|
//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.base"), JSON.stringify(conf.settings.plugins.base.parts))
|
||||||
fs.writeFile(paths.join(__preview, ".plugins.metadata"), JSON.stringify(metadata))
|
fs.writeFile(paths.join(__preview, ".plugins.metadata"), JSON.stringify(metadata))
|
||||||
fs.writeFile(paths.join(__preview, ".templates__"), JSON.stringify(templates))
|
fs.writeFile(paths.join(__preview, ".templates__"), JSON.stringify(templates))
|
||||||
|
|||||||
@@ -18,6 +18,10 @@
|
|||||||
values.push(probability)
|
values.push(probability)
|
||||||
return values.sort((a, b) => b - a)
|
return values.sort((a, b) => b - a)
|
||||||
}
|
}
|
||||||
|
//Escape partial
|
||||||
|
function escape(partial) {
|
||||||
|
return encodeURIComponent(partial).replace(/%2F/gi, "/")
|
||||||
|
}
|
||||||
//Static complex placeholder
|
//Static complex placeholder
|
||||||
async function staticPlaceholder(condition, name) {
|
async function staticPlaceholder(condition, name) {
|
||||||
if (!condition)
|
if (!condition)
|
||||||
@@ -28,7 +32,7 @@
|
|||||||
globalThis.placeholder = async function(set) {
|
globalThis.placeholder = async function(set) {
|
||||||
//Load templates informations
|
//Load templates informations
|
||||||
let { image, style, fonts, partials } = await load(`/.templates/${set.templates.selected}`)
|
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
|
//Trap includes
|
||||||
image = image.replace(/<%-\s*await include[(](`.*?[.]ejs`)[)]\s*%>/g, (m, g) => `<%- await $include(${g}) %>`)
|
image = image.replace(/<%-\s*await include[(](`.*?[.]ejs`)[)]\s*%>/g, (m, g) => `<%- await $include(${g}) %>`)
|
||||||
//Faked data
|
//Faked data
|
||||||
@@ -53,7 +57,7 @@
|
|||||||
},
|
},
|
||||||
//Trap for includes
|
//Trap for includes
|
||||||
async $include(path) {
|
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 })
|
return await ejs.render(partial, data, { async: true, rmWhitespace: true })
|
||||||
},
|
},
|
||||||
//Meta-data
|
//Meta-data
|
||||||
|
|||||||
Reference in New Issue
Block a user