Skip to content

Commit

Permalink
Fix filename error and put correct checks on the state
Browse files Browse the repository at this point in the history
  • Loading branch information
robsimmons committed Mar 31, 2024
1 parent f2389ae commit 49b21e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 11 additions & 3 deletions wiki/elf-to-mdx.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ export async function elfToMdx(elfFilename) {
let twelfcontext = [];

/** @typedef {{ type: "twelf", subtype: null | "hidden" | "checked", accum: string[] }} TwelfState */
/** @typedef { { type: "markdown-block", subtype: "math" | "twelf" | "checkedtwelf", accum: string[] }} MarkdownBlockState */
/** @typedef {{ type: "markdown-block", subtype: "math" | "twelf" | "checkedtwelf", accum: string[] }} MarkdownBlockState */
/** @typedef {{ type: "markdown" }} MarkdownState */
/** @type {TwelfState | MarkdownState | MarkdownBlockState} */
let state = { type: "twelf", subtype: null, accum: [] };

// Precondition: state.type === "twelf"
async function reduceTwelfAccum(checked = false, save = false) {
if (state.type !== "twelf") throw new TypeError();
if (
!(
state.type === "twelf" ||
(state.type === "markdown-block" &&
(state.subtype === "twelf" || state.subtype === "checkedtwelf"))
)
) {
throw new TypeError(`state ${state.type} - ${state.subtype}`);
}
mutablyTrimEmptyLines(state.accum);

if (state.accum.length === 0) {
Expand Down Expand Up @@ -291,7 +299,7 @@ import Todo from "../../../components/Todo.astro";
{/* AUTOMATICALLY GENERATED FROM A .ELF FILE */}
{/* DO NOT EDIT */}
{/* EDIT ${elfFilename} INSTEAD */}
{/* EDIT twelf/wiki/${elfFilename} INSTEAD */}
${body.join("\n")}
`;
Expand Down
4 changes: 2 additions & 2 deletions wiki/elf-watcher.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { existsSync, mkdirSync, readdirSync, watch, writeFileSync } from "fs";
import { argv } from "process";
import { elfToMdx } from "./elf-to-mdx.mjs";
import { join } from "path";

const DIR_OF_WIKI = "twelf/wiki/";
const DIR_OF_ELF = "pages";
const DIR_OF_MDX = "src/content/docs/wiki";
if (!existsSync(DIR_OF_MDX)) {
Expand All @@ -20,7 +20,7 @@ async function mdxOfFile(file) {
const base = file.slice(0, file.length - 4);
const mdxname = `${DIR_OF_MDX}/${base}.mdx`;
console.log(`elf->mdx transforming ${file}`);
const mdxFile = await elfToMdx(DIR_OF_WIKI + elfname);
const mdxFile = await elfToMdx(elfname);
writeFileSync(mdxname, mdxFile);
}

Expand Down

0 comments on commit 49b21e8

Please sign in to comment.