Skip to content

Commit

Permalink
feat(docs): optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
aednikanov committed Sep 20, 2024
1 parent 095aff6 commit 1adab32
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
21 changes: 15 additions & 6 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Note: type annotations allow type checking and IDEs autocompletion

require("dotenv").config();
const { fetchAndGenerateSidebarItems } = require("./src/helpers/index.ts");
const { fetchAndGenerateSidebarItems } = require("./src/helpers");
import { NETWORK_NAMES } from "./src/lib/constants.ts";
const upperFirst = require("lodash.upperfirst");
const { themes } = require("prism-react-renderer");
const codeTheme = themes.dracula;
Expand Down Expand Up @@ -130,15 +131,23 @@ const config = {
sidebarItemsGenerator: async function ({ defaultSidebarItemsGenerator, ...args }) {
config.customFields.sidebarData = args;
let sidebarItems = await defaultSidebarItemsGenerator(args);
const networkName = "linea";
const dynamicSidebarItems = await fetchAndGenerateSidebarItems(networkName);
const dynamicSidebarItems = await fetchAndGenerateSidebarItems(NETWORK_NAMES.linea);
config.customFields.dynamicData = dynamicSidebarItems;
const updatedItems = sidebarItems.map(item => {
if (item?.label === upperFirst(networkName) && item?.items) {
item.items = [...item.items, ...dynamicSidebarItems]
if (item?.label === upperFirst(NETWORK_NAMES.linea) && item?.items) {
return { ...item, items: [...item.items, ...dynamicSidebarItems.map(dynamicItem => {
const jsonRpcCategory = item.items.find(({ label }) => label === 'JSON-RPC methods');
if (jsonRpcCategory) {
return {
...dynamicItem,
...{ items: [...dynamicItem.items, ...jsonRpcCategory.items.filter(refItem => refItem.type === "category")] }
};
}
return dynamicItem;
})]};
}
return item;
})
});
return [...updatedItems];
},
},
Expand Down
5 changes: 2 additions & 3 deletions src/components/CustomReferencePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import Layout from "@theme/Layout";
import { NETWORK_NAMES } from "@site/src/plugins/plugin-json-rpc";
import ParserOpenRPC from "@site/src/components/ParserOpenRPC";
import React, { useEffect, useState } from "react";
import DocSidebar from '@theme/DocSidebar';
import styles from "@site/src/theme/Layout/styles.module.css"
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import * as upperFirst from "lodash.upperfirst"
import { lineaSidebarNames } from "@site/src/lib/constants";
import upperFirst from "lodash.upperfirst"
import { lineaSidebarNames, NETWORK_NAMES } from "@site/src/lib/constants";

const formatMenuLabel = (label) => {
const menuItem = lineaSidebarNames.find(name => name.old === label);
Expand Down
7 changes: 1 addition & 6 deletions src/plugins/plugin-json-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
export const RPC_NETWORK_URL = "https://sot-network-methods.vercel.app/specs";

export enum NETWORK_NAMES {
linea = "linea",
metamask = "metamask",
}
import { NETWORK_NAMES, RPC_NETWORK_URL } from "../lib/constants.ts";

export interface ResponseItem {
name: string;
Expand Down

0 comments on commit 1adab32

Please sign in to comment.