docs: give GDK its own navigation and developer guides (#13165)
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
export type LanguageId = "rust" | "python" | "kotlin";
|
||||
|
||||
export type Language = {
|
||||
id: LanguageId;
|
||||
label: string;
|
||||
prism: string;
|
||||
func: (name: string) => string;
|
||||
field: (name: string) => string;
|
||||
variant: (name: string, isDataCarrying: boolean) => string;
|
||||
type: (type: string) => string;
|
||||
default: (value: string) => string;
|
||||
errorType: (name: string) => string;
|
||||
};
|
||||
|
||||
export type GdkParam = {
|
||||
name: string;
|
||||
type: string;
|
||||
default: string | null;
|
||||
docs: string;
|
||||
};
|
||||
|
||||
export type GdkFunc = {
|
||||
name: string;
|
||||
docs: string;
|
||||
params: GdkParam[];
|
||||
returns: string | null;
|
||||
throws: string | null;
|
||||
isAsync: boolean;
|
||||
};
|
||||
|
||||
export type GdkItem = {
|
||||
name: string;
|
||||
kind: "object" | "callback" | "record" | "enum" | "error";
|
||||
docs: string;
|
||||
fields: GdkParam[];
|
||||
variants: { name: string; fields: GdkParam[] }[];
|
||||
methods: GdkFunc[];
|
||||
};
|
||||
|
||||
export type GdkApiDoc = {
|
||||
version: string;
|
||||
docVersion: string;
|
||||
source: string;
|
||||
functions: GdkFunc[];
|
||||
items: GdkItem[];
|
||||
};
|
||||
|
||||
export const LANGUAGES: Language[];
|
||||
export function slug(...parts: string[]): string;
|
||||
export function funcAnchor(func: GdkFunc, owner?: string): string;
|
||||
export function itemAnchor(item: GdkItem): string;
|
||||
export function memberAnchor(
|
||||
ownerAnchor: string,
|
||||
kind: string,
|
||||
name: string,
|
||||
): string;
|
||||
export function signature(
|
||||
func: GdkFunc,
|
||||
language: Language,
|
||||
owner?: string,
|
||||
): string;
|
||||
export function variantName(
|
||||
item: GdkItem,
|
||||
variant: GdkItem["variants"][number],
|
||||
language: Language,
|
||||
): string;
|
||||
+86
-32
@@ -2,20 +2,16 @@
|
||||
// mirror the uniffi 0.32 code generators, which are the actual source of the
|
||||
// Python and Kotlin bindings.
|
||||
|
||||
export type LanguageId = "rust" | "python" | "kotlin";
|
||||
|
||||
const toSnake = (name: string) => name;
|
||||
const toCamel = (name: string) =>
|
||||
name.replace(/_([a-z0-9])/g, (_, char: string) => char.toUpperCase());
|
||||
const toShoutySnake = (name: string) =>
|
||||
const toSnake = (name) => name;
|
||||
const toCamel = (name) =>
|
||||
name.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase());
|
||||
const toShoutySnake = (name) =>
|
||||
name
|
||||
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
||||
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
||||
.toUpperCase();
|
||||
|
||||
type Scalars = Record<string, string>;
|
||||
|
||||
const PYTHON_SCALARS: Scalars = {
|
||||
const PYTHON_SCALARS = {
|
||||
String: "str",
|
||||
bool: "bool",
|
||||
i8: "int",
|
||||
@@ -31,7 +27,7 @@ const PYTHON_SCALARS: Scalars = {
|
||||
"()": "None",
|
||||
};
|
||||
|
||||
const KOTLIN_SCALARS: Scalars = {
|
||||
const KOTLIN_SCALARS = {
|
||||
String: "String",
|
||||
bool: "Boolean",
|
||||
i8: "Byte",
|
||||
@@ -47,10 +43,10 @@ const KOTLIN_SCALARS: Scalars = {
|
||||
"()": "Unit",
|
||||
};
|
||||
|
||||
const generic = (type: string, name: string): string[] | null => {
|
||||
const generic = (type, name) => {
|
||||
const match = new RegExp(`^${name}\\s*<(.+)>$`, "s").exec(type.trim());
|
||||
if (!match) return null;
|
||||
const args: string[] = [];
|
||||
const args = [];
|
||||
let depth = 0;
|
||||
let current = "";
|
||||
for (const char of match[1]) {
|
||||
@@ -67,7 +63,7 @@ const generic = (type: string, name: string): string[] | null => {
|
||||
return args;
|
||||
};
|
||||
|
||||
const mapType = (type: string, language: LanguageId): string => {
|
||||
const mapType = (type, language) => {
|
||||
const trimmed = type.trim();
|
||||
if (language === "rust") return trimmed;
|
||||
|
||||
@@ -92,35 +88,28 @@ const mapType = (type: string, language: LanguageId): string => {
|
||||
const map = generic(trimmed, "HashMap");
|
||||
if (map) {
|
||||
const [key, value] = map.map((arg) => mapType(arg, language));
|
||||
return language === "python" ? `dict[${key}, ${value}]` : `Map<${key}, ${value}>`;
|
||||
return language === "python"
|
||||
? `dict[${key}, ${value}]`
|
||||
: `Map<${key}, ${value}>`;
|
||||
}
|
||||
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
const mapDefault = (value: string, language: LanguageId): string => {
|
||||
const mapDefault = (value, language) => {
|
||||
if (language === "rust") return value;
|
||||
if (value === "None") return language === "python" ? "None" : "null";
|
||||
if (value === "true" || value === "false") {
|
||||
return language === "python" ? (value === "true" ? "True" : "False") : value;
|
||||
return language === "python"
|
||||
? value === "true"
|
||||
? "True"
|
||||
: "False"
|
||||
: value;
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
export type Language = {
|
||||
id: LanguageId;
|
||||
label: string;
|
||||
/** Prism language for syntax highlighting. */
|
||||
prism: string;
|
||||
func: (name: string) => string;
|
||||
field: (name: string) => string;
|
||||
variant: (name: string, isDataCarrying: boolean) => string;
|
||||
type: (type: string) => string;
|
||||
default: (value: string) => string;
|
||||
errorType: (name: string) => string;
|
||||
};
|
||||
|
||||
export const LANGUAGES: Language[] = [
|
||||
const LANGUAGES = [
|
||||
{
|
||||
id: "rust",
|
||||
label: "Rust",
|
||||
@@ -140,7 +129,8 @@ export const LANGUAGES: Language[] = [
|
||||
field: toSnake,
|
||||
// Flat enums become `enum.Enum` members; data-carrying variants become
|
||||
// nested dataclasses that keep their Rust casing.
|
||||
variant: (name, isDataCarrying) => (isDataCarrying ? name : toShoutySnake(name)),
|
||||
variant: (name, isDataCarrying) =>
|
||||
isDataCarrying ? name : toShoutySnake(name),
|
||||
type: (type) => mapType(type, "python"),
|
||||
default: (value) => mapDefault(value, "python"),
|
||||
errorType: (name) => name,
|
||||
@@ -153,9 +143,73 @@ export const LANGUAGES: Language[] = [
|
||||
field: toCamel,
|
||||
// Flat enums become `enum class` entries; data-carrying variants become
|
||||
// `sealed class` subclasses that keep their Rust casing.
|
||||
variant: (name, isDataCarrying) => (isDataCarrying ? name : toShoutySnake(name)),
|
||||
variant: (name, isDataCarrying) =>
|
||||
isDataCarrying ? name : toShoutySnake(name),
|
||||
type: (type) => mapType(type, "kotlin"),
|
||||
default: (value) => mapDefault(value, "kotlin"),
|
||||
errorType: (name) => name.replace(/Error$/, "Exception"),
|
||||
},
|
||||
];
|
||||
|
||||
const slug = (...parts) =>
|
||||
parts
|
||||
.join("-")
|
||||
.replace(/[^a-zA-Z0-9]+/g, "-")
|
||||
.toLowerCase();
|
||||
|
||||
const funcAnchor = (func, owner) => slug(owner ?? "fn", func.name);
|
||||
const itemAnchor = (item) => slug(item.name);
|
||||
const memberAnchor = (ownerAnchor, kind, name) => slug(ownerAnchor, kind, name);
|
||||
|
||||
function signature(func, language, owner) {
|
||||
const params = func.params
|
||||
.map((param) => {
|
||||
const type = language.type(param.type);
|
||||
const suffix = param.default
|
||||
? ` = ${language.default(param.default)}`
|
||||
: "";
|
||||
return `${language.field(param.name)}: ${type}${suffix}`;
|
||||
})
|
||||
.join(", ");
|
||||
|
||||
const name = language.func(func.name);
|
||||
const returns = func.returns ? language.type(func.returns) : null;
|
||||
const prefix = owner ? `${owner}.` : "";
|
||||
|
||||
if (language.id === "rust") {
|
||||
const asyncKeyword = func.isAsync ? "async " : "";
|
||||
const result = func.throws
|
||||
? `Result<${returns ?? "()"}, ${func.throws}>`
|
||||
: returns;
|
||||
return `${asyncKeyword}fn ${prefix}${name}(${params})${result ? ` -> ${result}` : ""}`;
|
||||
}
|
||||
|
||||
if (language.id === "python") {
|
||||
const asyncKeyword = func.isAsync ? "async " : "";
|
||||
return `${asyncKeyword}def ${prefix}${name}(${params})${returns ? ` -> ${returns}` : ""}`;
|
||||
}
|
||||
|
||||
const suspend = func.isAsync ? "suspend " : "";
|
||||
const throwsAnnotation = func.throws
|
||||
? `@Throws(${language.errorType(func.throws)}::class)\n`
|
||||
: "";
|
||||
return `${throwsAnnotation}${suspend}fun ${prefix}${name}(${params})${returns ? `: ${returns}` : ""}`;
|
||||
}
|
||||
|
||||
function variantName(item, variant, language) {
|
||||
if (item.kind === "error" && language.id === "kotlin") {
|
||||
return `${language.errorType(item.name)}.${variant.name}`;
|
||||
}
|
||||
const dataCarrying = item.variants.some((entry) => entry.fields.length > 0);
|
||||
return language.variant(variant.name, dataCarrying);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
LANGUAGES,
|
||||
slug,
|
||||
funcAnchor,
|
||||
itemAnchor,
|
||||
memberAnchor,
|
||||
signature,
|
||||
variantName,
|
||||
};
|
||||
@@ -6,42 +6,23 @@ import { useHistory, useLocation } from "@docusaurus/router";
|
||||
import { useAnchorTargetClassName } from "@docusaurus/theme-common";
|
||||
import CodeBlock from "@theme/CodeBlock";
|
||||
import apiData from "@site/src/data/gdk-api.json";
|
||||
import { LANGUAGES, Language, LanguageId } from "./languages";
|
||||
import {
|
||||
LANGUAGES,
|
||||
slug,
|
||||
funcAnchor,
|
||||
itemAnchor,
|
||||
memberAnchor,
|
||||
signature,
|
||||
variantName,
|
||||
type Language,
|
||||
type LanguageId,
|
||||
type GdkParam,
|
||||
type GdkFunc,
|
||||
type GdkItem,
|
||||
type GdkApiDoc,
|
||||
} from "./api";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
type GdkParam = {
|
||||
name: string;
|
||||
type: string;
|
||||
default: string | null;
|
||||
docs: string;
|
||||
};
|
||||
|
||||
type GdkFunc = {
|
||||
name: string;
|
||||
docs: string;
|
||||
params: GdkParam[];
|
||||
returns: string | null;
|
||||
throws: string | null;
|
||||
isAsync: boolean;
|
||||
};
|
||||
|
||||
type GdkItem = {
|
||||
name: string;
|
||||
kind: "object" | "callback" | "record" | "enum" | "error";
|
||||
docs: string;
|
||||
fields: GdkParam[];
|
||||
variants: { name: string; fields: GdkParam[] }[];
|
||||
methods: GdkFunc[];
|
||||
};
|
||||
|
||||
type GdkApiDoc = {
|
||||
version: string;
|
||||
docVersion: string;
|
||||
source: string;
|
||||
functions: GdkFunc[];
|
||||
items: GdkItem[];
|
||||
};
|
||||
|
||||
const VERSIONS = (apiData as { versions: GdkApiDoc[] }).versions;
|
||||
|
||||
const DEFAULT_VERSION = VERSIONS[0].docVersion;
|
||||
@@ -64,8 +45,12 @@ const readSelection = (search: string): Selection => {
|
||||
const requestedVersion = params.get(VERSION_PARAM);
|
||||
const requestedLanguage = params.get(LANGUAGE_PARAM);
|
||||
return {
|
||||
docVersion: isKnownVersion(requestedVersion) ? requestedVersion : DEFAULT_VERSION,
|
||||
languageId: isKnownLanguage(requestedLanguage) ? requestedLanguage : DEFAULT_LANGUAGE,
|
||||
docVersion: isKnownVersion(requestedVersion)
|
||||
? requestedVersion
|
||||
: DEFAULT_VERSION,
|
||||
languageId: isKnownLanguage(requestedLanguage)
|
||||
? requestedLanguage
|
||||
: DEFAULT_LANGUAGE,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -96,19 +81,12 @@ const KIND_HEADINGS: Record<GdkItem["kind"], string> = {
|
||||
error: "Errors",
|
||||
};
|
||||
|
||||
const slug = (...parts: string[]) =>
|
||||
parts.join("-").replace(/[^a-zA-Z0-9]+/g, "-").toLowerCase();
|
||||
|
||||
// Anchors use the canonical Rust names so a link keeps working when the reader
|
||||
// switches the language or version toggle.
|
||||
const funcAnchor = (func: GdkFunc, owner?: string) => slug(owner ?? "fn", func.name);
|
||||
const itemAnchor = (item: GdkItem) => slug(item.name);
|
||||
const memberAnchor = (ownerAnchor: string, kind: string, name: string) =>
|
||||
slug(ownerAnchor, kind, name);
|
||||
|
||||
function anchorsForFunc(func: GdkFunc, owner?: string): string[] {
|
||||
const anchor = funcAnchor(func, owner);
|
||||
return [anchor, ...func.params.map((param) => memberAnchor(anchor, "param", param.name))];
|
||||
return [
|
||||
anchor,
|
||||
...func.params.map((param) => memberAnchor(anchor, "param", param.name)),
|
||||
];
|
||||
}
|
||||
|
||||
function anchorsForDoc(doc: GdkApiDoc): string[] {
|
||||
@@ -118,56 +96,20 @@ function anchorsForDoc(doc: GdkApiDoc): string[] {
|
||||
doc.items.forEach((item) => {
|
||||
const anchor = itemAnchor(item);
|
||||
anchors.push(anchor, slug(item.kind, "types"));
|
||||
item.fields.forEach((field) => anchors.push(memberAnchor(anchor, "field", field.name)));
|
||||
item.fields.forEach((field) =>
|
||||
anchors.push(memberAnchor(anchor, "field", field.name)),
|
||||
);
|
||||
item.variants.forEach((variant) =>
|
||||
anchors.push(memberAnchor(anchor, "variant", variant.name)),
|
||||
);
|
||||
item.methods.forEach((method) => anchors.push(...anchorsForFunc(method, item.name)));
|
||||
item.methods.forEach((method) =>
|
||||
anchors.push(...anchorsForFunc(method, item.name)),
|
||||
);
|
||||
});
|
||||
|
||||
return anchors;
|
||||
}
|
||||
|
||||
function signature(func: GdkFunc, language: Language, owner?: string): string {
|
||||
const params = func.params
|
||||
.map((param) => {
|
||||
const type = language.type(param.type);
|
||||
const suffix = param.default ? ` = ${language.default(param.default)}` : "";
|
||||
switch (language.id) {
|
||||
case "rust":
|
||||
return `${param.name}: ${type}${suffix}`;
|
||||
case "python":
|
||||
return `${language.field(param.name)}: ${type}${suffix}`;
|
||||
default:
|
||||
return `${language.field(param.name)}: ${type}${suffix}`;
|
||||
}
|
||||
})
|
||||
.join(", ");
|
||||
|
||||
const name = language.func(func.name);
|
||||
const returns = func.returns ? language.type(func.returns) : null;
|
||||
const prefix = owner ? `${owner}.` : "";
|
||||
|
||||
if (language.id === "rust") {
|
||||
const asyncKeyword = func.isAsync ? "async " : "";
|
||||
const result = func.throws
|
||||
? `Result<${returns ?? "()"}, ${func.throws}>`
|
||||
: returns;
|
||||
return `${asyncKeyword}fn ${prefix}${name}(${params})${result ? ` -> ${result}` : ""}`;
|
||||
}
|
||||
|
||||
if (language.id === "python") {
|
||||
const asyncKeyword = func.isAsync ? "async " : "";
|
||||
return `${asyncKeyword}def ${prefix}${name}(${params})${returns ? ` -> ${returns}` : ""}`;
|
||||
}
|
||||
|
||||
const suspend = func.isAsync ? "suspend " : "";
|
||||
const throwsAnnotation = func.throws
|
||||
? `@Throws(${language.errorType(func.throws)}::class)\n`
|
||||
: "";
|
||||
return `${throwsAnnotation}${suspend}fun ${prefix}${name}(${params})${returns ? `: ${returns}` : ""}`;
|
||||
}
|
||||
|
||||
function HashLink({ anchor, label }: { anchor: string; label: string }) {
|
||||
const search = useContext(SelectionSearchContext);
|
||||
const title = `Direct link to ${label}`;
|
||||
@@ -199,7 +141,10 @@ function Anchored({
|
||||
}) {
|
||||
const anchorTargetClassName = useAnchorTargetClassName(anchor);
|
||||
return (
|
||||
<As id={anchor} className={clsx("anchor", anchorTargetClassName, className)}>
|
||||
<As
|
||||
id={anchor}
|
||||
className={clsx("anchor", anchorTargetClassName, className)}
|
||||
>
|
||||
{children}
|
||||
<HashLink anchor={anchor} label={label} />
|
||||
</As>
|
||||
@@ -248,7 +193,13 @@ function ParamTable({
|
||||
<code>{language.type(row.type)}</code>
|
||||
</td>
|
||||
{hasDefaults && (
|
||||
<td>{row.default ? <code>{language.default(row.default)}</code> : "—"}</td>
|
||||
<td>
|
||||
{row.default ? (
|
||||
<code>{language.default(row.default)}</code>
|
||||
) : (
|
||||
"—"
|
||||
)}
|
||||
</td>
|
||||
)}
|
||||
<td>{row.docs || "—"}</td>
|
||||
</tr>
|
||||
@@ -272,11 +223,18 @@ function FuncEntry({
|
||||
const name = language.func(func.name);
|
||||
return (
|
||||
<div className={styles.entry}>
|
||||
<Anchored as="h4" anchor={anchor} label={name} className={styles.entryTitle}>
|
||||
<Anchored
|
||||
as="h4"
|
||||
anchor={anchor}
|
||||
label={name}
|
||||
className={styles.entryTitle}
|
||||
>
|
||||
<code>{name}</code>
|
||||
</Anchored>
|
||||
{func.docs && <p>{func.docs}</p>}
|
||||
<CodeBlock language={language.prism}>{signature(func, language, owner)}</CodeBlock>
|
||||
<CodeBlock language={language.prism}>
|
||||
{signature(func, language, owner)}
|
||||
</CodeBlock>
|
||||
<ParamTable
|
||||
rows={func.params}
|
||||
language={language}
|
||||
@@ -294,12 +252,17 @@ function FuncEntry({
|
||||
}
|
||||
|
||||
function ItemEntry({ item, language }: { item: GdkItem; language: Language }) {
|
||||
const dataCarrying = item.variants.some((variant) => variant.fields.length > 0);
|
||||
const anchor = itemAnchor(item);
|
||||
const name = item.kind === "error" ? language.errorType(item.name) : item.name;
|
||||
const name =
|
||||
item.kind === "error" ? language.errorType(item.name) : item.name;
|
||||
return (
|
||||
<section className={styles.item}>
|
||||
<Anchored as="h3" anchor={anchor} label={name} className={styles.itemTitle}>
|
||||
<Anchored
|
||||
as="h3"
|
||||
anchor={anchor}
|
||||
label={name}
|
||||
className={styles.itemTitle}
|
||||
>
|
||||
<code>{name}</code>
|
||||
<span className={styles.badge}>{KIND_LABELS[item.kind]}</span>
|
||||
</Anchored>
|
||||
@@ -323,19 +286,16 @@ function ItemEntry({ item, language }: { item: GdkItem; language: Language }) {
|
||||
</thead>
|
||||
<tbody>
|
||||
{item.variants.map((variant) => {
|
||||
const variantName =
|
||||
item.kind === "error" && language.id === "kotlin"
|
||||
? `${language.errorType(item.name)}.${variant.name}`
|
||||
: language.variant(variant.name, dataCarrying);
|
||||
const name = variantName(item, variant, language);
|
||||
return (
|
||||
<tr key={variant.name}>
|
||||
<Anchored
|
||||
as="td"
|
||||
anchor={memberAnchor(anchor, "variant", variant.name)}
|
||||
label={variantName}
|
||||
label={name}
|
||||
className={styles.nameCell}
|
||||
>
|
||||
<code>{variantName}</code>
|
||||
<code>{name}</code>
|
||||
</Anchored>
|
||||
<td>
|
||||
{variant.fields.length === 0
|
||||
@@ -343,7 +303,8 @@ function ItemEntry({ item, language }: { item: GdkItem; language: Language }) {
|
||||
: variant.fields.map((field) => (
|
||||
<div key={field.name}>
|
||||
<code>
|
||||
{language.field(field.name)}: {language.type(field.type)}
|
||||
{language.field(field.name)}:{" "}
|
||||
{language.type(field.type)}
|
||||
</code>
|
||||
</div>
|
||||
))}
|
||||
@@ -356,7 +317,12 @@ function ItemEntry({ item, language }: { item: GdkItem; language: Language }) {
|
||||
)}
|
||||
|
||||
{item.methods.map((method) => (
|
||||
<FuncEntry key={method.name} func={method} language={language} owner={item.name} />
|
||||
<FuncEntry
|
||||
key={method.name}
|
||||
func={method}
|
||||
language={language}
|
||||
owner={item.name}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
@@ -390,11 +356,14 @@ export default function GdkApiReference() {
|
||||
|
||||
const language = LANGUAGES.find((entry) => entry.id === languageId)!;
|
||||
const doc = useMemo(
|
||||
() => VERSIONS.find((entry) => entry.docVersion === docVersion) ?? VERSIONS[0],
|
||||
() =>
|
||||
VERSIONS.find((entry) => entry.docVersion === docVersion) ?? VERSIONS[0],
|
||||
[docVersion],
|
||||
);
|
||||
|
||||
anchorsForDoc(VERSIONS[0]).forEach((anchor) => brokenLinks.collectAnchor(anchor));
|
||||
anchorsForDoc(VERSIONS[0]).forEach((anchor) =>
|
||||
brokenLinks.collectAnchor(anchor),
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const anchor = location.hash.slice(1);
|
||||
@@ -403,14 +372,25 @@ export default function GdkApiReference() {
|
||||
}, [docVersion, languageId, location.hash]);
|
||||
|
||||
const grouped = useMemo(() => {
|
||||
const order: GdkItem["kind"][] = ["object", "callback", "record", "enum", "error"];
|
||||
const order: GdkItem["kind"][] = [
|
||||
"object",
|
||||
"callback",
|
||||
"record",
|
||||
"enum",
|
||||
"error",
|
||||
];
|
||||
return order
|
||||
.map((kind) => ({ kind, items: doc.items.filter((item) => item.kind === kind) }))
|
||||
.map((kind) => ({
|
||||
kind,
|
||||
items: doc.items.filter((item) => item.kind === kind),
|
||||
}))
|
||||
.filter((group) => group.items.length > 0);
|
||||
}, [doc]);
|
||||
|
||||
return (
|
||||
<SelectionSearchContext.Provider value={selectionSearch(selection, location.search)}>
|
||||
<SelectionSearchContext.Provider
|
||||
value={selectionSearch(selection, location.search)}
|
||||
>
|
||||
<div>
|
||||
<div className={styles.toolbar}>
|
||||
<div className={styles.tabs} role="tablist" aria-label="SDK language">
|
||||
@@ -420,7 +400,9 @@ export default function GdkApiReference() {
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={entry.id === languageId}
|
||||
className={entry.id === languageId ? styles.tabActive : styles.tab}
|
||||
className={
|
||||
entry.id === languageId ? styles.tabActive : styles.tab
|
||||
}
|
||||
onClick={() => select({ languageId: entry.id })}
|
||||
>
|
||||
{entry.label}
|
||||
@@ -445,7 +427,8 @@ export default function GdkApiReference() {
|
||||
</div>
|
||||
|
||||
<p className={styles.meta}>
|
||||
Generated from <code>{doc.source}</code> at <code>goose-sdk {doc.version}</code>.
|
||||
Generated from <code>{doc.source}</code> at{" "}
|
||||
<code>goose-sdk {doc.version}</code>.
|
||||
</p>
|
||||
|
||||
<Anchored as="h2" anchor="functions" label="Functions">
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { useLocation } from "@docusaurus/router";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import type { Props as NavbarItemConfig } from "@theme/NavbarItem";
|
||||
|
||||
export const GdkBlogContext = createContext(false);
|
||||
|
||||
export function useGdkNavigation(): boolean {
|
||||
const { pathname } = useLocation();
|
||||
const gdkPath = useBaseUrl("/docs/gdk");
|
||||
const blogPath = useBaseUrl("/blog/tags/gdk");
|
||||
const isGdkPost = useContext(GdkBlogContext);
|
||||
|
||||
return (
|
||||
isGdkPost ||
|
||||
[gdkPath, blogPath].some(
|
||||
(path) => pathname === path || pathname.startsWith(`${path}/`),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export const gdkNavbarItems = [
|
||||
{
|
||||
to: "/blog/tags/gdk",
|
||||
label: "Blog",
|
||||
activeBasePath: "blog",
|
||||
},
|
||||
{
|
||||
href: "https://github.com/aaif-goose/goose",
|
||||
label: "GitHub",
|
||||
},
|
||||
{ to: "/", label: "Back to goose", exact: true },
|
||||
] satisfies NavbarItemConfig[];
|
||||
@@ -498,3 +498,21 @@ main {
|
||||
[data-theme="dark"] .scrollbar-visible::-webkit-scrollbar-thumb:hover {
|
||||
background-color: var(--dark-grey-60);
|
||||
}
|
||||
|
||||
html:has(.gdk-navigation) {
|
||||
--gdk-accent: #6d28d9;
|
||||
--ifm-link-color: var(--gdk-accent);
|
||||
--ifm-breadcrumb-color-active: var(--gdk-accent);
|
||||
--ifm-menu-color-active: var(--gdk-accent);
|
||||
--ifm-menu-color-background-active: rgba(109, 40, 217, 0.08);
|
||||
--ifm-navbar-link-hover-color: var(--gdk-accent);
|
||||
}
|
||||
|
||||
html[data-theme="dark"]:has(.gdk-navigation) {
|
||||
--gdk-accent: #c4b5fd;
|
||||
--ifm-menu-color-background-active: rgba(196, 181, 253, 0.1);
|
||||
}
|
||||
|
||||
html:has(.gdk-navigation) .table-of-contents {
|
||||
--ifm-color-primary: var(--gdk-accent);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 1rem;
|
||||
margin: 2rem 0;
|
||||
}
|
||||
|
||||
.card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
padding: 1.5rem;
|
||||
border: 1px solid var(--ifm-color-emphasis-300);
|
||||
border-radius: 8px;
|
||||
color: var(--ifm-font-color-base);
|
||||
}
|
||||
|
||||
.card:focus-within {
|
||||
border-color: var(--ifm-color-primary);
|
||||
}
|
||||
|
||||
.card a:focus-visible {
|
||||
outline: 2px solid var(--ifm-color-primary);
|
||||
outline-offset: 3px;
|
||||
}
|
||||
|
||||
.focus {
|
||||
margin: 0 0 0.75rem;
|
||||
color: var(--ifm-color-emphasis-700);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.card h2 {
|
||||
margin: 0 0 0.75rem;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.card > p:not(.focus) {
|
||||
margin: 0 0 1.5rem;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
margin-top: auto;
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.footer > span {
|
||||
color: var(--ifm-color-emphasis-700);
|
||||
}
|
||||
|
||||
.footer p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
color: var(--ifm-link-color);
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ function StandardsSection() {
|
||||
an ACP server — connect from Zed, JetBrains, or VS Code — and can
|
||||
use ACP agents like Claude Code and Codex as providers.
|
||||
</p>
|
||||
<Link to="/docs/gdk/acp">goose as ACP server →</Link>
|
||||
<Link to="/docs/guides/zed">Set up goose in Zed →</Link>
|
||||
</div>
|
||||
<div className={styles.standardCard}>
|
||||
<h3>Agentic AI Foundation</h3>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import useBaseUrl from "@docusaurus/useBaseUrl";
|
||||
import OriginalBlogPostPage from "@theme-original/BlogPostPage";
|
||||
import type { Props } from "@theme/BlogPostPage";
|
||||
import { GdkBlogContext } from "@site/src/components/GdkNavigation";
|
||||
|
||||
export default function BlogPostPage(props: Props): ReactNode {
|
||||
const gdkTag = useBaseUrl("/blog/tags/gdk");
|
||||
const isGdk = props.content.metadata.tags.some(
|
||||
(tag) => tag.permalink === gdkTag,
|
||||
);
|
||||
|
||||
return (
|
||||
<GdkBlogContext.Provider value={isGdk}>
|
||||
<OriginalBlogPostPage
|
||||
{...props}
|
||||
sidebar={isGdk ? { ...props.sidebar, items: [] } : props.sidebar}
|
||||
/>
|
||||
</GdkBlogContext.Provider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import OriginalBlogTagsPostsPage from "@theme-original/BlogTagsPostsPage";
|
||||
import type { Props } from "@theme/BlogTagsPostsPage";
|
||||
import { useGdkNavigation } from "@site/src/components/GdkNavigation";
|
||||
|
||||
export default function BlogTagsPostsPage(props: Props): ReactNode {
|
||||
const isGdk = useGdkNavigation();
|
||||
|
||||
return (
|
||||
<OriginalBlogTagsPostsPage
|
||||
{...props}
|
||||
sidebar={isGdk ? { ...props.sidebar, items: [] } : props.sidebar}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -452,15 +452,15 @@ function PageActionsMenu(): ReactNode {
|
||||
);
|
||||
}
|
||||
|
||||
// Hook to determine if we should show the copy button
|
||||
function useShouldShowCopyButton(): boolean {
|
||||
const {metadata} = useDoc();
|
||||
|
||||
// Show copy button only on actual content pages (not category/index pages)
|
||||
// A content page should have a source file (.md file)
|
||||
if (metadata.id.startsWith('gdk/')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasSource = metadata?.source && metadata.source.includes('.md');
|
||||
|
||||
// Don't show on category pages (they typically have /category/ in the permalink)
|
||||
const isNotCategoryPage = !metadata?.permalink?.includes('/category/');
|
||||
|
||||
return hasSource && isNotCategoryPage;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import { PageMetadata } from "@docusaurus/theme-common";
|
||||
import { useDoc } from "@docusaurus/plugin-content-docs/client";
|
||||
import OriginalDocItemMetadata from "@theme-original/DocItem/Metadata";
|
||||
|
||||
export default function DocItemMetadata(): ReactNode {
|
||||
const { metadata, frontMatter, assets } = useDoc();
|
||||
if (!metadata.id.startsWith("gdk/")) {
|
||||
return <OriginalDocItemMetadata />;
|
||||
}
|
||||
|
||||
return (
|
||||
<PageMetadata
|
||||
title={metadata.title}
|
||||
description={metadata.description}
|
||||
keywords={frontMatter.keywords}
|
||||
image={assets.image ?? frontMatter.image ?? "/img/gdk/social-preview.png"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import OriginalNavbarContent from "@theme-original/Navbar/Content";
|
||||
import NavbarItem from "@theme/NavbarItem";
|
||||
import NavbarLogo from "@theme/Navbar/Logo";
|
||||
import NavbarColorModeToggle from "@theme/Navbar/ColorModeToggle";
|
||||
import NavbarMobileSidebarToggle from "@theme/Navbar/MobileSidebar/Toggle";
|
||||
import {
|
||||
gdkNavbarItems,
|
||||
useGdkNavigation,
|
||||
} from "@site/src/components/GdkNavigation";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
export default function NavbarContent(): ReactNode {
|
||||
const isGdk = useGdkNavigation();
|
||||
if (!isGdk) {
|
||||
return <OriginalNavbarContent />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="navbar__inner gdk-navigation">
|
||||
<div className="navbar__items">
|
||||
<NavbarMobileSidebarToggle />
|
||||
<NavbarLogo />
|
||||
</div>
|
||||
<div className="navbar__items navbar__items--right">
|
||||
{gdkNavbarItems.map((item) => (
|
||||
<NavbarItem key={item.label} {...item} />
|
||||
))}
|
||||
<NavbarColorModeToggle className={styles.colorModeToggle} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
@media (max-width: 996px) {
|
||||
.colorModeToggle {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import Link from "@docusaurus/Link";
|
||||
import GooseLogo from "@site/static/img/goose.svg";
|
||||
import OriginalNavbarLogo from "@theme-original/Navbar/Logo";
|
||||
import { useGdkNavigation } from "@site/src/components/GdkNavigation";
|
||||
import styles from "./styles.module.css";
|
||||
|
||||
export default function NavbarLogo(): ReactNode {
|
||||
const isGdk = useGdkNavigation();
|
||||
return isGdk ? (
|
||||
<Link className="navbar__brand margin-right--md" to="/docs/gdk">
|
||||
<GooseLogo
|
||||
aria-hidden="true"
|
||||
width={28}
|
||||
height={28}
|
||||
className={`${styles.mark} margin-right--sm`}
|
||||
/>
|
||||
<b className="navbar__title">GDK</b>
|
||||
</Link>
|
||||
) : (
|
||||
<OriginalNavbarLogo />
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
.mark {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.mark path {
|
||||
fill: var(--gdk-accent);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import React, { type ReactNode } from "react";
|
||||
import OriginalPrimaryMenu from "@theme-original/Navbar/MobileSidebar/PrimaryMenu";
|
||||
import NavbarItem from "@theme/NavbarItem";
|
||||
import { useNavbarMobileSidebar } from "@docusaurus/theme-common/internal";
|
||||
import {
|
||||
gdkNavbarItems,
|
||||
useGdkNavigation,
|
||||
} from "@site/src/components/GdkNavigation";
|
||||
|
||||
export default function NavbarMobilePrimaryMenu(): ReactNode {
|
||||
const isGdk = useGdkNavigation();
|
||||
const mobileSidebar = useNavbarMobileSidebar();
|
||||
if (!isGdk) {
|
||||
return <OriginalPrimaryMenu />;
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="menu__list">
|
||||
{gdkNavbarItems.map((item) => (
|
||||
<NavbarItem
|
||||
key={item.label}
|
||||
{...item}
|
||||
mobile
|
||||
onClick={() => mobileSidebar.toggle()}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user