Skip to content

Commit 5622de0

Browse files
committed
feat(docs): changed sidebar labels to the right ones
1 parent cfc5fb5 commit 5622de0

File tree

5 files changed

+96
-21
lines changed

5 files changed

+96
-21
lines changed

docusaurus.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
require("dotenv").config();
55
const { fetchAndGenerateSidebarItems } = require("./src/helpers/index.ts");
6-
const capitalize = require("lodash.capitalize");
6+
const upperFirst = require("lodash.upperfirst");
77
const { themes } = require("prism-react-renderer");
88
const codeTheme = themes.dracula;
99
const remarkCodesandbox = require("remark-codesandbox");
@@ -134,7 +134,7 @@ const config = {
134134
const dynamicSidebarItems = await fetchAndGenerateSidebarItems(networkName);
135135
config.customFields.dynamicData = dynamicSidebarItems;
136136
const updatedItems = sidebarItems.map(item => {
137-
if (item?.label === capitalize(networkName) && item?.items) {
137+
if (item?.label === upperFirst(networkName) && item?.items) {
138138
item.items = [...item.items, ...dynamicSidebarItems]
139139
}
140140
return item;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
"dotenv": "^16.4.5",
4949
"js-cookie": "^3.0.5",
5050
"launchdarkly-js-client-sdk": "^3.3.0",
51-
"lodash.capitalize": "^4.2.1",
5251
"lodash.debounce": "^4.0.8",
5352
"lodash.isobject": "^3.0.2",
53+
"lodash.upperfirst": "^4.3.1",
5454
"node-polyfill-webpack-plugin": "^2.0.1",
5555
"prettier": "^3.0.0",
5656
"prism-react-renderer": "^2.1.0",

src/lib/constants.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,3 +456,70 @@ export enum NETWORK_NAMES {
456456
linea = "linea",
457457
metamask = "metamask",
458458
}
459+
460+
export const lineaSidebarNames = [
461+
{
462+
old: "get-started",
463+
new: "Get Started"
464+
},
465+
{
466+
old: "how-to",
467+
new: "How to"
468+
},
469+
{
470+
old: "use-ipfs",
471+
new: "Use IPFS"
472+
},
473+
{
474+
old: "access-ipfs-content",
475+
new: "Access IPFS content"
476+
},
477+
{
478+
old: "send-a-transaction",
479+
new: "Send transactions"
480+
},
481+
{
482+
old: "use-infura-as-a-reverse-proxy",
483+
new: "Use Infura as a reverse proxy"
484+
},
485+
{
486+
old: "layer-2-networks",
487+
new: "Layer 2 networks"
488+
},
489+
{
490+
old: "json-rpc-methods",
491+
new: "JSON-RPC APIs"
492+
},
493+
{
494+
old: "avalanche-c-chain",
495+
new: "Avalanche (C-Chain)"
496+
},
497+
{
498+
old: "bnb-smart-chain",
499+
new: "BNB Smart Chain"
500+
},
501+
{
502+
old: "gas-api",
503+
new: "Gas API"
504+
},
505+
{
506+
old: "ipfs",
507+
new: "IPFS"
508+
},
509+
{
510+
old: "opbnb",
511+
new: "opBNB"
512+
},
513+
{
514+
old: "polygon-pos",
515+
new: "Polygon PoS"
516+
},
517+
{
518+
old: "zksync",
519+
new: "ZKsync Era"
520+
},
521+
{
522+
old: "http-api-methods",
523+
new: "HTTP API methods"
524+
},
525+
]

src/pages/CustomPage/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ import React, { useEffect, useState } from "react";
55
import DocSidebar from '@theme/DocSidebar';
66
import styles from "@site/src/theme/Layout/styles.module.css"
77
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
8-
import * as capitalize from "lodash.capitalize"
8+
import * as upperFirst from "lodash.upperfirst"
9+
import { lineaSidebarNames } from "@site/src/lib/constants";
10+
11+
const formatMenuLabel = (label) => {
12+
const menuItem = lineaSidebarNames.find(name => name.old === label);
13+
if (menuItem) {
14+
return menuItem.new;
15+
}
16+
return label;
17+
}
918

1019
function generateSidebarItems(docs) {
1120
const categories = {};
@@ -15,22 +24,21 @@ function generateSidebarItems(docs) {
1524
categories['Introduction'] = {
1625
type: 'link',
1726
href: '/services',
18-
label: capitalize(doc.frontMatter?.sidebar_label || doc.title),
27+
label: upperFirst(doc.frontMatter?.sidebar_label || doc.title),
1928
};
2029
return;
2130
}
2231

2332
const pathParts = doc.sourceDirName.split('/');
2433
let currentCategory = categories;
2534
let isIndexPage = doc.id.endsWith('/index');
26-
27-
pathParts.forEach((part, index) => {
35+
pathParts.map(pathPart => formatMenuLabel(pathPart)).forEach((part, index) => {
2836
if (!currentCategory[part]) {
2937
if (isIndexPage && index === pathParts.length - 2) {
3038
currentCategory[part] = {
3139
type: 'category',
32-
label: capitalize(doc.frontMatter?.sidebar_label || doc.frontMatter?.title || part),
33-
collapsed: true,
40+
label: upperFirst(doc.frontMatter?.sidebar_label || doc.frontMatter?.title || part),
41+
collapsed: false,
3442
collapsible: true,
3543
link: {
3644
type: 'generated-index',
@@ -41,8 +49,8 @@ function generateSidebarItems(docs) {
4149
} else {
4250
currentCategory[part] = {
4351
type: 'category',
44-
label: capitalize(part),
45-
collapsed: true,
52+
label: upperFirst(part),
53+
collapsed: part !== "get-started",
4654
collapsible: true,
4755
items: []
4856
};
@@ -52,7 +60,7 @@ function generateSidebarItems(docs) {
5260
if (index === pathParts.length - 1 && !isIndexPage) {
5361
currentCategory[part].items.push({
5462
type: 'link',
55-
label: capitalize(doc.frontMatter?.title || doc.title),
63+
label: doc.frontMatter?.title || doc.title,
5664
href: `/services/${doc.id.replace(/\/index$/, '')}`,
5765
sidebar_position: doc.frontMatter?.sidebar_position || Number.MAX_SAFE_INTEGER
5866
});
@@ -88,7 +96,7 @@ const CustomPage = (props) => {
8896
return {
8997
...item,
9098
items: item.items.map(referenceItem => {
91-
if (referenceItem?.label === capitalize(NETWORK_NAMES.linea) && referenceItem?.items) {
99+
if (referenceItem?.label === upperFirst(NETWORK_NAMES.linea) && referenceItem?.items) {
92100
return { ...referenceItem, items: [...referenceItem.items, ...siteConfig.customFields.dynamicData] };
93101
}
94102
return referenceItem;

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12569,13 +12569,6 @@ __metadata:
1256912569
languageName: node
1257012570
linkType: hard
1257112571

12572-
"lodash.capitalize@npm:^4.2.1":
12573-
version: 4.2.1
12574-
resolution: "lodash.capitalize@npm:4.2.1"
12575-
checksum: d9195f31d48c105206f1099946d8bbc8ab71435bc1c8708296992a31a992bb901baf120fdcadd773098ac96e62a79e6b023ee7d26a2deb0d6c6aada930e6ad0a
12576-
languageName: node
12577-
linkType: hard
12578-
1257912572
"lodash.debounce@npm:^4.0.8":
1258012573
version: 4.0.8
1258112574
resolution: "lodash.debounce@npm:4.0.8"
@@ -12618,6 +12611,13 @@ __metadata:
1261812611
languageName: node
1261912612
linkType: hard
1262012613

12614+
"lodash.upperfirst@npm:^4.3.1":
12615+
version: 4.3.1
12616+
resolution: "lodash.upperfirst@npm:4.3.1"
12617+
checksum: cadec6955900afe1928cc60cdc4923a79c2ef991e42665419cc81630ed9b4f952a1093b222e0141ab31cbc4dba549f97ec28ff67929d71e01861c97188a5fa83
12618+
languageName: node
12619+
linkType: hard
12620+
1262112621
"lodash@npm:^4.17.12, lodash@npm:^4.17.15, lodash@npm:^4.17.19, lodash@npm:^4.17.20, lodash@npm:^4.17.21, lodash@npm:^4.17.4, lodash@npm:^4.17.5":
1262212622
version: 4.17.21
1262312623
resolution: "lodash@npm:4.17.21"
@@ -13463,9 +13463,9 @@ __metadata:
1346313463
eslint-plugin-react: ^7.34.2
1346413464
js-cookie: ^3.0.5
1346513465
launchdarkly-js-client-sdk: ^3.3.0
13466-
lodash.capitalize: ^4.2.1
1346713466
lodash.debounce: ^4.0.8
1346813467
lodash.isobject: ^3.0.2
13468+
lodash.upperfirst: ^4.3.1
1346913469
node-polyfill-webpack-plugin: ^2.0.1
1347013470
prettier: ^3.0.0
1347113471
prism-react-renderer: ^2.1.0

0 commit comments

Comments
 (0)