mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-07-06 12:02:52 +00:00

After several weeks of carefully arranging ribbons, we pull the string and end up with, ... a bit of a messy bow. There were still some things I'd missed. - Split the mod into a common (vanilla-only) project and Forge-specific project. This gives us room to add Fabric support later on. - Split the project into main/client source sets. This is not currently statically checked: we'll do that soon. - Rename block/item/tile entities to use suffixes rather than prefixes.
54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
/**
|
|
* Find all HTML files generated by illuaminate and pipe them through a remark.
|
|
*
|
|
* This performs compile-time syntax highlighting and expands our custom
|
|
* components using React SSR.
|
|
*
|
|
* Yes, this would be so much nicer with next.js.
|
|
*/
|
|
import * as fs from "fs/promises";
|
|
import globModule from "glob";
|
|
import * as path from "path";
|
|
import { createElement, createElement as h, Fragment } from 'react';
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import rehypeHighlight from "rehype-highlight";
|
|
import rehypeParse from 'rehype-parse';
|
|
import rehypeReact from 'rehype-react';
|
|
import { unified } from 'unified';
|
|
import { promisify } from "util";
|
|
// Our components
|
|
import Recipe from "./components/Recipe.js";
|
|
import { noChildren } from "./components/support.js";
|
|
import { DataExport, WithExport } from "./components/WithExport.js";
|
|
|
|
const glob = promisify(globModule);
|
|
|
|
(async () => {
|
|
const base = "build/illuaminate";
|
|
|
|
const processor = unified()
|
|
.use(rehypeParse, { emitParseErrors: true })
|
|
.use(rehypeHighlight, { prefix: "" })
|
|
.use(rehypeReact, {
|
|
createElement,
|
|
Fragment,
|
|
passNode: false,
|
|
components: {
|
|
['mc-recipe']: noChildren(Recipe),
|
|
['mcrecipe']: noChildren(Recipe),
|
|
} as any
|
|
});
|
|
|
|
const dataExport = JSON.parse(await fs.readFile("src/export/index.json", "utf-8")) as DataExport;
|
|
|
|
for (const file of await glob(base + "/**/*.html")) {
|
|
const contents = await fs.readFile(file, "utf-8");
|
|
|
|
const { result } = await processor.process(contents);
|
|
|
|
const outputPath = path.resolve("build/jsxDocs", path.relative(base, file));
|
|
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
|
await fs.writeFile(outputPath, "<!doctype HTML>" + renderToStaticMarkup(<WithExport data={dataExport}>{result}</WithExport>));
|
|
}
|
|
})();
|