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: Guides nav update #426

Merged
merged 13 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
2 changes: 1 addition & 1 deletion scripts/generate-links/getDocs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export async function getDocs(key, order) {
case 'guides':
paths = [
// GUIDES
'./guides/docs/**/*.mdx'
'./guides/docs/**/*.mdx',
];
break;
case 'intro':
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-links/getSortedLinks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ function handleSubmenu(
];

return {
slug,
subpath,
label: thisCategory,
isExternal,
Expand Down
26 changes: 12 additions & 14 deletions scripts/generate-links/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,15 @@ 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.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) => {
Expand All @@ -49,10 +43,10 @@ async function main() {
fs.mkdirSync(folderPath, { recursive: true });
}
fs.writeFileSync(`${folderPath}/${key}.json`, json, 'utf-8');
if (!key.includes('guides') && key !== 'contributing') {
if (key !== 'contributing') {
if (
key.includes('nightly') ||
['intro', 'contributing'].includes(key)
['guides', 'intro', 'contributing'].includes(key)
) {
const cleanKey = key.replace('nightly-', '');
allNightlyOrders.push({
Expand Down Expand Up @@ -106,6 +100,9 @@ function getSidebarName(key) {
case 'migrations-and-disclosures':
newKey = 'Migrations & Disclosures';
break;
case 'guides':
newKey = 'Guides';
break;
default:
}

Expand All @@ -116,6 +113,7 @@ function handleAllOrders(allOrders, folderPath, filename) {
const correctOrder = [
'migrations-and-disclosures',
'intro',
'guides',
'sway',
'sway-libs',
'sway-standards',
Expand Down
17 changes: 15 additions & 2 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,26 @@ export function Sidebar({
{allNavs && (
<>
{/* DOCS */}

{allNavs.map((navOrder) => {
const catIndex = versionSet === 'default' ? 1 : 2;
let key = navOrder.links[0].slug.split('/')[catIndex];
console.log('nav', navOrder);
calldelegation marked this conversation as resolved.
Show resolved Hide resolved

let slug = navOrder.links[0]?.slug;

if (!slug && navOrder.links[0]?.submenu?.[0]?.slug) {
slug = navOrder.links[0].submenu[0].slug;
}

if (!slug) {
console.warn(`No slug found for navOrder.key: ${navOrder.key}`);
return null;
}

let key = slug.split('/')[catIndex];
if (key === 'sway') {
key = 'forc';
}

return (
<Box key={navOrder.key}>
<SidebarSection
Expand Down
21 changes: 12 additions & 9 deletions src/components/SidebarSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -91,22 +94,22 @@ export function SidebarSection({
<Box.VStack gap='0' css={styles.sectionContainer}>
{/* biome-ignore lint/suspicious/noExplicitAny: */}
{links.map((link: any, index: number) => {
if (link.slug) {
if (link.submenu) {
return (
<SidebarLink
<SidebarSubmenu
key={link.submenu[0].slug}
onClick={onClick}
key={link.slug}
item={link}
isIndex={index === 0 && bookHasIndex}
{...link}
/>
);
}
if (link.submenu) {
if (link.slug) {
return (
<SidebarSubmenu
key={link.submenu[0].slug}
<SidebarLink
onClick={onClick}
{...link}
key={link.slug}
item={link}
isIndex={index === 0 && bookHasIndex}
/>
);
}
Expand Down
6 changes: 1 addition & 5 deletions src/lib/getActiveNav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ export function getActiveNav(
doc?: DocType
) {
let navs = undefined;
if (
!doc ||
(!doc.originalSlug.includes('guides') &&
!doc.originalSlug.includes('docs/contributing'))
) {
if (!doc || !doc.originalSlug.includes('docs/contributing')) {
if (versionSet === 'nightly') {
navs = allNightlyNavs;
} else {
Expand Down
14 changes: 11 additions & 3 deletions src/lib/md-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -212,9 +213,16 @@ 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, '_');

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[];
}
Expand Down
Loading