#!/usr/bin/env node const fs = require("fs"); const path = require("path"); const sharp = require("sharp"); const PROJECT_ROOT = path.resolve(__dirname, ".."); const SOURCE_ICON_PATH = path.join(PROJECT_ROOT, "static", "favicon.png"); const APPLE_TOUCH_ICON_SIZE = 180; const APPLE_TOUCH_ICON_BACKGROUND = "#060c14"; const OUTPUT_ICON_PATHS = [ path.join(PROJECT_ROOT, "static", "apple-touch-icon.png"), path.join(PROJECT_ROOT, "static", "apple-touch-icon-precomposed.png"), ]; /** * Génère le PNG Apple Touch à partir du favicon principal du site. * * L'image finale est rendue opaque sur le fond sombre du thème actif pour * éviter les rendus incohérents des zones transparentes sur certains appareils iOS. * * @returns {Promise} */ function buildAppleTouchIconBuffer() { return sharp(SOURCE_ICON_PATH) .resize(APPLE_TOUCH_ICON_SIZE, APPLE_TOUCH_ICON_SIZE, { fit: "cover", }) .flatten({ background: APPLE_TOUCH_ICON_BACKGROUND, }) .png({ compressionLevel: 9, adaptiveFiltering: true, }) .toBuffer(); } /** * Écrit la même icône sous les deux noms historiques encore demandés par les navigateurs. * * @param {Buffer} iconBuffer */ function writeAppleTouchIcons(iconBuffer) { for (const outputPath of OUTPUT_ICON_PATHS) { fs.writeFileSync(outputPath, iconBuffer); } } (async function main() { const iconBuffer = await buildAppleTouchIconBuffer(); writeAppleTouchIcons(iconBuffer); })();