feat: skip save if no article
This commit is contained in:
parent
6c3cff1b66
commit
3b6e6c36b1
2 changed files with 20 additions and 7 deletions
|
@ -1,27 +1,30 @@
|
||||||
---
|
---
|
||||||
export interface Props {
|
export interface Props {
|
||||||
postDivSelector: string
|
postDivSelector: string,
|
||||||
|
skipSave?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const {postDivSelector} = Astro.props;
|
const {postDivSelector, skipSave = false} = Astro.props;
|
||||||
---
|
---
|
||||||
<div id="library">
|
<div id="library">
|
||||||
<ul id="post-list"></ul>
|
<ul id="post-list"></ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input value={postDivSelector} name="postDivSelector" id="postDivSelector" hidden />
|
<input value={postDivSelector} name="postDivSelector" id="postDivSelector" hidden />
|
||||||
|
<input type="checkbox" id="skipSave" name="skipSave" checked={skipSave} hidden />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const cache = await caches.open('cozy-reader');
|
const cache = await caches.open('cozy-reader');
|
||||||
const url = new URL(window.location.href);
|
const url = new URL(window.location.href);
|
||||||
const response = await cache.match(url)
|
const response = await cache.match(url)
|
||||||
if (!response) {
|
const postDivSelector = document.getElementById('postDivSelector') as HTMLInputElement;
|
||||||
|
const skipSave = document.getElementById('skipSave') as HTMLInputElement;
|
||||||
|
const postDiv = document.querySelector(postDivSelector?.value);
|
||||||
|
|
||||||
|
if (!response && !skipSave.checked) {
|
||||||
await cache.add(url);
|
await cache.add(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
const postDivSelector = document.getElementById('postDivSelector') as HTMLInputElement;
|
|
||||||
const postDiv = document.querySelector(postDivSelector?.value);
|
|
||||||
|
|
||||||
const cachedResponses = await cache.keys();
|
const cachedResponses = await cache.keys();
|
||||||
const list = document.querySelector('#post-list');
|
const list = document.querySelector('#post-list');
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Library from "../components/Library.astro";
|
||||||
const params = Astro.url.searchParams;
|
const params = Astro.url.searchParams;
|
||||||
const url = params.get('url') || '';
|
const url = params.get('url') || '';
|
||||||
let article;
|
let article;
|
||||||
|
let skipSave;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
article = await extract(url);
|
article = await extract(url);
|
||||||
|
@ -18,17 +19,26 @@ try {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!article) {
|
||||||
|
article = {
|
||||||
|
title: "Something is not right",
|
||||||
|
content: "<p>The article extractor did not get any result.</p>",
|
||||||
|
}
|
||||||
|
skipSave = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (url === '') {
|
if (url === '') {
|
||||||
article = {
|
article = {
|
||||||
title: "Welcome to Cozy 🧸",
|
title: "Welcome to Cozy 🧸",
|
||||||
author: "Ayo Ayco",
|
author: "Ayo Ayco",
|
||||||
content: "<p>Enter a URL in the address bar above to get started.</p>",
|
content: "<p>Enter a URL in the address bar above to get started.</p>",
|
||||||
};
|
};
|
||||||
|
skipSave = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
<Layout title={url !== "" ? article?.title : "Your modern-day reading assistant"}>
|
<Layout title={url !== "" ? article?.title : "Your modern-day reading assistant"}>
|
||||||
<AddressBar slot="address-bar" url={url} />
|
<AddressBar slot="address-bar" url={url} />
|
||||||
<Post slot="post" article={article} />
|
<Post slot="post" article={article} />
|
||||||
<Library slot="library" postDivSelector="#post" />
|
<Library skipSave={skipSave} slot="library" postDivSelector="#post" />
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
Loading…
Reference in a new issue