feat(cozy): revalidate cached article
This commit is contained in:
parent
8d95361e88
commit
ed2364ebe8
1 changed files with 10 additions and 5 deletions
|
@ -12,7 +12,7 @@ export interface Props {
|
||||||
<Serialize id="preferences" data={{...Astro.props}} />
|
<Serialize id="preferences" data={{...Astro.props}} />
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {deserialize} from '@ayco/astro-resume';
|
import { deserialize } from '@ayco/astro-resume';
|
||||||
import type { Props } from './Library.astro';
|
import type { Props } from './Library.astro';
|
||||||
import type { AppConfig } from '../pages/index.astro';
|
import type { AppConfig } from '../pages/index.astro';
|
||||||
import { getPostCard, renderPost } from '../utils/library'
|
import { getPostCard, renderPost } from '../utils/library'
|
||||||
|
@ -24,14 +24,19 @@ export interface Props {
|
||||||
if (urlParam) {
|
if (urlParam) {
|
||||||
url = new URL(`${url.origin}/?url=${urlParam}`);
|
url = new URL(`${url.origin}/?url=${urlParam}`);
|
||||||
}
|
}
|
||||||
const response = await cache.match(url);
|
|
||||||
const { skipSave } = deserialize<Props>('preferences');
|
const { skipSave } = deserialize<Props>('preferences');
|
||||||
const { routerOutlet } = deserialize<AppConfig>('app-config');
|
const { routerOutlet } = deserialize<AppConfig>('app-config');
|
||||||
const includesAppURL = urlParam?.includes(window.location.origin)
|
const includesAppURL = urlParam?.includes(window.location.origin)
|
||||||
|
|
||||||
if (!response && !skipSave && !includesAppURL) {
|
try {
|
||||||
await cache.add(url);
|
const responseFromNetwork = await fetch (url);
|
||||||
}
|
if (responseFromNetwork && !skipSave && !includesAppURL) {
|
||||||
|
console.info('[cozy-reader]: adding one to cache', url.pathname)
|
||||||
|
await cache.put(url, responseFromNetwork);
|
||||||
|
}
|
||||||
|
} catch(error) {
|
||||||
|
console.error('[cozy-reader]: ', error)
|
||||||
|
}
|
||||||
|
|
||||||
const cachedRequests = (await cache.keys())
|
const cachedRequests = (await cache.keys())
|
||||||
.filter(request => {
|
.filter(request => {
|
||||||
|
|
Loading…
Reference in a new issue