Skip to content

Commit

Permalink
Implement ae2:ConfigValue
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 12, 2024
1 parent cc2750b commit c8eee20
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/build-data/Guide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export type GuideIndex = {
pageIndices: Record<string, Array<any>>;

animations: Record<string, AnimationInfo>;

defaultConfigValues: Record<string, string>;
};

export type NavigationNode = {
Expand Down
9 changes: 7 additions & 2 deletions src/build-data/index.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -25,7 +25,12 @@ export async function getGuide(versionSlug: string): Promise<Guide> {
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,
Expand Down
21 changes: 21 additions & 0 deletions src/components/guide-elements/AE2ConfigValue.tsx
Original file line number Diff line number Diff line change
@@ -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 <ErrorText>Missing config value name</ErrorText>;
}
const configValue = guide.index.defaultConfigValues[name];
if (!configValue) {
return <ErrorText>Unknown config value: {name}</ErrorText>;
}

return configValue;
}

export default Ae2ConfigValue;
2 changes: 2 additions & 0 deletions src/components/page-compiler/customElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -40,6 +41,7 @@ const components: Record<string, CustomGuideComponent> = {
RecipeFor,
Row,
SubPages,
"ae2:ConfigValue": AE2ConfigValue,
};

const customCompilers: Record<string, CustomElementCompiler> = {
Expand Down

0 comments on commit c8eee20

Please sign in to comment.