Files
m038 f6ee4944f9 feat: complete CDN elimination + SVG icon build pipeline
CDN cleanup:
- entry.html.twig: remove PhotoSwipe CDN + duplicate JS (main.js handles it)
- dailies.html.twig: remove PhotoSwipe CDN + duplicate JS
- home.html.twig: remove PhotoSwipe CDN + MapLibre CDN + maplibre-utils.js
  script tags; add {% block map_assets %} to register map bundle

SVG build pipeline:
- Add lucide-static devDependency; gen-weather-icons.js reads icon SVGs
  from node_modules and emits templates/partials/weather-icons.html.twig
- package.json build script now runs gen-weather-icons.js before esbuild
- entry-journal.html.twig includes generated partial instead of hardcoded map
- Rebuild: main.js 83.7kb, map.js 860.7kb, all fonts; zero CDN requests remain
2026-06-25 00:13:17 +02:00

48 lines
1.6 KiB
JavaScript

#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const iconMap = {
'sunny': 'sun',
'partly cloudy': 'cloud-sun',
'cloudy': 'cloud',
'foggy': 'cloud-fog',
'drizzle': 'cloud-drizzle',
'rain': 'cloud-rain',
'snow': 'cloud-snow',
'thunderstorm': 'cloud-lightning'
};
const wrapAttrs = 'width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"';
function buildSvg(iconName) {
const src = path.resolve(__dirname, '..', 'node_modules', 'lucide-static', 'icons', iconName + '.svg');
const raw = fs.readFileSync(src, 'utf8');
const inner = raw
.replace(/^[\s\S]*?<svg[^>]*>/, '')
.replace(/<\/svg>[\s\S]*$/, '')
.replace(/\s+/g, ' ')
.trim();
return `<svg ${wrapAttrs}>${inner}</svg>`;
}
const entries = Object.entries(iconMap);
const lines = entries.map(([condition, iconName], i) => {
const svg = buildSvg(iconName).replace(/'/g, "\\'");
const pad = ' '.repeat(Math.max(0, 16 - condition.length));
const comma = i < entries.length - 1 ? ',' : '';
return ` '${condition}':${pad}'${svg}'${comma}`;
});
const twig = [
'{# Auto-generated by scripts/gen-weather-icons.js — do not edit directly #}',
'{% set weather_icons = {',
...lines,
'} %}'
].join('\n') + '\n';
const dest = path.resolve(__dirname, '..', 'templates', 'partials', 'weather-icons.html.twig');
fs.writeFileSync(dest, twig);
console.log('Generated ' + path.relative(path.resolve(__dirname, '..'), dest));