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 all 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 docs/nightly/fuel-specs
Submodule fuel-specs updated 1 files
+20 −19 src/abi/receipts.md
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;
case 'integration-docs':
newKey = 'Integrations';
break;
Expand All @@ -119,6 +116,7 @@ function handleAllOrders(allOrders, folderPath, filename) {
const correctOrder = [
'migrations-and-disclosures',
'intro',
'guides',
'sway',
'sway-libs',
'sway-standards',
Expand Down
16 changes: 14 additions & 2 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,25 @@ export function Sidebar({
{allNavs && (
<>
{/* DOCS */}

{allNavs.map((navOrder) => {
const catIndex = versionSet === 'default' ? 1 : 2;
let key = navOrder.links[0].slug.split('/')[catIndex];

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
23 changes: 13 additions & 10 deletions src/components/SidebarSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function SidebarSection({
version,
}: SectionProps) {
const [isOpened, setIsOpened] = useState<boolean | undefined>(
book === 'guides' ||
(book.toLowerCase() === 'guides' && docSlug?.includes('guides')) ||
docSlug?.includes(`/${book.toLowerCase()}/`) ||
docSlug === `docs/${book.toLowerCase()}` ||
(book === 'Intro' && !docSlug)
Expand Down 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;
case 'Integration-docs':
githubLink = 'https://github.com/FuelLabs/integration-docs';
break;
Expand Down Expand Up @@ -94,22 +97,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
13 changes: 10 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,15 @@ 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?.submenu) {
return guideLink.submenu as SidebarLinkItem[];
}
console.warn(`No guide link found for key: ${key}`);
return [];
}
return links as SidebarLinkItem[];
}
Expand Down
Loading