Refactor PWA caching and image generation scripts

- Updated `generate-pwa-cache-list.js` to include images directory and remove duplicate file entries.
- Refactored `generate-svg-variants.js` to utilize collections from a centralized source and renamed generation directory variable.
- Modified `update-data.js` to align with new directory structure for images and variants, ensuring proper paths are used.
- Adjusted `collections.js` to standardize directory naming for variants.
- Enhanced Svelte components (`Actions.svelte`, `CardFull.svelte`, `CardMiddle.svelte`, `CardSmall.svelte`, `CardTiny.svelte`) to utilize context for collection management, simplifying image URL generation.
This commit is contained in:
sha
2025-06-18 13:18:15 +03:00
parent d7feb6db19
commit 4a32deaeb5
12 changed files with 108 additions and 1622 deletions
+11 -10
View File
@@ -1,5 +1,5 @@
<script>
import { onMount } from "svelte";
import { onMount, getContext } from "svelte";
import InlineSvg from "./InlineSvg.svelte";
import Actions from "./Actions.svelte";
import ColorSwitcher from "./ColorSwitcher.svelte";
@@ -129,18 +129,19 @@
return str.charAt(0).toUpperCase() + str.slice(1);
}
function getCollectionByPath(path) {
return collections.find(col => path.startsWith(col.baseDir.replace('images/', '')) || path.startsWith(col.baseDir));
}
function getBaseDir(logo) {
const collection = getCollectionByPath(logo.path);
return collection ? collection.baseDir : 'images/logos';
// Use the current collection context for baseDir
let collection = getContext('collection');
if (!collection) {
// fallback: try to infer from window.appData
if (typeof window !== 'undefined' && window.appData && window.appData.collection) {
collection = collections.find(c => c.name === window.appData.collection) || collections[0];
} else {
collection = collections[0];
}
}
function getImageUrl(logo) {
const baseDir = getBaseDir(logo);
return `/${baseDir}/${logo.path.split('/').pop()}`;
return `/${collection.baseDir}/${logo.path}`;
}
</script>