fix navigation

This commit is contained in:
liquidex 2023-09-05 13:51:43 +02:00
parent f7cfb52504
commit f8ca16a50d

View file

@ -125,12 +125,15 @@ function expandDetailsRecursively(element) {
}
function navigateToPage(page) {
window.location.href = `${TREEHOUSE_SITE}/${page}.html`
console.log(page);
window.location.pathname = `${TREEHOUSE_SITE}/${page}.html`
}
async function navigateToBranch(fragment) {
if (fragment.length == 0) return;
console.log(`nagivating to branch: ${fragment}`);
let element = document.getElementById(fragment);
if (element !== null) {
// If the element is already loaded on the page, we're good.
@ -138,6 +141,7 @@ async function navigateToBranch(fragment) {
rehash();
} else {
// The element is not loaded, we need to load the tree that has it.
console.log("element is not loaded");
let parts = fragment.split(':');
if (parts.length >= 2) {
let [page, _id] = parts;
@ -147,8 +151,12 @@ async function navigateToBranch(fragment) {
// navigation maps with roots other than index. Currently though only index is
// generated so that doesn't matter.
let [_root, ...path] = fullPath;
console.log(`_root: ${_root}, path: ${path}`)
if (path !== undefined) {
let isNotAtIndexHtml = window.location.pathname != "/index.html";
let isNotAtIndexHtml =
window.location.pathname != "" &&
window.location.pathname != "/" &&
window.location.pathname != "/index.html";
let lastBranch = null;
for (let linked of path) {
let branch = LinkedBranch.byLink.get(linked);