fix: make sure to cache index

This commit is contained in:
Ayo 2023-06-14 22:54:19 +02:00
parent b2541606e4
commit 42f0bc859b
4 changed files with 11 additions and 8 deletions

View file

@ -9,7 +9,7 @@ const placeholder = 'Type the URL of an article here';
<div class="address-bar">
<form>
<button aria-label="Home" title="Home" class="left-button" type="button" id="app-home" name="app-home" onclick="history.back();" hidden>
<button aria-label="Home" title="Home" class="left-button" type="button" id="app-home" name="app-home" onclick="history.go(-1); return false;" hidden>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M17.51 3.87L15.73 2.1L5.84 12l9.9 9.9l1.77-1.77L9.38 12l8.13-8.13z"/></svg>
</button>
<input type="text" id="app-url" name="url" value={url} placeholder={placeholder} />

View file

@ -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);
});
});
}
</script>

View file

@ -32,6 +32,7 @@ if (url === '') {
content: "<p>Enter a URL above to get started.</p>",
url: '/'
};
skipSave = false;
}
---

View file

@ -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);