From 42f0bc859baba5d0696bc350d0f76a4ac2d9df60 Mon Sep 17 00:00:00 2001 From: Ayo Date: Wed, 14 Jun 2023 22:54:19 +0200 Subject: [PATCH] fix: make sure to cache index --- src/components/AddressBar.astro | 2 +- src/components/Library.astro | 14 +++++++------- src/pages/index.astro | 1 + src/utils/library.ts | 2 ++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/AddressBar.astro b/src/components/AddressBar.astro index d4b8887..fc54336 100644 --- a/src/components/AddressBar.astro +++ b/src/components/AddressBar.astro @@ -9,7 +9,7 @@ const placeholder = 'Type the URL of an article here';
- diff --git a/src/components/Library.astro b/src/components/Library.astro index ceb1fad..09af494 100644 --- a/src/components/Library.astro +++ b/src/components/Library.astro @@ -75,19 +75,19 @@ const {postDivSelector, skipSave = false} = Astro.props; }); }); - window.onpopstate = async (data) => { + window.addEventListener('popstate', async (data) => { let url = data.state?.url; if (!url) { url = window.location.href; } - const fullResponse = await cache.match(url) - fullResponse?.text().then(data => { - const responseText = data; - renderPost(responseText, url, postDivSelector?.value, true); - }); - } + const fullResponse = await cache.match(url) + fullResponse?.text().then(data => { + const responseText = data; + renderPost(responseText, url, postDivSelector?.value, true); + }); + }); } diff --git a/src/pages/index.astro b/src/pages/index.astro index 9559143..a7008c5 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -32,6 +32,7 @@ if (url === '') { content: "

Enter a URL above to get started.

", url: '/' }; + skipSave = false; } --- diff --git a/src/utils/library.ts b/src/utils/library.ts index 57cf3ed..8903eb9 100644 --- a/src/utils/library.ts +++ b/src/utils/library.ts @@ -77,6 +77,8 @@ export function renderPost(responseText, url, postDivSelector: string, preventPu const cozyUrl = html.querySelector('meta[property="cozy:url"]')?.getAttribute('content'); if(cozyUrl !== '/') { appUrl.value = cozyUrl || ''; + } else { + appUrl.value = ''; } if(!preventPushState) { window.history.pushState({url}, '', url);