",
` ${meta.name} |
`,
` | ${marked.parse(meta.description ?? "", {silent:true})} |
`,
meta.authors?.length ? `| Authors | ${[meta.authors].flat().map(author => `@${author}`)} |
` : "",
" ",
' Supported features → Full specification | ',
` ${Object.entries(compatibility).filter(([_, value]) => value).map(([id]) => `${templates[id].name ?? ""}`).join(" ")} | `,
"
",
" ",
` ${
[
meta.supports?.includes("user") ? "👤 Users" : "",
meta.supports?.includes("organization") ? "👥 Organizations" : "",
meta.supports?.includes("repository") ? "📓 Repositories" : "",
].filter(v => v).join(" ")
} | `,
"
",
" ",
` ${[
...(meta.scopes ?? []).map(scope => `🔑 ${{public_access:"(scopeless)"}[scope] ?? scope}`),
...Object.entries(inputs).filter(([_, {type}]) => type === "token").map(([token]) => `🗝️ ${token}`),
...(meta.scopes?.length ? ["read:org", "read:user", "repo"].map(scope => !meta.scopes.includes(scope) ? `${scope} (optional)` : null).filter(v => v) : []),
].filter(v => v).join(" ") || "No tokens are required for this plugin"} | `,
"
",
" ",
demos({colspan:2, wrap:name === "base", examples:meta.examples}),
"
",
"
",
].filter(v => v).join("\n")
//Options table
const table = [
"^[\s\S]+(?=[.]ejs$))/)?.groups?.plugin ?? null
if (plugin in compatibility)
compatibility[plugin] = true
}
}
//Header table
const header = [
"",
` ${meta.name ?? "(unnamed template)"} |
`,
` | ${marked.parse(meta.description ?? "", {silent:true})} |
`,
" ",
' Supported features → Full specification | ',
` ${Object.entries(compatibility).filter(([_, value]) => value).map(([id]) => `${plugins[id].icon}`).join(" ")}${meta.formats?.includes("markdown") ? " ✓ embed()" : ""} | `,
"
",
" ",
` ${
[
meta.supports?.includes("user") ? "👤 Users" : "",
meta.supports?.includes("organization") ? "👥 Organizations" : "",
meta.supports?.includes("repository") ? "📓 Repositories" : "",
].filter(v => v).join(" ")
} | `,
"
",
" ",
` ${
[
meta.formats?.includes("svg") ? "*️⃣ SVG" : "",
meta.formats?.includes("png") ? "*️⃣ PNG" : "",
meta.formats?.includes("jpeg") ? "*️⃣ JPEG" : "",
meta.formats?.includes("json") ? "#️⃣ JSON" : "",
meta.formats?.includes("markdown") ? "🔠 Markdown" : "",
meta.formats?.includes("markdown-pdf") ? "🔠 Markdown (PDF)" : "",
].filter(v => v).join(" ")
} | `,
"
",
" ",
demos({colspan:2, examples:meta.examples}),
"
",
"
",
].join("\n")
//Result
return {
name:meta.name ?? "(unnamed template)",
description:meta.description ?? "",
index:meta.index ?? null,
formats:meta.formats ?? null,
supports:meta.supports ?? null,
readme:{
demo:demos({examples:meta.examples}),
compatibility:{
...Object.fromEntries(Object.entries(compatibility).filter(([_, value]) => value)),
...Object.fromEntries(Object.entries(compatibility).filter(([_, value]) => !value).map(([key, value]) => [key, meta.formats?.includes("markdown") ? "embed" : value])),
base:true,
},
header,
},
check({q, account = "bypass", format = null}) {
//Support check
if (account !== "bypass") {
const context = q.repo ? "repository" : account
if ((Array.isArray(this.supports)) && (!this.supports.includes(context)))
throw new Error(`not supported for: ${context}`)
}
//Format check
if ((format) && (Array.isArray(this.formats)) && (!this.formats.includes(format)))
throw new Error(`not supported for: ${format}`)
},
}
}
catch (error) {
logger(`metrics/metadata > failed to load template ${name}: ${error}`)
return null
}
}
/**Metadata converters */
metadata.to = {
query(key, {name = null} = {}) {
key = key.replace(/^plugin_/, "").replace(/_/g, ".")
return name ? key.replace(new RegExp(`^(${name}.)`, "g"), "") : key
},
}
//Demo for main and individual readmes
function demos({colspan = null, wrap = false, examples = {}} = {}) {
if (("default1" in examples) && ("default2" in examples)) {
return [
wrap ? '' : "",
'',
` `,
" | ",
'',
` `,
" | ",
wrap ? "
| " : "",
].filter(v => v).join("\n")
}
return [
` `,
`${
Object.entries(examples).map(([text, link]) => {
let img = ` `
if (text !== "default") {
const open = text.charAt(0) === "+" ? " open" : ""
text = open ? text.substring(1) : text
text = `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`
img = `${text}${img} `
}
return ` ${img}`
}).join("\n")
}`,
' ',
" | ",
].filter(v => v).join("\n")
}