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/green-toys-cross.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 here fixes minor snake case issue and allows for configurable powered by link.
88 changes: 9 additions & 79 deletions packages/docusaurus-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
import logger from "@docusaurus/logger";
import type { LoadContext, Plugin } from "@docusaurus/types";
import type { PluginContent } from "./types";
import type { Options } from "./options";
import type { Options, PluginOptions } from "./options";
import { normalizeOptions } from "./options";
import { generateDocs } from "./lib";
import fs from "fs/promises";
import path from "path";

const PluginName = "@open-rpc/docusaurus-plugin";

async function initDocs(specPath: string, outputDir: string) {
async function initDocs(
specPath: string,
outputDir: string,
options: PluginOptions,
) {
if (!(await fs.stat(specPath)).isFile()) {
throw new Error(`OpenRPC spec file not found: ${specPath}`);
}
Expand All @@ -38,7 +42,7 @@ async function initDocs(specPath: string, outputDir: string) {
}

try {
await generateDocs(specPath, outputDir);
await generateDocs(specPath, outputDir, options);
} catch (err) {
logger.error(`[${PluginName}] generateDocs failed: ${err}`);
logger.error(
Expand All @@ -64,7 +68,7 @@ export default async function openRPCDocusaurusPlugin(
normalizedOptions.docOutputPath,
);

await initDocs(specPath, outputDir);
await initDocs(specPath, outputDir, normalizedOptions);

return {
name: PluginName,
Expand All @@ -90,39 +94,6 @@ export default async function openRPCDocusaurusPlugin(
*/
async loadContent(): Promise<PluginContent> {
logger.info(`[${PluginName}] loadContent called`);
// await initDocs(specPath, outputDir);
// await generateDocs(specPath, outputDir);

/*
if (!(await fs.stat(specPath)).isFile()) {
throw new Error(`OpenRPC spec file not found: ${specPath}`);
}

try {
const entries = await fs.readdir(outputDir, { withFileTypes: true });
await Promise.all(
entries
.filter((entry) => entry.name !== "index.md")
.map((entry) => {
const fullPath = `${outputDir}/${entry.name}`;
return fs.rm(fullPath, { recursive: true, force: true });
}),
);
} catch {
// Directory doesn't exist yet, that's fine
}

try {
await generateDocs(specPath, outputDir);
} catch (err) {
logger.error(`[${PluginName}] generateDocs failed: ${err}`);
logger.error(
`[${PluginName}] Stack: ${err instanceof Error ? err.stack : "no stack"}`,
);
throw err;
}
*/
// Return content to be used in contentLoaded
return {};
},

Expand All @@ -131,48 +102,7 @@ export default async function openRPCDocusaurusPlugin(
*/
async contentLoaded({ content, actions }): Promise<void> {
logger.info(`[${PluginName}] contentLoaded called`);
await initDocs(specPath, outputDir);
/*
if (!(await fs.stat(specPath)).isFile()) {
throw new Error(`OpenRPC spec file not found: ${specPath}`);
}

try {
const entries = await fs.readdir(outputDir, { withFileTypes: true });
await Promise.all(
entries
.filter((entry) => entry.name !== "index.md")
.map((entry) => {
const fullPath = `${outputDir}/${entry.name}`;
return fs.rm(fullPath, { recursive: true, force: true });
}),
);
} catch {
// Directory doesn't exist yet, that's fine
}

try {
await generateDocs(specPath, outputDir);
} catch (err) {
logger.error(`[${PluginName}] generateDocs failed: ${err}`);
logger.error(
`[${PluginName}] Stack: ${err instanceof Error ? err.stack : "no stack"}`,
);
throw err;
}
// Return content to be used in contentLoaded

// const { addRoute, setGlobalData } = actions;

// TODO: Create routes using addRoute() for generated markdown pages
// TODO: Set global data using setGlobalData() if needed
// Example:
// addRoute({
// path: '/api',
// component: '@theme/DocPage',
// exact: false,
// });
*/
await initDocs(specPath, outputDir, normalizedOptions);
},

/**
Expand Down
20 changes: 14 additions & 6 deletions packages/docusaurus-plugin/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { promises as fs } from "fs";
import * as path from "path";
import { OpenRPCMdContent } from "@open-rpc/markdown-generator";
import { MethodObjectParamStructure } from "@open-rpc/meta-schema";
import { Options, PluginOptions } from "./options";

type JSONSchema = any;

Expand Down Expand Up @@ -57,7 +58,11 @@ methodEdits.editMethod = (content, method) => {
] as OpenRPCMdContent[];
};

export async function generateDocs(inputPath: string, outputPath: string) {
export async function generateDocs(
inputPath: string,
outputPath: string,
options: PluginOptions,
) {
const raw = await fs.readFile(inputPath, "utf8");
const doc: DereffedOpenrpcDocument = (await parseOpenRPCDocument(
raw,
Expand All @@ -81,11 +86,14 @@ export async function generateDocs(inputPath: string, outputPath: string) {
);
}

await fs.writeFile(
path.join(outDir, "index.md"),
renderIndex(doc, "mdx"),
"utf8",
);
// NOTE a little hacky, but good for now
const indexContent = renderIndex(doc, "mdx");
const finalIndex =
options.showPoweredBy === true
? `${indexContent}\n---\n\n*Powered by [OpenRPC](https://open-rpc.org)*\n`
: indexContent;

await fs.writeFile(path.join(outDir, "index.md"), finalIndex, "utf8");
}

/* ---------- Renderers ---------- */
Expand Down
3 changes: 3 additions & 0 deletions packages/docusaurus-plugin/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type Options = {

openRPCSpecPath: string;
docOutputPath: string;
showPoweredBy: boolean;
};

/**
Expand All @@ -22,5 +23,7 @@ export function normalizeOptions(options: Options): PluginOptions {
return {
openRPCSpecPath: options.openRPCSpecPath || "./openrpc.json",
docOutputPath: options.docOutputPath || "./api-reference",
showPoweredBy:
options.showPoweredBy === undefined ? true : options.showPoweredBy,
};
}
4 changes: 4 additions & 0 deletions packages/example-site/docs/api-reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ A specification of the standard interface for Ethereum clients.
- [`eth_simulateV1`](./methods/eth_simulateV1.mdx)
- [`eth_syncing`](./methods/eth_syncing.mdx)
- [`eth_uninstallFilter`](./methods/eth_uninstallFilter.mdx)

---

*Powered by [OpenRPC](https://open-rpc.org)*
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"debug_getBadBlocks\",\n \"params\": [],\n \"id\": 1\n}"} />}>
# debug\_getBadBlocks
# debug_getBadBlocks



Expand Down Expand Up @@ -1360,7 +1360,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
debug\_getBadBlocks example
debug_getBadBlocks example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"debug_getRawBlock\",\n \"params\": [\n \"0x32026E\"\n ],\n \"id\": 1\n}"} />}>
# debug\_getRawBlock
# debug_getRawBlock



Expand Down Expand Up @@ -74,7 +74,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
debug\_getRawBlock example
debug_getRawBlock example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"debug_getRawHeader\",\n \"params\": [\n \"0x32026E\"\n ],\n \"id\": 1\n}"} />}>
# debug\_getRawHeader
# debug_getRawHeader



Expand Down Expand Up @@ -74,7 +74,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
debug\_getRawHeader example
debug_getRawHeader example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"debug_getRawReceipts\",\n \"params\": [\n \"0x32026E\"\n ],\n \"id\": 1\n}"} />}>
# debug\_getRawReceipts
# debug_getRawReceipts



Expand Down Expand Up @@ -74,7 +74,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
debug\_getRawReceipts example
debug_getRawReceipts example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"debug_getRawTransaction\",\n \"params\": [\n \"0x3a2fd1a5ea9ffee477f449be53a49398533d2c006a5815023920d1c397298df3\"\n ],\n \"id\": 1\n}"} />}>
# debug\_getRawTransaction
# debug_getRawTransaction



Expand All @@ -36,7 +36,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
debug\_getRawTransaction example
debug_getRawTransaction example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_exchangeCapabilities\",\n \"params\": [\n [\n \"engine_exchangeTransitionConfigurationV1\",\n \"engine_forkchoiceUpdatedV1\",\n \"engine_getPayloadBodiesByHashV1\",\n \"engine_getPayloadBodiesByRangeV1\",\n \"engine_getPayloadV1\",\n \"engine_newPayloadV1\"\n ]\n ],\n \"id\": 1\n}"} />}>
# engine\_exchangeCapabilities
# engine_exchangeCapabilities



Expand All @@ -32,7 +32,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_exchangeCapabilities example
engine_exchangeCapabilities example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_exchangeTransitionConfigurationV1\",\n \"params\": [\n {\n \"terminalTotalDifficulty\": 0,\n \"terminalBlockHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n \"terminalBlockNumber\": \"0x1\"\n }\n ],\n \"id\": 1\n}"} />}>
# engine\_exchangeTransitionConfigurationV1
# engine_exchangeTransitionConfigurationV1



Expand Down Expand Up @@ -112,7 +112,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_exchangeTransitionConfigurationV1 example
engine_exchangeTransitionConfigurationV1 example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_forkchoiceUpdatedV1\",\n \"params\": [\n {\n \"headBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"safeBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"finalizedBlockHash\": \"0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a\"\n },\n {\n \"timestamp\": \"0x5\",\n \"prevRandao\": \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n \"suggestedFeeRecipient\": \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\"\n }\n ],\n \"id\": 1\n}"} />}>
# engine\_forkchoiceUpdatedV1
# engine_forkchoiceUpdatedV1



Expand Down Expand Up @@ -210,7 +210,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_forkchoiceUpdatedV1 example
engine_forkchoiceUpdatedV1 example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_forkchoiceUpdatedV2\",\n \"params\": [\n {\n \"headBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"safeBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"finalizedBlockHash\": \"0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a\"\n },\n {\n \"timestamp\": \"0x64e7785b\",\n \"prevRandao\": \"0xc130d5e63c61c935f6089e61140ca9136172677cf6aa5800dcc1cf0a02152a14\",\n \"suggestedFeeRecipient\": \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\",\n \"withdrawals\": [\n {\n \"index\": \"0xf0\",\n \"validatorIndex\": \"0xf0\",\n \"address\": \"0x00000000000000000000000000000000000010f0\",\n \"amount\": \"0x1\"\n },\n {\n \"index\": \"0xf1\",\n \"validatorIndex\": \"0xf1\",\n \"address\": \"0x00000000000000000000000000000000000010f1\",\n \"amount\": \"0x1\"\n }\n ]\n }\n ],\n \"id\": 1\n}"} />}>
# engine\_forkchoiceUpdatedV2
# engine_forkchoiceUpdatedV2



Expand Down Expand Up @@ -262,7 +262,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_forkchoiceUpdatedV2 example
engine_forkchoiceUpdatedV2 example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_forkchoiceUpdatedV3\",\n \"params\": [\n {\n \"headBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"safeBlockHash\": \"0x3559e851470f6e7bbed1db474980683e8c315bfce99b2a6ef47c057c04de7858\",\n \"finalizedBlockHash\": \"0x3b8fb240d288781d4aac94d3fd16809ee413bc99294a085798a589dae51ddd4a\"\n },\n {\n \"timestamp\": \"0x64e7785b\",\n \"prevRandao\": \"0xc130d5e63c61c935f6089e61140ca9136172677cf6aa5800dcc1cf0a02152a14\",\n \"suggestedFeeRecipient\": \"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b\",\n \"withdrawals\": [\n {\n \"index\": \"0xf0\",\n \"validatorIndex\": \"0xf0\",\n \"address\": \"0x00000000000000000000000000000000000010f0\",\n \"amount\": \"0x1\"\n },\n {\n \"index\": \"0xf1\",\n \"validatorIndex\": \"0xf1\",\n \"address\": \"0x00000000000000000000000000000000000010f1\",\n \"amount\": \"0x1\"\n }\n ],\n \"parentBeaconBlockRoot\": \"0x11f780a954bcba8889998e4e61deaae6388dd2391e9c810bd9c94962cc1eadc1\"\n }\n ],\n \"id\": 1\n}"} />}>
# engine\_forkchoiceUpdatedV3
# engine_forkchoiceUpdatedV3



Expand Down Expand Up @@ -296,7 +296,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_forkchoiceUpdatedV3 example
engine_forkchoiceUpdatedV3 example
</summary>

#### Request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TwoColumnLayout, InteractiveRequest, ResponseExample} from '@open-rpc/do
import { useState } from 'react';

<TwoColumnLayout sidebar={<InteractiveRequest request={"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"engine_getBlobsV1\",\n \"params\": [\n [\n \"0x000657f37554c781402a22917dee2f75def7ab966d7b770905398eba3c444014\"\n ]\n ],\n \"id\": 1\n}"} />}>
# engine\_getBlobsV1
# engine_getBlobsV1



Expand Down Expand Up @@ -96,7 +96,7 @@ import { useState } from 'react';
<div>
<details>
<summary>
engine\_getBlobsV1 example
engine_getBlobsV1 example
</summary>

#### Request
Expand Down
Loading
Loading