fix: prevent history mess (#70)
* chore: add favicon * fix: home article url * fix: prevent duplicated history entry (unencoded & encoded) * fix: prevent own app * remove console.log * fix: prevent showing cached cozy
This commit is contained in:
parent
98b538396b
commit
34e32abe51
7 changed files with 27 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
||||||
<h1 align="center"><s>Cozy 🧸</s> Uh, we need a new name! See why <a href="https://social.ayco.io/@ayo/110547172702258070">here</a></h1>
|
<h1 align="center"><s>Cozy</s> Uh, we need a new name! See why <a href="https://social.ayco.io/@ayo/110547172702258070">here</a></h1>
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/ayoayco/cozy">
|
<a href="https://github.com/ayoayco/cozy">
|
||||||
<img alt="Last Commit" src="https://img.shields.io/github/last-commit/ayoayco/cozy?logo=github" />
|
<img alt="Last Commit" src="https://img.shields.io/github/last-commit/ayoayco/cozy?logo=github" />
|
||||||
|
@ -58,6 +58,3 @@ It doesn't exist yet... I'll probably get to creating a browser extension at som
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
Speaking of PRs being welcome, see our [CONTRIBUTING guide](/CONTRIBUTING.md).
|
Speaking of PRs being welcome, see our [CONTRIBUTING guide](/CONTRIBUTING.md).
|
||||||
|
|
||||||
🧸
|
|
||||||
|
|
||||||
|
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -12,6 +12,7 @@ import Icon from 'astro-iconify'
|
||||||
<a href="http://ayos.blog/building-a-cozy-web/">Hand-crafted</a> with <Icon name="line-md:heart" /> by <a href="https://ayo.ayco.io">Ayo Ayco</a>
|
<a href="http://ayos.blog/building-a-cozy-web/">Hand-crafted</a> with <Icon name="line-md:heart" /> by <a href="https://ayo.ayco.io">Ayo Ayco</a>
|
||||||
<br />
|
<br />
|
||||||
<a href="https://github.com/ayoayco/cozy">Star on GitHub to support!</a>
|
<a href="https://github.com/ayoayco/cozy">Star on GitHub to support!</a>
|
||||||
|
<!-- <Icon name="twemoji:blue-circle" /> -->
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="disclaimer">All rights reserved to content owners.</section>
|
<section class="disclaimer">All rights reserved to content owners.</section>
|
||||||
|
|
|
@ -17,19 +17,30 @@ const {routerOutlet, skipSave = false} = Astro.props;
|
||||||
<script>
|
<script>
|
||||||
import { getPostCard, renderPost } from '../utils/library'
|
import { getPostCard, renderPost } from '../utils/library'
|
||||||
const cache = await caches.open('cozy-reader');
|
const cache = await caches.open('cozy-reader');
|
||||||
const url = new URL(window.location.href);
|
let url= new URL(window.location.href);
|
||||||
const response = await cache.match(url)
|
// only cached unencoded url param
|
||||||
|
const urlParam = url.searchParams.get('url')
|
||||||
|
if (urlParam) {
|
||||||
|
url = new URL(`${url.origin}/?url=${urlParam}`);
|
||||||
|
}
|
||||||
|
const response = await cache.match(url);
|
||||||
const postDivSelector = document.querySelector<HTMLInputElement>('#postDivSelector');
|
const postDivSelector = document.querySelector<HTMLInputElement>('#postDivSelector');
|
||||||
const skipSave = document.querySelector<HTMLInputElement>('#skipSave');
|
const skipSave = document.querySelector<HTMLInputElement>('#skipSave');
|
||||||
|
const includesAppURL = urlParam?.includes(window.location.origin)
|
||||||
|
|
||||||
if (!response && !skipSave?.checked) {
|
if (!response && !skipSave?.checked && !includesAppURL) {
|
||||||
await cache.add(url);
|
await cache.add(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedRequests = (await cache.keys())
|
const cachedRequests = (await cache.keys())
|
||||||
.filter(request => {
|
.filter(request => {
|
||||||
const urlObj = new URL(request.url);
|
const urlObj = new URL(request.url);
|
||||||
return urlObj.search !== '' && urlObj.searchParams.get('url') !== '';
|
const urlParam = urlObj.searchParams.get('url');
|
||||||
|
|
||||||
|
return urlObj.search !== ''
|
||||||
|
&& !urlParam?.startsWith(window.location.origin)
|
||||||
|
&& urlParam !== ''
|
||||||
|
&& urlParam !== 'null';
|
||||||
});
|
});
|
||||||
|
|
||||||
if(cachedRequests?.length && postDivSelector !== null) {
|
if(cachedRequests?.length && postDivSelector !== null) {
|
||||||
|
|
|
@ -5,14 +5,9 @@ import Footer from "../components/Footer.astro";
|
||||||
export interface Props {
|
export interface Props {
|
||||||
article: ArticleData | null
|
article: ArticleData | null
|
||||||
}
|
}
|
||||||
const app: ArticleData = {
|
|
||||||
title: "Cozy 🧸",
|
|
||||||
description: "Remove distractions. Save your favorites. Get useful insights. Cozy is your modern-day reading assistant.",
|
|
||||||
content: "<p>Enter a URL in the address bar to get started.</p>",
|
|
||||||
url: '/'
|
|
||||||
};
|
|
||||||
const { article } = Astro.props;
|
const { article } = Astro.props;
|
||||||
const appTitle = article?.title ? `${article.title} | Cozy 🧸` : app.title;
|
const appTitle = article?.title ? `${article.title} | Cozy` : 'Cozy';
|
||||||
---
|
---
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
|
|
@ -7,7 +7,7 @@ import Library from "../components/Library.astro";
|
||||||
import Footer from "../components/Footer.astro";
|
import Footer from "../components/Footer.astro";
|
||||||
|
|
||||||
const url = Astro.url.searchParams.get('url');
|
const url = Astro.url.searchParams.get('url');
|
||||||
let article: ArticleData | null = {};
|
let article: ArticleData | null = {url: '/'};
|
||||||
|
|
||||||
if (url)
|
if (url)
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -65,13 +65,13 @@ export function renderPost(responseText, url, postDivSelector: string, preventPu
|
||||||
backBtn?.removeAttribute('disabled');
|
backBtn?.removeAttribute('disabled');
|
||||||
submitBtn?.removeAttribute('disabled');
|
submitBtn?.removeAttribute('disabled');
|
||||||
homeBtn?.removeAttribute('disabled');
|
homeBtn?.removeAttribute('disabled');
|
||||||
document.title = `${getCozyTitle(html)} | Cozy 🧸`;
|
document.title = `${getCozyTitle(html)} | Cozy`;
|
||||||
} else {
|
} else {
|
||||||
appUrl.value = '';
|
appUrl.value = '';
|
||||||
backBtn?.setAttribute('disabled', 'true');
|
backBtn?.setAttribute('disabled', 'true');
|
||||||
submitBtn?.setAttribute('disabled', 'true');
|
submitBtn?.setAttribute('disabled', 'true');
|
||||||
homeBtn?.setAttribute('disabled', 'true');
|
homeBtn?.setAttribute('disabled', 'true');
|
||||||
document.title = `Cozy 🧸`;
|
document.title = `Cozy`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!preventPushState) {
|
if(!preventPushState) {
|
||||||
|
@ -102,6 +102,9 @@ function getCozyTitle(html: HTMLHtmlElement): string | undefined {
|
||||||
return html.querySelector('meta[property="cozy:title"]')?.getAttribute("content")
|
return html.querySelector('meta[property="cozy:title"]')?.getAttribute("content")
|
||||||
/**
|
/**
|
||||||
* backwards compatibility for stuff before we implemented cozy:meta tags
|
* backwards compatibility for stuff before we implemented cozy:meta tags
|
||||||
|
* REMOVE ON V1 release
|
||||||
*/
|
*/
|
||||||
?? html.querySelector("title")?.innerHTML?.replace("Cozy 🧸 | ", "");
|
?? html.querySelector("title")?.innerHTML
|
||||||
|
?.replace("Cozy 🧸 | ", "")
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue