From: Ardis Lu Date: Sun, 6 Mar 2022 06:58:05 +0000 (-0800) Subject: Include forward slash in path names X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=79b5e3086d9d3dbcf278ae0799a677cf62777984;p=ardislu.dev Include forward slash in path names Backend is also updated to include forward slash to match --- diff --git a/script.js b/script.js index f40489c..81801e2 100644 --- a/script.js +++ b/script.js @@ -96,7 +96,7 @@ async function showPage(path) { document.body.innerHTML = ''; // Determine which placeholders to show - if (path === 'home' || path === '') { + if (path === '/home' || path === '/') { document.body.appendChild(homeHeader); document.body.appendChild(homeLoader); } @@ -110,13 +110,13 @@ async function showPage(path) { await fetchPostMetadata(); } - if (path === 'home' || path === '') { + if (path === '/home' || path === '/') { document.title = 'ardislu.dev'; homeMain.innerHTML = ''; for (const [path, post] of posts) { homeMain.insertAdjacentHTML('beforeend', `
-

${post.title}

${post.description}

${post.linkText}

+

${post.title}

${post.description}

${post.linkText}

`); } homeLoader.remove(); @@ -163,11 +163,11 @@ function route(href) { } window.history.pushState({}, '', url); - showPage(url.pathname.substring(1)); + showPage(url.pathname); } /* Set event handlers for client-side routing */ -window.addEventListener('popstate', _ => showPage(window.location.pathname.substring(1))); +window.addEventListener('popstate', _ => showPage(window.location.pathname)); document.addEventListener('click', e => { e.preventDefault(); const anchor = e.target.closest('a'); @@ -178,7 +178,7 @@ document.addEventListener('click', e => { }); // Show the current URL (to support direct linking aka deep links) -showPage(window.location.pathname.substring(1)); +showPage(window.location.pathname); /* Set grid-row-end for each card on homeMain resize. Required to implement masonry layout. */ new ResizeObserver(_ => {