Skip to content

Commit

Permalink
feat(docs): added new custom field
Browse files Browse the repository at this point in the history
  • Loading branch information
aednikanov committed Sep 18, 2024
1 parent b7ab9f5 commit 21ac68c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
2 changes: 2 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const config = {
customFields: {
LD_CLIENT_ID: process.env.LD_CLIENT_ID,
sidebarData: {},
dynamicData: []
},

trailingSlash: true,
Expand Down Expand Up @@ -130,6 +131,7 @@ const config = {
let sidebarItems = await defaultSidebarItemsGenerator(args);
const networkName = "linea";
const dynamicSidebarItems = await fetchAndGenerateSidebarItems(networkName);
config.customFields.dynamicData = dynamicSidebarItems;
const updatedItems = sidebarItems.map(item => {
if (item?.label === capitalize(networkName) && item?.items) {
item.items = [...item.items, ...dynamicSidebarItems]
Expand Down
31 changes: 13 additions & 18 deletions src/pages/CustomPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 { fetchAndGenerateSidebarItems } from "@site/src/helpers";
import * as capitalize from "lodash.capitalize"

function generateSidebarItems(docs) {
Expand Down Expand Up @@ -84,24 +83,20 @@ const CustomPage = (props) => {
const [formattedData, setFormattedData] = useState([]);

useEffect(() => {
fetchAndGenerateSidebarItems(NETWORK_NAMES.linea).then(generatedItems => {
console.log("generatedItems", generatedItems);
console.log("generatedSidebarItems)", generateSidebarItems(siteConfig.customFields.sidebarData.docs));
setFormattedData(generateSidebarItems(siteConfig.customFields.sidebarData.docs).map(item => {
if (item?.label === "Reference" && item?.items) {
return {
...item,
items: item.items.map(referenceItem => {
if (referenceItem?.label === capitalize(NETWORK_NAMES.linea) && referenceItem?.items) {
return { ...referenceItem, items: [...referenceItem.items, ...generatedItems] };
}
return referenceItem;
})
}
setFormattedData(generateSidebarItems(siteConfig.customFields.sidebarData.docs).map(item => {
if (item?.label === "Reference" && item?.items) {
return {
...item,
items: item.items.map(referenceItem => {
if (referenceItem?.label === capitalize(NETWORK_NAMES.linea) && referenceItem?.items) {
return { ...referenceItem, items: [...referenceItem.items, ...siteConfig.customFields.dynamicData] };
}
return referenceItem;
})
}
return item;
}));
});
}
return item;
}));
}, []);

return formattedData ? (
Expand Down

0 comments on commit 21ac68c

Please sign in to comment.