Compare commits

..

No commits in common. "main" and "v1.3.0" have entirely different histories.
main ... v1.3.0

5 changed files with 14 additions and 50 deletions

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
dist/ dist/
.output/ .output/
.astro/ .astro/
.continue/
# dependencies # dependencies
node_modules/ node_modules/

View file

@ -47,7 +47,7 @@ export const footerLinks: Link[] = [
}, },
{ {
text: 'SourceHut', text: 'SourceHut',
url: 'https://sr.ht/~ayoayco', url: 'https://ayco.io/sh/',
icon: 'sourcehut', icon: 'sourcehut',
}, },
{ {

View file

@ -2,7 +2,7 @@
import Layout from '../layouts/Layout.astro' import Layout from '../layouts/Layout.astro'
import Card from '../components/Card.astro' import Card from '../components/Card.astro'
import Footer from '../components/Footer.astro' import Footer from '../components/Footer.astro'
// import now from '../constants/now.json' import now from '../constants/now.json'
--- ---
<Layout> <Layout>
@ -29,11 +29,11 @@ import Footer from '../components/Footer.astro'
<h1 title="Ayo Ayco | Software Engineer + Web Developer"> <h1 title="Ayo Ayco | Software Engineer + Web Developer">
Hi, I'm <span class="heavy-text">Ayo</span>! Hi, I'm <span class="heavy-text">Ayo</span>!
</h1> </h1>
<!--a href="https://forms.ayo.run/form/tnz7FybY" class="now-wrapper"--> <!-- <a href="https://forms.ayo.run/form/tnz7FybY" class="now-wrapper"> -->
<!--a href="/now" class="now-wrapper"> <a href="/now" class="now-wrapper">
<span class="now-label">now</span> <span class="now-label">now</span>
<span class="status">{now.title}</span> <span class="status">{now.title}</span>
</a--> </a>
</div> </div>
</div> </div>
</section> </section>

View file

@ -16,12 +16,6 @@ import Card from '../components/Card.astro'
>. >.
</p> </p>
<ul> <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 <Card
newTab newTab
href="https://mcfly.js.org" href="https://mcfly.js.org"

View file

@ -6,39 +6,17 @@
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}` const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
const forceLogging = true 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 cleanOldCaches = async () => {
const allowCacheNames = [cacheName] const allowCacheNames = [cacheName]
const allCaches = await caches.keys() const allCaches = await caches.keys()
allCaches.forEach((key) => { allCaches.forEach((key) => {
if (!allowCacheNames.includes(key)) { if (!allowCacheNames.includes(key)) {
console.info('Deleting old cache', key) console.info('Deleting old cache', key)
caches caches.delete(key)
.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 addResourcesToCache = async (resources) => {
const cache = await caches.open(cacheName) const cache = await caches.open(cacheName)
console.info('adding resources to cache...', { console.info('adding resources to cache...', {
@ -56,14 +34,6 @@ 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 putInCache = async (request, response) => {
const cache = await caches.open(cacheName) const cache = await caches.open(cacheName)
@ -79,6 +49,9 @@ const networkFirst = async ({ request, fallbackUrl }) => {
try { try {
// Try to get the resource from the network for 5 seconds // Try to get the resource from the network for 5 seconds
const responseFromNetwork = await fetch(request.clone()) 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()) putInCache(request, responseFromNetwork.clone())
console.info('using network response', responseFromNetwork.url) console.info('using network response', responseFromNetwork.url)
return responseFromNetwork return responseFromNetwork
@ -91,14 +64,12 @@ const networkFirst = async ({ request, fallbackUrl }) => {
return responseFromCache return responseFromCache
} }
// If fallback is provided, try to use it, otherwise return error // Try the fallback
if (fallbackUrl) {
const fallbackResponse = await cache.match(fallbackUrl) const fallbackResponse = await cache.match(fallbackUrl)
if (fallbackResponse) { if (fallbackResponse) {
console.info('using fallback cached response...', fallbackResponse.url) console.info('using fallback cached response...', fallbackResponse.url)
return fallbackResponse return fallbackResponse
} }
}
// when even the fallback response is not available, // when even the fallback response is not available,
// there is nothing we can do, but we must always // there is nothing we can do, but we must always