From 0cc131dc6edc4a57d24080b57f35c745db78de43 Mon Sep 17 00:00:00 2001 From: Call Delegation <106365423+calldelegation@users.noreply.github.com> Date: Sat, 14 Sep 2024 16:40:03 -0400 Subject: [PATCH] ready to compare --- docs/guides/docs/guides.json | 35 +++++++++++++++++------ docs/guides/docs/nav.json | 19 ++++++++---- scripts/generate-links/getDocs.mjs | 6 ++++ scripts/generate-links/getSortedLinks.mjs | 2 ++ scripts/generate-links/index.mjs | 33 ++++++++++++--------- src/components/Sidebar.tsx | 1 + src/components/SidebarSection.tsx | 3 ++ src/lib/md-doc.ts | 20 ++++++++++--- 8 files changed, 88 insertions(+), 31 deletions(-) diff --git a/docs/guides/docs/guides.json b/docs/guides/docs/guides.json index c645661ff..6813d0ac0 100644 --- a/docs/guides/docs/guides.json +++ b/docs/guides/docs/guides.json @@ -3,42 +3,61 @@ "title": "Predicates 101: Building Stateless DeFi Applications", "description": "Learn about predicates by building a MultiSig", "featured": true, - "tags": ["Full Stack"] + "tags": [ + "Full Stack" + ] }, "intro_to_sway": { "title": "Introduction to Sway for JavaScript developers", "description": "Learn Sway fundamentals by building a marketplace React dApp.", "featured": true, - "tags": ["Full Stack", "React"] + "tags": [ + "Full Stack", + "React" + ] }, "contract-quickstart": { "title": "Smart Contract Quickstart", "description": "Get started by generating a counter contract in Sway.", "featured": false, - "tags": ["Getting Started"] + "tags": [ + "Getting Started" + ] }, "frontend-quickstart": { "title": "Next.js Fullstack Quickstart", "description": "Get started by generating a full-stack counter dapp on Fuel.", "featured": false, - "tags": ["Getting Started", "Full Stack", "Next.js"] + "tags": [ + "Getting Started", + "Full Stack", + "Next.js" + ] }, "counter-dapp": { "title": "Counter React Dapp", "description": "Step-by-step guide to build a counter dApp on Fuel", "featured": false, - "tags": ["Getting Started", "Full Stack", "React"] + "tags": [ + "Getting Started", + "Full Stack", + "React" + ] }, "running_a_node": { "title": "Running a Node", "description": "Run a local Fuel node.", "featured": false, - "tags": ["fuel-core"] + "tags": [ + "fuel-core" + ] }, "installation": { "title": "Toolchain Installation", "description": "Install the Fuel toolchain and binaries.", "featured": false, - "tags": ["Getting Started"] + "tags": [ + "Getting Started" + ] } -} +} \ No newline at end of file diff --git a/docs/guides/docs/nav.json b/docs/guides/docs/nav.json index 55c7930ab..6213d867a 100644 --- a/docs/guides/docs/nav.json +++ b/docs/guides/docs/nav.json @@ -5,13 +5,22 @@ "Counter Dapp", "Running a Node", "Installation", - "Intro to Sway" + "Intro to Sway", + "Intro to Predicates" + ], + "installation": [ + "Fuel Github Codespace" + ], + "counter-dapp": [ + "Building a Smart Contract", + "Building a Frontend" ], - "installation": ["Fuel Github Codespace"], - "counter-dapp": ["Building a Smart Contract", "Building a Frontend"], "contract-quickstart": [], "frontend-quickstart": [], - "running_a_node": ["Running a Local Node", "Running a Testnet Node"], + "running_a_node": [ + "Running a Local Node", + "Running a Testnet Node" + ], "intro_to_sway": [ "Introduction to Sway", "Prerequisites", @@ -40,4 +49,4 @@ "Logging in Rust tests", "Rust Testing" ] -} +} \ No newline at end of file diff --git a/scripts/generate-links/getDocs.mjs b/scripts/generate-links/getDocs.mjs index de993f47e..f1a488665 100644 --- a/scripts/generate-links/getDocs.mjs +++ b/scripts/generate-links/getDocs.mjs @@ -200,6 +200,12 @@ export async function getDocs(key, order) { './guides/docs/**/*.mdx' ]; break; + case 'nightly-guides': + paths = [ + // GUIDES + './guides/docs/**/*.mdx' + ]; + break; case 'intro': paths = [ // INTRO diff --git a/scripts/generate-links/getSortedLinks.mjs b/scripts/generate-links/getSortedLinks.mjs index 430b66fc1..9a87612a4 100644 --- a/scripts/generate-links/getSortedLinks.mjs +++ b/scripts/generate-links/getSortedLinks.mjs @@ -343,7 +343,9 @@ function handleSubmenu( }, ]; + console.log(title, slug); return { + slug, subpath, label: thisCategory, isExternal, diff --git a/scripts/generate-links/index.mjs b/scripts/generate-links/index.mjs index c9767af05..92c5530d8 100644 --- a/scripts/generate-links/index.mjs +++ b/scripts/generate-links/index.mjs @@ -20,21 +20,21 @@ async function main() { const final = slugs.map(({ slug }) => getDocBySlug(slug, slugs)); let sortedLinks = getSortedLinks(orders[key], final); - if (key === 'intro') { - sortedLinks.push({ - slug: '/guides', - label: 'Guides', - isExternal: false, - }); - } + // if (key === 'guides') { + // sortedLinks.push({ + // slug: '/guides', + // label: 'Guides', + // isExternal: false, + // }); + // } if (key.includes('guides')) { - const newLinks = {}; - sortedLinks.forEach((link) => { - newLinks[ - link.label.toLowerCase().replaceAll(' ', '_').replaceAll('-', '_') - ] = link; + sortedLinks = sortedLinks.map((link) => { + link.key = link.label + .toLowerCase() + .replaceAll(' ', '_') + .replaceAll('-', '_'); + return link; }); - sortedLinks = newLinks; } if (Array.isArray(sortedLinks)) { sortedLinks = sortedLinks.map((link) => { @@ -49,7 +49,8 @@ async function main() { fs.mkdirSync(folderPath, { recursive: true }); } fs.writeFileSync(`${folderPath}/${key}.json`, json, 'utf-8'); - if (!key.includes('guides') && key !== 'contributing') { + // if (!key.includes('guides') && key !== 'contributing') { + if (key !== 'contributing') { if ( key.includes('nightly') || ['intro', 'contributing'].includes(key) @@ -106,6 +107,9 @@ function getSidebarName(key) { case 'migrations-and-disclosures': newKey = 'Migrations & Disclosures'; break; + case 'guides': + newKey = 'Guides'; + break; default: } @@ -116,6 +120,7 @@ function handleAllOrders(allOrders, folderPath, filename) { const correctOrder = [ 'migrations-and-disclosures', 'intro', + 'guides', 'sway', 'sway-libs', 'sway-standards', diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 05bc5870e..e3a6ba487 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -62,6 +62,7 @@ export function Sidebar({ {allNavs.map((navOrder) => { const catIndex = versionSet === 'default' ? 1 : 2; + // console.log("hello", navOrder.links) let key = navOrder.links[0].slug.split('/')[catIndex]; if (key === 'sway') { key = 'forc'; diff --git a/src/components/SidebarSection.tsx b/src/components/SidebarSection.tsx index be0218df9..0e7e8b3a7 100644 --- a/src/components/SidebarSection.tsx +++ b/src/components/SidebarSection.tsx @@ -58,6 +58,9 @@ export function SidebarSection({ case 'Migrations-and-disclosures': githubLink = 'https://github.com/FuelLabs/migrations-and-disclosures'; break; + case 'Guides': + githubLink = 'https://github.com/FuelLabs/docs-hub'; + break; default: break; } diff --git a/src/lib/md-doc.ts b/src/lib/md-doc.ts index d4d4565a1..e862d2c6f 100644 --- a/src/lib/md-doc.ts +++ b/src/lib/md-doc.ts @@ -71,6 +71,7 @@ export class Doc { .replace('docs/sway/', '') .replace('docs/sway-standards/', '') .replace('docs/sway-by-example-lib/', '') + .replace('docs/guides/', '') .replace('docs/fuel-specs/', '')}`; let pageLink = `${config.repository}${actualPath.replace( @@ -201,6 +202,7 @@ export class Doc { `../src/generated/sidebar-links/${configSlug}.json` ); const links = JSON.parse(readFileSync(linksPath, 'utf8')); + if ( (configSlug === 'guides' || configSlug === 'nightly-guides') && guideName @@ -212,9 +214,17 @@ export class Doc { .replace(`${guideName}/`, '') .replace('/index', ''); - const key = slug.split('/')[0].replaceAll('-', '_'); - const guideLinks = [links[key]]; - return guideLinks as SidebarLinkItem[]; + const key = slug.split('/')[0].replace(/-/g, '_'); + + // Updated code: Find the link with matching key + const guideLink = links.find((link) => link.key === key); + + if (guideLink && guideLink.submenu) { + return guideLink.submenu as SidebarLinkItem[]; + } else { + console.warn(`No guide link found for key: ${key}`); + return []; + } } return links as SidebarLinkItem[]; } @@ -222,7 +232,9 @@ export class Doc { get navLinks() { const slug = this.#parseSlug(this.item.originalSlug); const links = this.sidebarLinks(this.item.originalSlug); - + console.log(slug); + console.log(links); + console.log(this.item); const result = []; for (const link of links) { if (link.submenu) {