From d0e1a37f7c731a13432abbfb3fc67b5ff1a0d76d Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Tue, 16 Aug 2022 20:43:03 -0700 Subject: [PATCH] Build home component regardless of path Fixes bug where home is undefined when users search after opening an article direct link --- script.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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); -- 2.47.3