From: Ardis Lu Date: Wed, 17 Aug 2022 03:43:03 +0000 (-0700) Subject: Build home component regardless of path X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=d0e1a37f7c731a13432abbfb3fc67b5ff1a0d76d;p=ardislu.dev Build home component regardless of path Fixes bug where home is undefined when users search after opening an article direct link --- diff --git a/script.js b/script.js index 4e75917..0e9792c 100644 --- a/script.js +++ b/script.js @@ -201,6 +201,7 @@ async function showPage(path) { if (globalThis.metadata.size === 0) { globalThis.metadata = await fetchPostMetadata(); globalThis.flexIndex = buildFlexIndex(globalThis.metadata); + globalThis.components.set('home', buildHomeComponent(globalThis.metadata)); } if (path === '/home' || path === '/') { @@ -211,9 +212,7 @@ async function showPage(path) { editUrl: 'https://docs.google.com/spreadsheets/d/1pfGF8yBu3D0GPTezygLuzu3Cif8SkjhtG98nL-czlhc/edit' }); - const homeComponent = buildHomeComponent(globalThis.metadata); - globalThis.components.set('home', homeComponent); - document.querySelector('main').replaceWith(homeComponent); + document.querySelector('main').replaceWith(globalThis.components.get('home')); } else if (globalThis.metadata.has(path)) { const post = globalThis.metadata.get(path);