Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/social-cycles-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@open-rpc/markdown-generator": patch
"@open-rpc/docusaurus-plugin": patch
---

Change adds support for some index frontmatter customization
7 changes: 6 additions & 1 deletion packages/docusaurus-plugin/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ export async function generateDocs(
}

// NOTE a little hacky, but good for now
const indexContent = renderIndex(doc, "mdx");
const additionalFrontmatter: Record<string, string> = {};
if (options.indexSlug) {
additionalFrontmatter["slug"] = options.indexSlug;
}

const indexContent = renderIndex(doc, "mdx", additionalFrontmatter);
const finalIndex =
options.showPoweredBy === true
? `${indexContent}\n---\n\n*Powered by [OpenRPC](https://open-rpc.org)*\n`
Expand Down
2 changes: 2 additions & 0 deletions packages/docusaurus-plugin/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type Options = {
openRPCSpecPath: string;
docOutputPath: string;
showPoweredBy: boolean;
indexSlug: string | undefined;
};

/**
Expand All @@ -23,5 +24,6 @@ export function normalizeOptions(options: Options): PluginOptions {
docOutputPath: options.docOutputPath || "./api-reference",
showPoweredBy:
options.showPoweredBy === undefined ? true : options.showPoweredBy,
indexSlug: options.indexSlug === undefined ? undefined : options.indexSlug,
};
}
1 change: 1 addition & 0 deletions packages/example-site/docs/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# GENERATED DOCUMENTATION - DO NOT EDIT THIS FILE
title: "Ethereum JSON-RPC Specification"
description: "A specification of the standard interface for Ethereum clients."
slug: /api-reference

---

Expand Down
2 changes: 1 addition & 1 deletion packages/example-site/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const config: Config = {
openRPCSpecPath: `./error-group-openrpc.json`,
docOutputPath: `./docs/api-reference`,
showPoweredBy: true,

indexSlug: '/api-reference',
}]],
presets: [
[
Expand Down
6 changes: 6 additions & 0 deletions packages/markdown-generator/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export async function renderDocumentToMarkdownFiles(
export function renderIndex(
doc: DereffedOpenrpcDocument,
markdownType: "mdx" | "md",
additionalFrontmatter: Record<string, string> = {},
): string {
const title = doc.info?.title || "API";
const version = doc.info?.version || "";
Expand Down Expand Up @@ -139,10 +140,15 @@ export function renderIndex(
)
.join("\n");

const frontmatter = Object.entries(additionalFrontmatter)
.map(([key, value]) => `${key}: ${value}`)
.join("\n");

return `---
# GENERATED DOCUMENTATION - DO NOT EDIT THIS FILE
title: "${title}"
description: "${escapeYaml(desc)}"
${frontmatter}
${tagsList}
---
Expand Down
Loading