diff --git a/package.json b/package.json index 862b65d..9680124 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "postbuild": "next-sitemap", "build-debug": "cross-env NODE_OPTIONS='--inspect' next build", "start": "serve out", - "lint": "next lint" + "lint": "next lint", + "download-data": "node scripts/download_data.mjs" }, "dependencies": { "@docsearch/react": "^3.5.2", diff --git a/src/build-data/Guide.ts b/src/build-data/Guide.ts index 4a661e3..085d7f5 100644 --- a/src/build-data/Guide.ts +++ b/src/build-data/Guide.ts @@ -168,6 +168,8 @@ export type GuideIndex = { pageIndices: Record>; animations: Record; + + defaultConfigValues: Record; }; export type NavigationNode = { diff --git a/src/build-data/index.ts b/src/build-data/index.ts index 21641b3..232e78b 100644 --- a/src/build-data/index.ts +++ b/src/build-data/index.ts @@ -1,6 +1,6 @@ import { join as joinPath } from "node:path"; import { readFile, stat } from "node:fs/promises"; -import { Guide } from "./Guide.ts"; +import { Guide, GuideIndex } from "./Guide.ts"; import { getGuideVersionBySlug } from "./GuideVersionIndex.ts"; type CachedGuide = { @@ -25,7 +25,12 @@ export async function getGuide(versionSlug: string): Promise { return cachedData.guide; } - const guideData = JSON.parse(await readFile(dataPath, { encoding: "utf-8" })); + const guideData: GuideIndex = JSON.parse( + await readFile(dataPath, { encoding: "utf-8" }), + ); + + // Fix up older versions. Introduced in late 1.20.4 + guideData.defaultConfigValues ??= {}; const guide = new Guide( versionInfo.baseUrl, diff --git a/src/components/guide-elements/AE2ConfigValue.tsx b/src/components/guide-elements/AE2ConfigValue.tsx new file mode 100644 index 0000000..bc3088e --- /dev/null +++ b/src/components/guide-elements/AE2ConfigValue.tsx @@ -0,0 +1,21 @@ +import React from "react"; +import { CustomGuideElementProps } from "@component/CustomGuideElementProps.ts"; +import ErrorText from "@component/ErrorText.tsx"; + +export interface AE2ConfigValueProps extends CustomGuideElementProps { + name: string; +} + +function Ae2ConfigValue({ guide, name }: AE2ConfigValueProps) { + if (!name) { + return Missing config value name; + } + const configValue = guide.index.defaultConfigValues[name]; + if (!configValue) { + return Unknown config value: {name}; + } + + return configValue; +} + +export default Ae2ConfigValue; diff --git a/src/components/page-compiler/customElement.ts b/src/components/page-compiler/customElement.ts index 07bee5f..f1fceb4 100644 --- a/src/components/page-compiler/customElement.ts +++ b/src/components/page-compiler/customElement.ts @@ -17,6 +17,7 @@ import { getAttributes } from "./mdxUtils.ts"; import CategoryIndex from "@component/guide-elements/CategoryIndex"; import { CustomGuideElementProps } from "@component/CustomGuideElementProps.ts"; import SubPages from "@component/guide-elements/SubPages.tsx"; +import AE2ConfigValue from "@component/guide-elements/AE2ConfigValue.tsx"; type CustomElementCompiler = ( context: CompileContext, @@ -40,6 +41,7 @@ const components: Record = { RecipeFor, Row, SubPages, + "ae2:ConfigValue": AE2ConfigValue, }; const customCompilers: Record = {