mirror of
https://github.com/shadoll/sLogos.git
synced 2026-02-04 02:53:22 +00:00
feat: Implement collection support for logos and flags in the gallery
This commit is contained in:
@@ -3,27 +3,44 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
const LOGOS_DIR = path.join(__dirname, '..', 'public', 'logos');
|
const collections = [
|
||||||
const LOGOS_GEN_DIR = path.join(__dirname, '..', 'public', 'logos_gen');
|
{ name: 'logos', label: 'Logos',
|
||||||
|
baseDir: 'logos',
|
||||||
|
genDir: 'logos_gen',
|
||||||
|
dataFile: 'data/logos.json'
|
||||||
|
},
|
||||||
|
{ name: 'flags', label: 'Flags',
|
||||||
|
baseDir: 'flags',
|
||||||
|
genDir: 'flags_gen',
|
||||||
|
dataFile: 'data/flags.json'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Accept collection as a CLI arg or env var
|
||||||
|
const collectionArg = process.argv.find(arg => arg.startsWith('--collection='));
|
||||||
|
const collectionName = collectionArg ? collectionArg.split('=')[1] : (process.env.COLLECTION || 'logos');
|
||||||
|
const collection = collections.find(c => c.name === collectionName) || collections[0];
|
||||||
|
|
||||||
|
const LOGOS_DIR = path.join(__dirname, '..', 'public', collection.baseDir);
|
||||||
|
const LOGOS_GEN_DIR = path.join(__dirname, '..', 'public', collection.genDir);
|
||||||
|
|
||||||
// Try multiple possible locations for logos.json
|
// Try multiple possible locations for logos.json
|
||||||
const POSSIBLE_LOGOS_JSON_PATHS = [
|
const POSSIBLE_LOGOS_JSON_PATHS = [
|
||||||
path.join(process.cwd(), 'public', 'data', 'logos.json'), // Correct location after scan-logos
|
path.join(process.cwd(), 'public', collection.dataFile),
|
||||||
path.join(__dirname, '..', 'public', 'data', 'logos.json'),
|
path.join(__dirname, '..', 'public', collection.dataFile),
|
||||||
path.join(process.cwd(), 'public', 'logos.json'),
|
path.join(process.cwd(), 'public', collection.baseDir + '.json'),
|
||||||
path.join(__dirname, '..', 'public', 'logos.json'),
|
path.join(__dirname, '..', 'public', collection.baseDir + '.json'),
|
||||||
path.join(__dirname, '..', 'src', 'data', 'logos.json')
|
path.join(__dirname, '..', 'src', 'data', collection.baseDir + '.json')
|
||||||
];
|
];
|
||||||
|
|
||||||
function findLogosJsonPath() {
|
function findLogosJsonPath() {
|
||||||
for (const possiblePath of POSSIBLE_LOGOS_JSON_PATHS) {
|
for (const possiblePath of POSSIBLE_LOGOS_JSON_PATHS) {
|
||||||
if (fs.existsSync(possiblePath)) {
|
if (fs.existsSync(possiblePath)) {
|
||||||
console.log(`📁 Found logos.json at: ${possiblePath}`);
|
console.log(`📁 Found ${collection.dataFile} at: ${possiblePath}`);
|
||||||
return possiblePath;
|
return possiblePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.error(`❌ Could not find ${collection.dataFile} in any of these locations:`);
|
||||||
console.error('❌ Could not find logos.json in any of these locations:');
|
|
||||||
POSSIBLE_LOGOS_JSON_PATHS.forEach(p => console.error(` ${p}`));
|
POSSIBLE_LOGOS_JSON_PATHS.forEach(p => console.error(` ${p}`));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -93,7 +110,7 @@ function applySvgColors(svgContent, colorSet, targets) {
|
|||||||
* Generate SVG variants with color sets
|
* Generate SVG variants with color sets
|
||||||
*/
|
*/
|
||||||
function generateSvgVariants() {
|
function generateSvgVariants() {
|
||||||
console.log('🎨 Generating SVG variants with color sets...');
|
console.log(`🎨 Generating SVG variants with color sets for collection: ${collection.name}...`);
|
||||||
|
|
||||||
// Ensure the logos_gen directory exists
|
// Ensure the logos_gen directory exists
|
||||||
if (!fs.existsSync(LOGOS_GEN_DIR)) {
|
if (!fs.existsSync(LOGOS_GEN_DIR)) {
|
||||||
@@ -106,7 +123,7 @@ function generateSvgVariants() {
|
|||||||
let skippedCount = 0;
|
let skippedCount = 0;
|
||||||
|
|
||||||
if (!Array.isArray(logos)) {
|
if (!Array.isArray(logos)) {
|
||||||
console.error('❌ Expected logos.json to contain an array, got:', typeof logos);
|
console.error('❌ Expected data file to contain an array, got:', typeof logos);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
} console.log(`📊 Processing ${logos.length} logos...`);
|
} console.log(`📊 Processing ${logos.length} logos...`);
|
||||||
|
|
||||||
|
|||||||
@@ -4,19 +4,8 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { Resvg } = require('@resvg/resvg-js');
|
const { Resvg } = require('@resvg/resvg-js');
|
||||||
|
|
||||||
// Configuration
|
// Use collections from src/collections.js
|
||||||
const collections = [
|
const { collections } = require('../src/collections.js');
|
||||||
{ name: 'logos', label: 'Logos',
|
|
||||||
baseDir: 'logos',
|
|
||||||
genDir: 'logos_gen',
|
|
||||||
dataFile: 'data/logos.json'
|
|
||||||
},
|
|
||||||
{ name: 'flags', label: 'Flags',
|
|
||||||
baseDir: 'flags',
|
|
||||||
genDir: 'flags_gen',
|
|
||||||
dataFile: 'data/flags.json'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// Accept collection as a CLI arg or env var
|
// Accept collection as a CLI arg or env var
|
||||||
const collectionArg = process.argv.find(arg => arg.startsWith('--collection='));
|
const collectionArg = process.argv.find(arg => arg.startsWith('--collection='));
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import Router from "svelte-spa-router/Router.svelte";
|
import Router from "svelte-spa-router/Router.svelte";
|
||||||
|
import { collections } from "./collections.js";
|
||||||
|
|
||||||
import Home from "./pages/Home.svelte";
|
import Home from "./pages/Home.svelte";
|
||||||
import Preview from "./pages/Preview.svelte";
|
import Preview from "./pages/Preview.svelte";
|
||||||
@@ -28,6 +29,38 @@
|
|||||||
let selectedLogo = null;
|
let selectedLogo = null;
|
||||||
let compactMode = false;
|
let compactMode = false;
|
||||||
|
|
||||||
|
// --- Collection support ---
|
||||||
|
let collection = localStorage.getItem("collection") || "logos";
|
||||||
|
function setCollection(val) {
|
||||||
|
if (val !== collection) {
|
||||||
|
collection = val;
|
||||||
|
localStorage.setItem("collection", val);
|
||||||
|
loadCollectionData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCollectionData() {
|
||||||
|
// Load the correct data file for the selected collection
|
||||||
|
try {
|
||||||
|
const timestamp = new Date().getTime();
|
||||||
|
const response = await fetch(`data/${collection}.json?t=${timestamp}`);
|
||||||
|
if (response.ok) {
|
||||||
|
logos = await response.json();
|
||||||
|
// Reset filters and state for new collection
|
||||||
|
searchQuery = "";
|
||||||
|
selectedTags = [];
|
||||||
|
selectedBrands = [];
|
||||||
|
selectedVariants = [];
|
||||||
|
tagDropdownOpen = false;
|
||||||
|
compactMode = false;
|
||||||
|
} else {
|
||||||
|
logos = [];
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logos = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setSearchQuery(val) {
|
function setSearchQuery(val) {
|
||||||
searchQuery = val;
|
searchQuery = val;
|
||||||
console.log("App: searchQuery set to:", val);
|
console.log("App: searchQuery set to:", val);
|
||||||
@@ -404,6 +437,9 @@
|
|||||||
selectedVariants,
|
selectedVariants,
|
||||||
tagDropdownOpen,
|
tagDropdownOpen,
|
||||||
compactMode,
|
compactMode,
|
||||||
|
collection,
|
||||||
|
setCollection,
|
||||||
|
collections,
|
||||||
setSearchQuery,
|
setSearchQuery,
|
||||||
setGridView,
|
setGridView,
|
||||||
setListView,
|
setListView,
|
||||||
|
|||||||
20
src/collections.js
Normal file
20
src/collections.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// This file lists all supported collections for the gallery
|
||||||
|
export const collections = [
|
||||||
|
{
|
||||||
|
name: 'logos',
|
||||||
|
label: 'Logos',
|
||||||
|
baseDir: 'logos',
|
||||||
|
genDir: 'logos_gen',
|
||||||
|
dataFile: 'data/logos.json'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'flags',
|
||||||
|
label: 'Flags',
|
||||||
|
baseDir: 'flags',
|
||||||
|
genDir: 'flags_gen',
|
||||||
|
dataFile: 'data/flags.json'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
module.exports = { collections };
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
import ThemeSwitcher from "./ThemeSwitcher.svelte";
|
import ThemeSwitcher from "./ThemeSwitcher.svelte";
|
||||||
import ListViewSwitcher from "./ListViewSwitcher.svelte";
|
import ListViewSwitcher from "./ListViewSwitcher.svelte";
|
||||||
import SearchBar from "./SearchBar.svelte";
|
import SearchBar from "./SearchBar.svelte";
|
||||||
|
import { collections } from "../collections.js";
|
||||||
|
|
||||||
export let displayLogos = [];
|
export let displayLogos = [];
|
||||||
export let allLogos = []; // Add this to get total count
|
export let allLogos = []; // Add this to get total count
|
||||||
@@ -30,6 +31,8 @@
|
|||||||
export let getTagObj = (tag) => ({ text: tag });
|
export let getTagObj = (tag) => ({ text: tag });
|
||||||
export let compactMode = false;
|
export let compactMode = false;
|
||||||
export let setCompactMode = () => {};
|
export let setCompactMode = () => {};
|
||||||
|
export let collection = "logos";
|
||||||
|
export let setCollection = () => {};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<header class="main-header">
|
<header class="main-header">
|
||||||
@@ -38,6 +41,11 @@
|
|||||||
<div class="header-icon">
|
<div class="header-icon">
|
||||||
<img src="favicon.svg" alt="Logo Gallery icon" />
|
<img src="favicon.svg" alt="Logo Gallery icon" />
|
||||||
</div>
|
</div>
|
||||||
|
<select class="collection-chooser" bind:value={collection} on:change={(e) => setCollection(e.target.value)} aria-label="Choose collection">
|
||||||
|
{#each collections as c}
|
||||||
|
<option value={c.name}>{c.label}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
<h1>Logo Gallery</h1>
|
<h1>Logo Gallery</h1>
|
||||||
</div>
|
</div>
|
||||||
<span class="logo-count">
|
<span class="logo-count">
|
||||||
@@ -119,6 +127,18 @@
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.collection-chooser {
|
||||||
|
font-family: inherit;
|
||||||
|
font-size: 1rem;
|
||||||
|
color: var(--color-text);
|
||||||
|
background: var(--color-card);
|
||||||
|
border: 1px solid var(--color-border);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0.25rem 0.5rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.header-controls {
|
.header-controls {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user