Migrate to Astro 5
This commit is contained in:
parent
5d701069e9
commit
bb1e533a00
129 changed files with 1408 additions and 1448 deletions
|
|
@ -7,7 +7,7 @@ import { createInterface } from "node:readline";
|
|||
import { program } from "commander";
|
||||
import fetchRetryWrapper from "fetch-retry";
|
||||
import type { HealthcheckResponse } from "../src/pages/api/healthcheck";
|
||||
import type { ExportStoryResponse } from "../src/pages/api/export-story/[...slug]";
|
||||
import type { ExportStoryResponse } from "../src/pages/api/export-story/[...id]";
|
||||
|
||||
function getRTFStyles(rtfSource: string) {
|
||||
const matches = rtfSource.matchAll(
|
||||
|
|
@ -46,7 +46,7 @@ const isLibreOfficeRunning = async () =>
|
|||
lines.on("close", () => res(false));
|
||||
});
|
||||
|
||||
async function exportStory(slug: string, options: { outputDir: string }) {
|
||||
async function exportStory(id: string, options: { outputDir: string }) {
|
||||
/* Check that LibreOffice is not running */
|
||||
if (await isLibreOfficeRunning()) {
|
||||
console.error("ERROR: LibreOffice cannot be open while this command is running!");
|
||||
|
|
@ -103,7 +103,7 @@ async function exportStory(slug: string, options: { outputDir: string }) {
|
|||
let storyText = "";
|
||||
try {
|
||||
console.log("Getting data from Astro...");
|
||||
const response = await fetch(new URL(`api/export-story/${slug}`, astroURL));
|
||||
const response = await fetch(new URL(`api/export-story/${id}`, astroURL));
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to reach export-story API (status code ${response.status})`);
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ async function exportStory(slug: string, options: { outputDir: string }) {
|
|||
// Story
|
||||
(async () => {
|
||||
storyText = data.story;
|
||||
await writeFile(join(outputDir, `${slug}.txt`), storyText);
|
||||
await writeFile(join(outputDir, `${id}.txt`), storyText);
|
||||
})(),
|
||||
// Descriptions
|
||||
Object.entries(data.description).map(
|
||||
|
|
@ -153,9 +153,9 @@ async function exportStory(slug: string, options: { outputDir: string }) {
|
|||
console.log("Parsing story into output formats...");
|
||||
// Process output files in parallel
|
||||
await Promise.all([
|
||||
// ${slug}.md
|
||||
writeFile(join(outputDir, `${slug}.md`), storyText.replaceAll(/=(?==)/g, "= ").replaceAll("*", "\\*")),
|
||||
// ${slug}.rtf
|
||||
// ${id}.md
|
||||
writeFile(join(outputDir, `${id}.md`), storyText.replaceAll(/=(?==)/g, "= ").replaceAll("*", "\\*")),
|
||||
// ${id}.rtf
|
||||
(async () => {
|
||||
const tempDir = await mkdtemp(join(tmpdir(), "export-story-"));
|
||||
await writeFile(join(tempDir, "temp.txt"), storyText.replaceAll(/\n\n+/g, "\n"));
|
||||
|
|
@ -174,7 +174,7 @@ async function exportStory(slug: string, options: { outputDir: string }) {
|
|||
console.warn(`Missing RTF style "Normal"! Skipping RTF file generation.`);
|
||||
} else {
|
||||
await writeFile(
|
||||
join(outputDir, `${slug}.rtf`),
|
||||
join(outputDir, `${id}.rtf`),
|
||||
rtfText.replaceAll(rtfStyles["Preformatted Text"], rtfStyles["Normal"]),
|
||||
);
|
||||
}
|
||||
|
|
@ -187,7 +187,7 @@ async function exportStory(slug: string, options: { outputDir: string }) {
|
|||
await program
|
||||
.name("export-story")
|
||||
.description("Generate and export formatted upload files for a story")
|
||||
.argument("<story-slug>", `Slug portion of the story's URL (eg. "the-lost-of-the-marshes/chapter-1")`)
|
||||
.argument("<story-id>", `ID portion of the story's URL (eg. "the-lost-of-the-marshes/chapter-1")`)
|
||||
.option("-o, --output-dir <directory>", `Empty or inexistent directory path to export files to`)
|
||||
.action(exportStory)
|
||||
.parseAsync();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue