Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
3b5bf08541 | |||
a8b77eca65 | |||
e79a6b29fc | |||
29a29e4d63 | |||
343568042c | |||
f80807eebd | |||
f755588f58 | |||
410f43166c |
5 changed files with 50 additions and 14 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,6 +2,7 @@
|
|||
dist/
|
||||
.output/
|
||||
.astro/
|
||||
.continue/
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
|
|
@ -47,7 +47,7 @@ export const footerLinks: Link[] = [
|
|||
},
|
||||
{
|
||||
text: 'SourceHut',
|
||||
url: 'https://ayco.io/sh/',
|
||||
url: 'https://sr.ht/~ayoayco',
|
||||
icon: 'sourcehut',
|
||||
},
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import Layout from '../layouts/Layout.astro'
|
||||
import Card from '../components/Card.astro'
|
||||
import Footer from '../components/Footer.astro'
|
||||
import now from '../constants/now.json'
|
||||
// import now from '../constants/now.json'
|
||||
---
|
||||
|
||||
<Layout>
|
||||
|
@ -29,11 +29,11 @@ import now from '../constants/now.json'
|
|||
<h1 title="Ayo Ayco | Software Engineer + Web Developer">
|
||||
Hi, I'm <span class="heavy-text">Ayo</span>!
|
||||
</h1>
|
||||
<!-- <a href="https://forms.ayo.run/form/tnz7FybY" class="now-wrapper"> -->
|
||||
<a href="/now" class="now-wrapper">
|
||||
<!--a href="https://forms.ayo.run/form/tnz7FybY" class="now-wrapper"-->
|
||||
<!--a href="/now" class="now-wrapper">
|
||||
<span class="now-label">now</span>
|
||||
<span class="status">{now.title}</span>
|
||||
</a>
|
||||
</a-->
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
@ -16,6 +16,12 @@ import Card from '../components/Card.astro'
|
|||
>.
|
||||
</p>
|
||||
<ul>
|
||||
<Card
|
||||
newTab
|
||||
href="https://git.ayo.run/ayo/simple-tts#readme"
|
||||
title="Simple TTS"
|
||||
body="A simple machine learning text-to-speech program for the terminal"
|
||||
/>
|
||||
<Card
|
||||
newTab
|
||||
href="https://mcfly.js.org"
|
||||
|
|
47
src/sw.mjs
47
src/sw.mjs
|
@ -6,17 +6,39 @@
|
|||
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
|
||||
const forceLogging = true
|
||||
|
||||
/**
|
||||
* Cleans up old service worker caches by deleting any cache that doesn't match the current cache name.
|
||||
* This ensures only the current version of the application's cache is retained.
|
||||
* @async
|
||||
* @function cleanOldCaches
|
||||
* @returns {Promise<void>} A promise that resolves when old caches have been deleted
|
||||
*/
|
||||
const cleanOldCaches = async () => {
|
||||
const allowCacheNames = [cacheName]
|
||||
const allCaches = await caches.keys()
|
||||
allCaches.forEach((key) => {
|
||||
if (!allowCacheNames.includes(key)) {
|
||||
console.info('Deleting old cache', key)
|
||||
caches.delete(key)
|
||||
caches
|
||||
.delete(key)
|
||||
.then(() => {
|
||||
console.info('Successfully deleted cache:', key)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('Failed to delete old cache:', key, error)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds specified resources to the service worker cache.
|
||||
* This function is used to cache static assets for offline access.
|
||||
* @async
|
||||
* @function addResourcesToCache
|
||||
* @param {Array<string>} resources - An array of URLs representing the resources to be cached.
|
||||
* @returns {Promise<void>} A promise that resolves when all resources have been successfully added to the cache.
|
||||
*/
|
||||
const addResourcesToCache = async (resources) => {
|
||||
const cache = await caches.open(cacheName)
|
||||
console.info('adding resources to cache...', {
|
||||
|
@ -34,6 +56,14 @@ const addResourcesToCache = async (resources) => {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts a response in the cache.
|
||||
* @async
|
||||
* @function putInCache
|
||||
* @param {Request} request - The request to be cached.
|
||||
* @param {Response} response - The response to be cached.
|
||||
* @returns {Promise<void>} A promise that resolves when the response has been added to the cache.
|
||||
*/
|
||||
const putInCache = async (request, response) => {
|
||||
const cache = await caches.open(cacheName)
|
||||
|
||||
|
@ -49,9 +79,6 @@ const networkFirst = async ({ request, fallbackUrl }) => {
|
|||
try {
|
||||
// Try to get the resource from the network for 5 seconds
|
||||
const responseFromNetwork = await fetch(request.clone())
|
||||
// response may be used only once
|
||||
// we need to save clone to put one copy in cache
|
||||
// and serve second one
|
||||
putInCache(request, responseFromNetwork.clone())
|
||||
console.info('using network response', responseFromNetwork.url)
|
||||
return responseFromNetwork
|
||||
|
@ -64,11 +91,13 @@ const networkFirst = async ({ request, fallbackUrl }) => {
|
|||
return responseFromCache
|
||||
}
|
||||
|
||||
// Try the fallback
|
||||
const fallbackResponse = await cache.match(fallbackUrl)
|
||||
if (fallbackResponse) {
|
||||
console.info('using fallback cached response...', fallbackResponse.url)
|
||||
return fallbackResponse
|
||||
// If fallback is provided, try to use it, otherwise return error
|
||||
if (fallbackUrl) {
|
||||
const fallbackResponse = await cache.match(fallbackUrl)
|
||||
if (fallbackResponse) {
|
||||
console.info('using fallback cached response...', fallbackResponse.url)
|
||||
return fallbackResponse
|
||||
}
|
||||
}
|
||||
|
||||
// when even the fallback response is not available,
|
||||
|
|
Loading…
Reference in a new issue