website backgrounds: make it easy to force a bg for a service
rework a bit the backgrounds transformation script so that we can later easily force a specific background for a specific service. This comes from a request from france-transfert but they changed their mind in the end. Felt like the logic is good to keep for later though.
@@ -1,6 +1,7 @@
|
|||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { promisify } from "util"
|
import { promisify } from "util"
|
||||||
|
const readdir = promisify(fs.readdir)
|
||||||
const copyFile = promisify(fs.copyFile)
|
const copyFile = promisify(fs.copyFile)
|
||||||
|
|
||||||
import services from "../src/data/services.json" with { type: "json" }
|
import services from "../src/data/services.json" with { type: "json" }
|
||||||
@@ -11,12 +12,17 @@ const weekOffset = args[0] && !isNaN(args[0]) ? args[0] * 1 : Math.floor(new Dat
|
|||||||
const backgroundsDir = path.join(import.meta.dirname, "..", "src", "assets", "backgrounds")
|
const backgroundsDir = path.join(import.meta.dirname, "..", "src", "assets", "backgrounds")
|
||||||
const outputDir = path.join(import.meta.dirname, "..", "public", "api", "backgrounds", "v1")
|
const outputDir = path.join(import.meta.dirname, "..", "public", "api", "backgrounds", "v1")
|
||||||
|
|
||||||
|
let backgrounds = await readdir(backgroundsDir)
|
||||||
|
backgrounds = backgrounds.filter((bg) => bg.endsWith(".jpg")).map((bg) => bg.replace(".jpg", ""))
|
||||||
|
|
||||||
async function buildStaticBackgrounds() {
|
async function buildStaticBackgrounds() {
|
||||||
try {
|
try {
|
||||||
console.log(`Building backgrounds with offset ${weekOffset}…`)
|
console.log(`Building backgrounds with offset ${weekOffset}…`)
|
||||||
services.forEach(async (service, i) => {
|
services.forEach(async (service, i) => {
|
||||||
;[".avif", ".jpg"].forEach(async (ext) => {
|
;[".avif", ".jpg"].forEach(async (ext) => {
|
||||||
const srcPath = path.join(backgroundsDir, `${weekOffset + i}${ext}`)
|
let src = backgrounds[weekOffset + i]
|
||||||
|
// if we want, we can check the service id and force a specific src here
|
||||||
|
const srcPath = path.join(backgroundsDir, `${src}${ext}`)
|
||||||
const destPath = path.join(outputDir, `${service.id}${ext}`)
|
const destPath = path.join(outputDir, `${service.id}${ext}`)
|
||||||
await copyFile(srcPath, destPath)
|
await copyFile(srcPath, destPath)
|
||||||
console.log(`Copied ${getFilename(srcPath)} to ${getFilename(destPath)}`)
|
console.log(`Copied ${getFilename(srcPath)} to ${getFilename(destPath)}`)
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ async function resizeSourceBackgrounds() {
|
|||||||
const backgrounds = await readdir(sourcesDir)
|
const backgrounds = await readdir(sourcesDir)
|
||||||
backgrounds.forEach((backgroundFile, i) => {
|
backgrounds.forEach((backgroundFile, i) => {
|
||||||
const srcPath = path.join(sourcesDir, backgroundFile)
|
const srcPath = path.join(sourcesDir, backgroundFile)
|
||||||
const jpegPath = path.join(outputDir, `${i}.jpg`)
|
const backgroundName = path.parse(backgroundFile).name
|
||||||
const avifPath = path.join(outputDir, `${i}.avif`)
|
const jpegPath = path.join(outputDir, `${backgroundName}.jpg`)
|
||||||
|
const avifPath = path.join(outputDir, `${backgroundName}.avif`)
|
||||||
|
|
||||||
const image = sharp(srcPath)
|
const image = sharp(srcPath)
|
||||||
.resize(1920, 1200, { fit: "cover" })
|
.resize(1920, 1200, { fit: "cover" })
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 289 KiB After Width: | Height: | Size: 289 KiB |
|
Before Width: | Height: | Size: 84 KiB After Width: | Height: | Size: 84 KiB |
|
Before Width: | Height: | Size: 255 KiB After Width: | Height: | Size: 255 KiB |
|
Before Width: | Height: | Size: 53 KiB After Width: | Height: | Size: 53 KiB |
|
Before Width: | Height: | Size: 194 KiB After Width: | Height: | Size: 194 KiB |
|
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 109 KiB |
|
Before Width: | Height: | Size: 295 KiB After Width: | Height: | Size: 295 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 263 KiB After Width: | Height: | Size: 263 KiB |
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 145 KiB After Width: | Height: | Size: 145 KiB |
|
Before Width: | Height: | Size: 229 KiB After Width: | Height: | Size: 229 KiB |
|
Before Width: | Height: | Size: 475 KiB After Width: | Height: | Size: 475 KiB |
|
Before Width: | Height: | Size: 122 KiB After Width: | Height: | Size: 122 KiB |
|
Before Width: | Height: | Size: 297 KiB After Width: | Height: | Size: 297 KiB |
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 95 KiB |
|
Before Width: | Height: | Size: 251 KiB After Width: | Height: | Size: 251 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 193 KiB After Width: | Height: | Size: 193 KiB |
|
Before Width: | Height: | Size: 79 KiB After Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 256 KiB |
|
Before Width: | Height: | Size: 57 KiB After Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 281 KiB After Width: | Height: | Size: 281 KiB |
|
Before Width: | Height: | Size: 131 KiB After Width: | Height: | Size: 131 KiB |
|
Before Width: | Height: | Size: 332 KiB After Width: | Height: | Size: 332 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 248 KiB After Width: | Height: | Size: 248 KiB |
|
Before Width: | Height: | Size: 45 KiB After Width: | Height: | Size: 45 KiB |
|
Before Width: | Height: | Size: 192 KiB After Width: | Height: | Size: 192 KiB |
|
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
Before Width: | Height: | Size: 219 KiB After Width: | Height: | Size: 219 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 278 KiB After Width: | Height: | Size: 278 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 152 KiB |
|
Before Width: | Height: | Size: 243 KiB After Width: | Height: | Size: 243 KiB |
|
Before Width: | Height: | Size: 444 KiB After Width: | Height: | Size: 444 KiB |
|
Before Width: | Height: | Size: 212 KiB After Width: | Height: | Size: 212 KiB |
|
Before Width: | Height: | Size: 423 KiB After Width: | Height: | Size: 423 KiB |