Skip to content

Commit

Permalink
Make new page show up in menu
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Sep 4, 2023
1 parent a5b0cee commit facc29f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const handbookPages = [
{ file: "topics/Time and Timers.md" },
{ file: "topics/Composing Reactors.md" },
{ file: "topics/Reactions and Methods.md" },
{ file: "topics/Reaction Declarations.md" },
{ file: "topics/Causality Loops.md" },
{ file: "topics/Extending Reactors.md" },
{ file: "topics/Actions.md" },
Expand Down
64 changes: 32 additions & 32 deletions packages/lingua-franca/src/lib/documentationNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
*/

export interface SidebarNavItem {
title: string
id: string
permalink?: string
chronological?: boolean
oneline?: string
items?: SidebarNavItem[]
title: string;
id: string;
permalink?: string;
chronological?: boolean;
oneline?: string;
items?: SidebarNavItem[];
}

/** ---INSERT--- */

export function getDocumentationNavForLanguage(
langRequest: string
): SidebarNavItem[] {
const langs = ["en"]
const lang = langs.includes(langRequest) ? langRequest : "en"
const navigations: Record<string, SidebarNavItem[]> = {}
const langs = ["en"];
const lang = langs.includes(langRequest) ? langRequest : "en";
const navigations: Record<string, SidebarNavItem[]> = {};

navigations.en = [
{
Expand Down Expand Up @@ -310,9 +310,9 @@ export function getDocumentationNavForLanguage(
},
],
},
]
];

return navigations[lang]
return navigations[lang];
}

/** ---INSERT-END--- */
Expand All @@ -323,40 +323,40 @@ const findInNav = (
): SidebarNavItem | undefined => {
if (Array.isArray(item)) {
for (const subItem of item) {
const sub = findInNav(subItem, fun)
if (sub) return sub
const sub = findInNav(subItem, fun);
if (sub) return sub;
}
} else {
if (fun(item)) return item
if (!item.items) return undefined
if (fun(item)) return item;
if (!item.items) return undefined;
for (const subItem of item.items) {
const sub = findInNav(subItem, fun)
if (sub) return sub
const sub = findInNav(subItem, fun);
if (sub) return sub;
}
return undefined
return undefined;
}
}
};

export function getNextPageID(navs: SidebarNavItem[], currentID: string) {
// prettier-ignore
const section = findInNav(navs, (i) => i && !!i.items && !!i.items.find(i => i.id === currentID)) || false
if (!section) return undefined
if (!section.chronological) return undefined
if (!section.items) return
if (!section) return undefined;
if (!section.chronological) return undefined;
if (!section.items) return;

const currentIndex = section.items.findIndex(i => i.id === currentID)
const next = section.items[currentIndex + 1]
const currentIndex = section.items.findIndex((i) => i.id === currentID);
const next = section.items[currentIndex + 1];
if (next) {
if (next.items) {
return {
path: next.items[0].permalink,
...section.items[currentIndex + 1],
}
};
} else {
return {
path: next.permalink,
...section.items[currentIndex + 1],
}
};
}
}
}
Expand All @@ -365,17 +365,17 @@ export function getPreviousPageID(navs: SidebarNavItem[], currentID: string) {
// prettier-ignore
const section = findInNav(navs, (i) => i && !!i.items && !!i.items.find(i => i.id === currentID)) || false

if (!section) return undefined
if (!section.chronological) return undefined
if (!section.items) return
if (!section) return undefined;
if (!section.chronological) return undefined;
if (!section.items) return;

const currentIndex = section.items.findIndex(i => i.id === currentID)
const prev = section.items[currentIndex - 1]
const currentIndex = section.items.findIndex((i) => i.id === currentID);
const prev = section.items[currentIndex - 1];

if (prev) {
return {
path: prev.permalink,
...section.items[currentIndex - 1],
}
};
}
}

0 comments on commit facc29f

Please sign in to comment.