add some scripts to fix mutant.json file and give files proper paths

This commit is contained in:
Lio 2024-01-14 12:27:32 +01:00
parent 5db3c0ccc4
commit bc1830a62a
4 changed files with 86946 additions and 7522 deletions

View file

@ -5,33 +5,44 @@ import Site from "lume/core/site.ts";
export interface Options {
/** Extensions processed by this plugin to extract the utility classes */
extensions?: string[];
}
export const defaults: Options = {
extensions: [".md", ".mdx", ".html"],
};
function replaceSlashes(text: string) {
return text.replace(/\//g, '+');
}
export default function (userOptions?: Options) {
const options = merge(defaults, userOptions);
const alreadyProcessed: string[] = [];
return (site: Site) => {
site.process(options.extensions, (pages) => {
pages.forEach((page: any) => {
const regex = /:(.*?):/g;
const regex = /(?<= ):(.*?):(?= )/g;
let m: RegExpExecArray | null;
while ((m = regex.exec(page.content as unknown as string)) !== null) {
const text = m[0].trim();
const textBetweenColons = m[1].trim();
// deno-lint-ignore ban-ts-comment
// @ts-ignore
// console.log(textBetweenColons, mtnt, mtnt.some(item => item.short === textBetweenColons))
// console.log(mtnt.some(item => item.short === textBetweenColons), mtnt.find(item => item.short === textBetweenColons))
if (mtnt.some(item => item.short === textBetweenColons)) {
const emoji = mtnt.find(item => item.short === textBetweenColons).src
const emoji = mtnt.find(item => item.short === textBetweenColons)
const emojiPath = replaceSlashes(emoji.src);
if (page.data.url === '/') {
// console.log((page.content as unknown as string).replace(new RegExp(text, 'g'), text))
}
page.content = (page.content as unknown as string).replace(new RegExp(text, 'g'),
`<img class="markdown-emoji" src="/files/emojis/${emoji}" />`);
// deno-lint-ignore ban-ts-comment
// @ts-ignore
site.getOrCreatePage(`/files/emojis/${emoji}`)
// site.copy(`files/emojis/${emoji}`, `/files/emojis/${emoji}`)
`<img alt="${emoji.desc}" class="markdown-emoji" src="/files/emojis/${emojiPath}" />`);
if (!alreadyProcessed.includes(textBetweenColons)) {
alreadyProcessed.push(textBetweenColons);
console.log(alreadyProcessed)
site.getOrCreatePage(`/files/emojis/${emojiPath}`)
}
}
}
});

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,40 @@
import mtnt from "../plugins/pluginData/mutant_base.json" with { type: "json" }
type obj = {
cat: string,
code: number[] | string,
color: string,
desc: string,
morph: string,
root: string,
short: string,
src: string
}
function renameSrc(obj: obj) {
// Build the new filename
let newFilename
if (!obj.morph || !obj.color) {
newFilename = `${obj.short}`;
}
else newFilename = `${obj.root}_${obj.morph}_${obj.color}`;
// Extract the path and the old filename from the src string
const path = obj.src.substring(0, obj.src.lastIndexOf("/") + 1);
const oldFilename = obj.src.substring(obj.src.lastIndexOf("/") + 1);
// Replace the old filename with the new one
obj.src = path + newFilename + oldFilename.substring(oldFilename.lastIndexOf("."));
return obj;
}
const newMtnt = mtnt.map((obj) => renameSrc(obj));
if (Deno.cwd().endsWith("lotus")) {
Deno.writeTextFile("_src/lib/plugins/pluginData/newMutant.json", JSON.stringify(newMtnt, null, 2));
} else if (Deno.cwd().endsWith("scripts")) {
Deno.writeTextFile("../plugins/pluginData/newMutant.json", JSON.stringify(newMtnt, null, 2));
}