Improve age-restricted hyperlinks, clean up markup, and add navigation icons

This commit is contained in:
Bad Manners 2024-08-25 16:18:13 -03:00
parent c55c82633d
commit 57c2c7c649
31 changed files with 279 additions and 138 deletions

View file

@ -66,20 +66,20 @@ async function exportStory(slug: string, options: { outputDir: string }) {
/* Spawn Astro dev server */
console.log("Starting Astro development server...");
const devServerProcess = spawn("./node_modules/.bin/astro", ["dev"], { stdio: 'pipe' });
const promise = new Promise<string>((resolve, reject) => {
const localServerRegex = /Local\s+(http\S+)/
const lines = createInterface({ input: devServerProcess.stdout });
lines.on("line", (line) => {
const match = localServerRegex.exec(line);
if (match && match[1]) {
resolve(match[1]);
}
});
lines.on("close", reject);
});
const astroURL = await promise;
console.log(`Astro listening on ${astroURL}`);
let astroURL: string | null = null;
try {
astroURL = await new Promise<string>((resolve, reject) => {
const localServerRegex = /Local\s+(http:\/\/\S+)/
const lines = createInterface({ input: devServerProcess.stdout });
lines.on("line", (line) => {
const match = localServerRegex.exec(line);
if (match && match[1]) {
resolve(match[1]);
}
});
lines.on("close", reject);
});
console.log(`Astro listening on ${astroURL}`);
const response = await fetchRetry(new URL(`/api/healthcheck`, astroURL), { retries: 5, retryDelay: 2000 });
if (!response.ok) {
throw new Error(response.statusText);
@ -106,9 +106,9 @@ async function exportStory(slug: string, options: { outputDir: string }) {
}
const data: { story: string, description: Record<string, string>, thumbnail: string | null } = await response.json();
await Promise.all(
Object.entries(data.description).map(async ([website, description]) => {
Object.entries(data.description).map(async ([filename, description]) => {
return await writeFile(
join(outputDir, `description_${website}.${website === "weasyl" ? "md" : "txt"}`),
join(outputDir, filename),
description,
);
}),
@ -124,7 +124,7 @@ async function exportStory(slug: string, options: { outputDir: string }) {
if (!thumbnail.ok) {
throw new Error("Failed to get thumbnail");
}
const thumbnailExt = thumbnail.headers.get("Content-Type")?.startsWith("image/png") ? "png" : "jpg";
const thumbnailExt = thumbnail.headers.get("Content-Type")!.startsWith("image/png") ? "png" : "jpg";
await writeFile(join(outputDir, `thumbnail.${thumbnailExt}`), Buffer.from(await thumbnail.arrayBuffer()));
}
}