feat: macro names

This commit is contained in:
TrèsAbhi committed 2026-03-19 18:44:00 -05:00
1 parent 6a58c5ea1d
commit 8d3678ddcb
8 files changed
+64 -29

No files matched your search

+1 -6
View File
@@ -123,11 +123,6 @@
"media": "Media methods", "media": "Media methods",
"no_docs": "This method has no documentation.", "no_docs": "This method has no documentation.",
"test": "Test", "test": "Test",
"view_full": "View full types", "view_full": "View full types"
"macros": {
"see": "See {path} {message}",
"types": "Types:"
}
} }
} }
@@ -9,7 +9,12 @@ interface Props {
} }
const macroPattern = /@(\w+) (.+)/; const macroPattern = /@(\w+) (.+)/;
const macros: Record<string, string> = {}; const macros: Record<string, string[]> = {};
const macroComponents = {
see: ApiMacroSee,
type: ApiMacroType,
};
const { body: bodyOriginal, locale } = Astro.props; const { body: bodyOriginal, locale } = Astro.props;
let body = ""; let body = "";
@@ -25,7 +30,11 @@ for (const line of bodyOriginal.split("\n")) {
const macro = match[1]; const macro = match[1];
const value = match[2]; const value = match[2];
macros[macro] = value; if (macro in macros) {
macros[macro].push(value);
} else {
macros[macro] = [value];
}
} }
--- ---
@@ -56,7 +65,17 @@ for (const line of bodyOriginal.split("\n")) {
<div class="content"> <div class="content">
<MarkdownCustom {body} /> <MarkdownCustom {body} />
{"see" in macros && <ApiMacroSee {locale} value={macros.see} />} <!-- {"see" in macros && <ApiMacroSee {locale} value={macros.see} />}
{"type" in macros && <ApiMacroType {locale} value={macros.type} />} {"type" in macros && <ApiMacroType {locale} value={macros.type} />} -->
{
Object.entries(macroComponents).map(([macro, Component]) => {
if (!(macro in macros)) return null;
return macros[macro].map((value) => {
return <Component {locale} value={value} />;
});
})
}
</div> </div>
</div> </div>
@@ -1,7 +1,6 @@
--- ---
import { sluggify } from "@blitzkit/core"; import { sluggify } from "@blitzkit/core";
import { literalsArray } from "@blitzkit/i18n"; import { Code } from "./Code";
import { api } from "../core/api/dynamic";
import { Link } from "./Link"; import { Link } from "./Link";
import { Text } from "./Text"; import { Text } from "./Text";
@@ -10,10 +9,9 @@ interface Props {
locale: string; locale: string;
} }
const bodyPattern = /^([a-z0-9-\/\.]+) (.+)$/; const bodyPattern = /^([a-z0-9-\/\.\[\]]+) (.+)$/;
const { value, locale } = Astro.props; const { value, locale } = Astro.props;
const strings = await api.strings(locale);
const match = value.match(bodyPattern); const match = value.match(bodyPattern);
@@ -26,10 +24,13 @@ const message = match[2];
--- ---
<Text> <Text>
{ <Text lowContrast weight="medium" color="tomato">
literalsArray(strings.api.macros.see, { <Code>@see</Code>
path: <Link href={`#${sluggify(path)}`}>{path}</Link>, </Text>
message,
}) <Link underline="never" href={`#${sluggify(path)}`}>
} <Code>{path}</Code>
</Link>
{message}
</Text> </Text>
@@ -5,6 +5,8 @@ import { Link } from "./Link";
import { api } from "../core/api/dynamic"; import { api } from "../core/api/dynamic";
import HighlightedCodeBlock from "./HighlightedCodeBlock.astro"; import HighlightedCodeBlock from "./HighlightedCodeBlock.astro";
import { Text } from "./Text"; import { Text } from "./Text";
import { ArrowBottomRightIcon } from "@radix-ui/react-icons";
import { Code } from "./Code";
interface Props { interface Props {
value: string; value: string;
@@ -73,6 +75,14 @@ stripped = stripped.replaceAll(" ", " ");
--- ---
<style> <style>
.macro {
color: var(--gray-11);
display: flex;
align-items: center;
gap: var(--space-2);
}
.types { .types {
overflow: hidden; overflow: hidden;
@@ -115,9 +125,13 @@ stripped = stripped.replaceAll(" ", " ");
} }
</script> </script>
<Text> <div class="macro">
{strings.api.macros.types} <Text lowContrast weight="medium" color="tomato">
</Text> <Code>@types</Code>
</Text>
<ArrowBottomRightIcon />
</div>
<div class="types"> <div class="types">
<HighlightedCodeBlock {lang} content={stripped} /> <HighlightedCodeBlock {lang} content={stripped} />
@@ -2,10 +2,6 @@
font-size: var(--font-size-regular); font-size: var(--font-size-regular);
color: var(--gray-12); color: var(--gray-12);
&[data-low-contrast="true"] {
color: var(--white-a9);
}
&[data-size="minor"] { &[data-size="minor"] {
font-size: var(--font-size-minor); font-size: var(--font-size-minor);
} }
@@ -1,5 +1,6 @@
import type { ComponentProps } from "react"; import type { ComponentProps } from "react";
import { classNames } from "../../core/ui/classNames"; import { classNames } from "../../core/ui/classNames";
import type { Color } from "../../core/ui/color";
import styles from "./index.module.css"; import styles from "./index.module.css";
export interface TextProps extends ComponentProps<"span"> { export interface TextProps extends ComponentProps<"span"> {
@@ -7,6 +8,7 @@ export interface TextProps extends ComponentProps<"span"> {
lowContrast?: boolean; lowContrast?: boolean;
size?: "regular" | "minor" | "major"; size?: "regular" | "minor" | "major";
align?: "left" | "center" | "right"; align?: "left" | "center" | "right";
color?: Color;
} }
export function Text({ export function Text({
@@ -16,6 +18,7 @@ export function Text({
weight, weight,
style, style,
align, align,
color = "gray",
...props ...props
}: TextProps) { }: TextProps) {
return ( return (
@@ -25,6 +28,7 @@ export function Text({
data-size={size} data-size={size}
data-weight={weight} data-weight={weight}
data-align={align === "left" ? undefined : align} data-align={align === "left" ? undefined : align}
style={{ color: `var(--${color}-${lowContrast ? 10 : 12})` }}
{...props} {...props}
/> />
); );
@@ -2,6 +2,7 @@
import "@radix-ui/colors/amber-dark.css"; import "@radix-ui/colors/amber-dark.css";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import ApiGroup from "../../../components/ApiGroup.astro"; import ApiGroup from "../../../components/ApiGroup.astro";
import ColorScale from "../../../components/ColorScale.astro";
import { Heading } from "../../../components/Heading"; import { Heading } from "../../../components/Heading";
import { Section } from "../../../components/Section"; import { Section } from "../../../components/Section";
import SyntaxStyles from "../../../components/SyntaxStyles.astro"; import SyntaxStyles from "../../../components/SyntaxStyles.astro";
@@ -25,8 +26,10 @@ paths.sort((a, b) => a.path.localeCompare(b.path));
--- ---
<BaseLayout {locale} accent="brown"> <BaseLayout {locale} accent="brown">
<ToolBanner {locale} tool={tools.api} slot="pre-app" />
<SyntaxStyles slot="head" /> <SyntaxStyles slot="head" />
<ColorScale color="tomato" slot="head" />
<ToolBanner {locale} tool={tools.api} slot="pre-app" />
<Section> <Section>
<Heading>{strings.api.json}</Heading> <Heading>{strings.api.json}</Heading>
@@ -10,9 +10,12 @@ export const getStaticPaths = (async () => {
}) satisfies GetStaticPaths; }) satisfies GetStaticPaths;
/** /**
* Returns data on an avatar based on its `id`. * Returns data on an avatar based on its `id`. Do not use the `.webp` URLs
* from the returned data as they point to Wargaming's servers which may update
* over time, out of sync with BlitzKit.
* *
* @see avatars/list.json for all avatar ids. * @see avatars/list.json for all avatar ids.
* @see avatars/[id].webp for avatar images.
* @type avatar * @type avatar
*/ */
export async function GET({ params }: APIContext<never, { id: string }>) { export async function GET({ params }: APIContext<never, { id: string }>) {