Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Render proto files #21090

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
init
  • Loading branch information
ronny-mysten committed Feb 5, 2025
commit 284d92732726fc7ab80b721a444e967c65e2a35d
10 changes: 10 additions & 0 deletions docs/content/references/fullnode-protocol.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: Full Node Protocol
description: The Full node protocol API is available on all Sui Full nodes.
---

import Protocol from "../../site/src/components/Protocol";

The Full node protocol ...

<Protocol />
1 change: 1 addition & 0 deletions docs/content/sidebars/references.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const references = [
'references/cli/validator',
],
},
'references/fullnode-protocol',
{
type: 'category',
label: 'Sui IDE Support',
Expand Down
1 change: 1 addition & 0 deletions docs/site/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const config = {
path.resolve(__dirname, `./src/plugins/descriptions`),
path.resolve(__dirname, `./src/plugins/framework`),
path.resolve(__dirname, `./src/plugins/askcookbook`),
path.resolve(__dirname, `./src/plugins/protocol`),
],
presets: [
[
Expand Down
90 changes: 90 additions & 0 deletions docs/site/src/components/Protocol/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import React, { useState, useEffect } from "react";

export default function Protocol(props) {
const { toc } = props;
const [proto, setProto] = useState(toc[0]);
const [messages, setMessages] = useState(toc[0].messages);
const [belowFold, setBelowFold] = useState(false);
const triggerY = 140;

useEffect(() => {
const handleScroll = () => {
if (window.scrollY >= triggerY) {
setBelowFold(true);
} else {
setBelowFold(false);
}
};

window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);

if (!toc) {
return;
}

const handleProtoChange = (e) => {
const selected = e.target.value;
const selectedProto = toc[selected]; // Get the selected protocol
setProto(selectedProto);
setMessages(selectedProto.messages);
window.location.hash = `#${selectedProto.link}`;
};
const handleMessageChange = (e) => {
const selected = e.target.value;
const message = proto.messages.filter((item) => {
return item.name === selected;
});
const hash = message[0].link;
window.location.hash = `#${hash}`;
};

return (
<div
className={`max-xl:hidden sticky top-16 py-4 -mx-4 z-10 backdrop-blur-sm border-sui-ghost-white dark:border-sui-ghost-dark ${belowFold ? "border-solid border-x-0 border-t-0 border-b" : ""}`}
>
<style>
{`
h2, h3 {
scroll-margin:126px !important;
}
`}
</style>
<label
className="m-2 text-xs bg-sui-white rounded-lg backdrop-blur-none"
htmlFor="proto"
>
Proto files
</label>
<select id="proto" className="p-2 w-[200px]" onChange={handleProtoChange}>
{toc.map((item, i) => {
return (
<option key={i} value={i}>
{item.name}
</option>
);
})}
</select>
<label className="mx-2 text-xs" htmlFor="messages">
Messages
</label>
<select
id="messages"
className="p-2 w-[200px]"
onChange={handleMessageChange}
>
{messages.map((message) => {
return (
<option key={message.name} value={message.name}>
{message.name}
</option>
);
})}
</select>
</div>
);
}
18 changes: 5 additions & 13 deletions docs/site/src/plugins/framework/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ const BRIDGE_PATH = path.join(
);
const FRAMEWORK_PATH = path.join(
__dirname,
"../../../../../crates/sui-framework/docs/sui",
"../../../../../crates/sui-framework/docs/sui-framework",
);
const STDLIB_PATH = path.join(
__dirname,
"../../../../../crates/sui-framework/docs/std",
"../../../../../crates/sui-framework/docs/move-stdlib",
);
const DEEPBOOK_PATH = path.join(
__dirname,
"../../../../../crates/sui-framework/docs/deepbook",
);
const SUISYS_PATH = path.join(
__dirname,
"../../../../../crates/sui-framework/docs/sui_system",
"../../../../../crates/sui-framework/docs/sui-system",
);
const DOCS_PATH = path.join(
__dirname,
Expand Down Expand Up @@ -86,22 +86,14 @@ const frameworkPlugin = (context, options) => {
// Remove code blocks without pre's. Render automatically adds
// pre element that messes up formatting.
// Remove empty code blocks because it looks lame.
// Replace named anchor tags for titles with id'd title.
// Replace remaining named anchor tags with ids and scroll margin
// inline. Necessary for mdx to process correctly.
let reMarkdown = markdown
.replace(/<a\s+(.*?)\.md(.*?)>/g, `<a $1$2>`)
.replace(
/(title: .*)Module `(.*::)(.*)`/g,
/(title: .*)Module `(0x[1-9a-f]{1,4}::)(.*)`/g,
`$1 Module $2$3\nsidebar_label: $3`,
)
.replace(/(?<!<pre>)<code>(.*?)<\/code>/gs, `$1`)
.replace(/<pre><code><\/code><\/pre>/g, "")
.replace(
/<a name="([^"]+)"><\/a>\n\n(#+) (.+) `([^`]+)`/g,
`$2 $3 \`$4\` {#$1}`,
)
.replace(/<a name=/g, "<a style='scroll-margin-top:80px' id=");
.replace(/<pre><code><\/code><\/pre>/g, "");
const filename = file.replace(/.*\/docs\/(.*)$/, `$1`);
const parts = filename.split("/");
const fileWrite = path.join(DOCS_PATH, filename);
Expand Down
43 changes: 43 additions & 0 deletions docs/site/src/plugins/protocol/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

// Plugin copies file from crates and creates fullnode doc

import path from "path";
import fs from "fs";
//import Protocol from "@site/src/components/Protocol";

const PROTOCOL_PATH = path.join(
__dirname,
"../../../../../crates/sui-rpc-api/proto/documentation.json",
);
const MDX_FILENAME = "fullnode-protocol";
const MDX_TEST = new RegExp(`${MDX_FILENAME}\\.mdx$`);
const SPEC_MD = fs.readFileSync(PROTOCOL_PATH, "utf-8");

const fullnodeProtocolPlugin = (context, options) => {
return {
name: "sui-fullnode-protocol-plugin",
configureWebpack() {
return {
module: {
rules: [
{
test: MDX_TEST,
use: [
{
loader: path.resolve(__dirname, "./protocolLoader-json.js"),
options: {
protocolSpec: SPEC_MD,
},
},
],
},
],
},
};
},
};
};

module.exports = fullnodeProtocolPlugin;
Loading