|
4 | 4 | import url from "url" |
5 | 5 | import yaml from "js-yaml" |
6 | 6 |
|
| 7 | +//Defined categories |
| 8 | + const categories = ["core", "github", "social", "health", "other"] |
| 9 | + |
7 | 10 | /**Metadata descriptor parser */ |
8 | 11 | export default async function metadata({log = true} = {}) { |
9 | 12 | //Paths |
|
25 | 28 | } |
26 | 29 | //Reorder keys |
27 | 30 | const {base, core, ...plugins} = Plugins |
28 | | - Plugins = {base, core, ...plugins} |
| 31 | + Plugins = Object.fromEntries(Object.entries(Plugins).sort(([_an, a], [_bn, b]) => categories.indexOf(a.categorie) - categories.indexOf(b.categorie))) |
29 | 32 |
|
30 | 33 | //Load templates metadata |
31 | 34 | let Templates = {} |
|
53 | 56 | const raw = `${await fs.promises.readFile(path.join(__plugins, name, "metadata.yml"), "utf-8")}` |
54 | 57 | const {inputs, ...meta} = yaml.load(raw) |
55 | 58 |
|
| 59 | + //Categorie |
| 60 | + if (!categories.includes(meta.categorie)) |
| 61 | + meta.categorie = "other" |
| 62 | + |
56 | 63 | //Inputs parser |
57 | 64 | { |
58 | 65 | meta.inputs = function({data:{user = null} = {}, q, account}, defaults = {}) { |
|
260 | 267 | return { |
261 | 268 | name:raw.match(/^### (?<name>[\s\S]+?)\n/)?.groups?.name?.trim(), |
262 | 269 | readme:{ |
263 | | - demo:raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? (name === "community" ? "<td align=\"center\">See <a href=\"/source/templates/community/README.md\">documentation</a> 🌍</td>" : "<td></td>"), |
| 270 | + demo:raw.match(/(?<demo><table>[\s\S]*?<[/]table>)/)?.groups?.demo?.replace(/<[/]?(?:table|tr)>/g, "")?.trim() ?? (name === "community" ? "<td align=\"center\"><h3>See <a href=\"/source/templates/community/README.md\">documentation</a> 🌍</h3></td>" : "<td></td>"), |
264 | 271 | compatibility:{...compatibility, base:true}, |
265 | 272 | }, |
266 | 273 | } |
|
0 commit comments