feat: add DuckDuckGo logo SVG and update logos.json entry

This commit is contained in:
sHa
2025-05-12 22:23:50 +03:00
parent c9f467de62
commit 64c5f275cb
3 changed files with 44 additions and 40 deletions

View File

@@ -161,6 +161,13 @@
], ],
"brand": "BMW" "brand": "BMW"
}, },
{
"name": "DuckDuckGo",
"path": "logos/duckduckgo.svg",
"format": "SVG",
"disable": false,
"brand": "DuckDuckGo"
},
{ {
"name": "Mastercard", "name": "Mastercard",
"path": "logos/mastercard.svg", "path": "logos/mastercard.svg",

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -1,4 +1,4 @@
// This file has been renamed and updated. See scanLogos.js in the same directory for the new script. #!/usr/bin/env node
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@@ -106,10 +106,6 @@ function scanLogos() {
console.error('Could not parse existing logos.json:', e); console.error('Could not parse existing logos.json:', e);
} }
} }
const existingMap = new Map();
for (const item of existing) {
existingMap.set(item.path, item);
}
try { try {
if (!fs.existsSync(logosDir)) { if (!fs.existsSync(logosDir)) {
@@ -128,31 +124,40 @@ function scanLogos() {
// Create a Set of all logo paths in the directory // Create a Set of all logo paths in the directory
const logoPathsSet = new Set(logoFiles.map(file => `logos/${file}`)); const logoPathsSet = new Set(logoFiles.map(file => `logos/${file}`));
// 1. Keep all existing logos that still exist in the directory, in their original order // Mark existing records as disabled if they are not found in the directory
const keptLogos = existing.filter(item => logoPathsSet.has(item.path)); for (const logo of existing) {
const keptPaths = new Set(keptLogos.map(item => item.path)); if (!logoPathsSet.has(logo.path)) {
logo.disable = true;
}
}
// 2. Add new logos (not present in existing) and sort them alphabetically by name // Create a Set of existing paths to avoid duplication
const existingPathsSet = new Set(existing.map(logo => logo.path));
// Create new minimal logo objects for files that don't have records yet
const newLogos = logoFiles const newLogos = logoFiles
.filter(file => !keptPaths.has(`logos/${file}`)) .filter(file => !existingPathsSet.has(`logos/${file}`))
.map(file => { .map(file => {
const format = getFileExtension(file); const format = getFileExtension(file);
const logoPath = `logos/${file}`; const logoPath = `logos/${file}`;
// Create minimal object for new logos - just the essential fields
return { return {
name: formatName(file), name: formatName(file),
path: logoPath, path: logoPath,
format: format, format: format,
disable: false, disable: false,
tags: [], brand: formatName(file)
}; };
}) })
.sort((a, b) => a.name.localeCompare(b.name)); .sort((a, b) => a.name.localeCompare(b.name));
// 3. Merge: existing (kept) + new (sorted) // Merge existing and new logos
// Instead of just appending newLogos, insert each new logo in the correct sorted position by name let merged = [...existing];
let merged = [...keptLogos];
// Add new logos in alphabetical order
for (const newLogo of newLogos) { for (const newLogo of newLogos) {
// Find the first index where newLogo.name < merged[i].name // Find the position to insert based on name
let insertIdx = merged.findIndex(l => newLogo.name.localeCompare(l.name) < 0); let insertIdx = merged.findIndex(l => newLogo.name.localeCompare(l.name) < 0);
if (insertIdx === -1) { if (insertIdx === -1) {
merged.push(newLogo); merged.push(newLogo);
@@ -160,27 +165,20 @@ function scanLogos() {
merged.splice(insertIdx, 0, newLogo); merged.splice(insertIdx, 0, newLogo);
} }
} }
const logos = merged;
// 4. For all, update format/path/brand fields if needed // Force-upgrade SVGs with older colorConfig format to the new targets+sets format
for (const logoObj of logos) { // but ONLY if they have colors and either a target or selector defined
const file = path.basename(logoObj.path); // Don't add empty objects to logos that don't need them
logoObj.format = getFileExtension(file); for (const logoObj of merged) {
logoObj.path = `logos/${file}`; // Only proceed if this is an SVG with existing color info that needs upgrading
if (!logoObj.name) logoObj.name = formatName(file); if (logoObj.format?.toLowerCase() === 'svg' &&
if (!logoObj.brand) logoObj.brand = logoObj.name; logoObj.colors &&
if (!Array.isArray(logoObj.tags)) logoObj.tags = []; Object.keys(logoObj.colors).length > 0 &&
if (typeof logoObj.disable !== 'boolean') logoObj.disable = false; logoObj.colorConfig &&
!logoObj.sets) {
// Set default colorConfig, targets, and sets for SVGs // Initialize targets only if needed
if (logoObj.format.toLowerCase() === 'svg') { if (!logoObj.targets) {
// Maintain backward compatibility
if (!logoObj.colorConfig) {
logoObj.colorConfig = { target: 'path', attribute: 'fill' };
}
// Add new format targets if not already present
if (!logoObj.targets && (logoObj.colorConfig.target || logoObj.colorConfig.selector)) {
logoObj.targets = {}; logoObj.targets = {};
if (logoObj.colorConfig.selector) { if (logoObj.colorConfig.selector) {
@@ -193,13 +191,11 @@ function scanLogos() {
}); });
} else if (logoObj.colorConfig.target) { } else if (logoObj.colorConfig.target) {
logoObj.targets.main = logoObj.colorConfig.target; logoObj.targets.main = logoObj.colorConfig.target;
} else {
logoObj.targets.main = 'path';
} }
} }
// Create sets if there are colors but no sets // Initialize sets only if we have both colors and targets
if (logoObj.colors && !logoObj.sets) { if (logoObj.targets && Object.keys(logoObj.targets).length > 0) {
logoObj.sets = {}; logoObj.sets = {};
let setIndex = 1; let setIndex = 1;
@@ -209,7 +205,7 @@ function scanLogos() {
logoObj.sets[setName] = {}; logoObj.sets[setName] = {};
// Apply this color to all targets // Apply this color to all targets
Object.keys(logoObj.targets || {}).forEach(targetName => { Object.keys(logoObj.targets).forEach(targetName => {
logoObj.sets[setName][targetName] = colorName; logoObj.sets[setName][targetName] = colorName;
}); });
@@ -219,7 +215,7 @@ function scanLogos() {
} }
} }
return logos; return merged;
} catch (error) { } catch (error) {
console.error('Error scanning logos directory:', error); console.error('Error scanning logos directory:', error);
return []; return [];