fix: local ASCII Art inclusion
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
export async function getAsciiArt(art: string) {
|
||||
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
|
||||
getBearmetalAsciiPath();
|
||||
if (!artFilePath) return art;
|
||||
let artFileText: string;
|
||||
if (artFilePath.startsWith("http")) {
|
||||
artFileText = await fetch(artFilePath).then((res) => res.text());
|
||||
} else {
|
||||
artFileText = await Deno.readTextFile(artFilePath);
|
||||
}
|
||||
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
|
||||
let result = parserRX.exec(artFileText);
|
||||
import { log } from "./logfile.ts";
|
||||
import { join } from "@std/path";
|
||||
|
||||
while (result !== null) {
|
||||
const [_, name, artText] = result;
|
||||
if (name === art) return artText;
|
||||
result = parserRX.exec(artFileText);
|
||||
export async function getAsciiArt(art: string) {
|
||||
try {
|
||||
const artFilePath = Deno.env.get("BEARMETAL_ASCII_PATH") ||
|
||||
join(import.meta.dirname || "", "../asciiart.txt");
|
||||
let artFileText: string;
|
||||
if (artFilePath?.startsWith("http")) {
|
||||
artFileText = await fetch(artFilePath).then((res) => res.text());
|
||||
} else {
|
||||
artFileText = await Deno.readTextFile(
|
||||
artFilePath,
|
||||
);
|
||||
}
|
||||
const parserRX = /begin\s+(\w+)\s*\n([\s\S]*?)\s*end\s*/g;
|
||||
let result = parserRX.exec(artFileText);
|
||||
|
||||
while (result !== null) {
|
||||
const [_, name, artText] = result;
|
||||
if (name === art) return artText;
|
||||
result = parserRX.exec(artFileText);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
alert();
|
||||
}
|
||||
return art;
|
||||
}
|
||||
|
||||
function getBearmetalAsciiPath() {
|
||||
const filenameRX = /asciiarts?\.txt$/;
|
||||
for (const filename of Deno.readDirSync(".")) {
|
||||
if (filename.isFile && filenameRX.test(filename.name)) {
|
||||
return filename.name;
|
||||
}
|
||||
}
|
||||
return "https://git.cyborggrizzly.com/BearMetal/pdf-tools/raw/branch/main/asciiart.txt";
|
||||
}
|
||||
|
Reference in New Issue
Block a user