first commit:
- we have a static astro website under /website. It has the implementation docs of the homepage/gaufre templates, and it handles the few API endpoints (the gaufre js, backgrounds, logos) - we have a vite app under /packages/integration. It has the react components generating the homepage and the gaufre button, and their css. Its used to generate an npm package
This commit is contained in:
39
website/bin/build-services-backgrounds.mjs
Normal file
39
website/bin/build-services-backgrounds.mjs
Normal file
@@ -0,0 +1,39 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { promisify } from "util"
|
||||
const copyFile = promisify(fs.copyFile)
|
||||
|
||||
import services from "../src/data/services.json" with { type: "json" }
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
const weekOffset = args[0] && !isNaN(args[0]) ? args[0] * 1 : Math.floor(new Date().getDate() / 7)
|
||||
|
||||
const backgroundsDir = path.join(import.meta.dirname, "..", "src", "assets", "backgrounds")
|
||||
const outputDir = path.join(import.meta.dirname, "..", "public", "api", "backgrounds", "v1")
|
||||
|
||||
async function buildStaticBackgrounds() {
|
||||
try {
|
||||
console.log(`Building backgrounds with offset ${weekOffset}…`)
|
||||
services.forEach(async (service, i) => {
|
||||
;[".avif", ".jpg"].forEach(async (ext) => {
|
||||
const srcPath = path.join(backgroundsDir, `${weekOffset + i}${ext}`)
|
||||
const destPath = path.join(outputDir, `${service.id}${ext}`)
|
||||
await copyFile(srcPath, destPath)
|
||||
console.log(`Copied ${getFilename(srcPath)} to ${getFilename(destPath)}`)
|
||||
if (i === 0) {
|
||||
await copyFile(srcPath, path.join(outputDir, `default${ext}`))
|
||||
console.log(`Copied ${getFilename(srcPath)} to default${ext}`)
|
||||
}
|
||||
})
|
||||
})
|
||||
console.log("Backgrounds have been successfully built.")
|
||||
} catch (error) {
|
||||
console.error("Error building static backgrounds:", error)
|
||||
}
|
||||
}
|
||||
|
||||
function getFilename(path) {
|
||||
return path.split("/").pop()
|
||||
}
|
||||
|
||||
buildStaticBackgrounds()
|
||||
49
website/bin/transform-source-backgrounds.mjs
Normal file
49
website/bin/transform-source-backgrounds.mjs
Normal file
@@ -0,0 +1,49 @@
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { promisify } from "util"
|
||||
import sharp from "sharp"
|
||||
import svgGradient from "svg-gradient"
|
||||
const readdir = promisify(fs.readdir)
|
||||
|
||||
const sourcesDir = path.join(import.meta.dirname, "..", "src", "assets", "backgrounds", "sources")
|
||||
const outputDir = path.join(import.meta.dirname, "..", "src", "assets", "backgrounds")
|
||||
|
||||
async function resizeSourceBackgrounds() {
|
||||
try {
|
||||
console.log(`Resizing source background files…`)
|
||||
|
||||
const gradient = await sharp(
|
||||
Buffer.from(
|
||||
svgGradient(`linear-gradient(135deg, rgba(0, 0, 145, 0.6) 0%, rgba(225, 0, 15, 0.6) 100%)`),
|
||||
),
|
||||
)
|
||||
.resize(1920, 1200, { fit: "cover" })
|
||||
.toBuffer()
|
||||
|
||||
const backgrounds = await readdir(sourcesDir)
|
||||
backgrounds.forEach((backgroundFile, i) => {
|
||||
const srcPath = path.join(sourcesDir, backgroundFile)
|
||||
const jpegPath = path.join(outputDir, `${i}.jpg`)
|
||||
const avifPath = path.join(outputDir, `${i}.avif`)
|
||||
|
||||
const image = sharp(srcPath)
|
||||
.resize(1920, 1200, { fit: "cover" })
|
||||
.composite([{ input: gradient }])
|
||||
|
||||
image.toFile(jpegPath).then(() => {
|
||||
console.log(`Resized ${getFilename(backgroundFile)} to ${getFilename(jpegPath)}`)
|
||||
})
|
||||
image.toFile(avifPath).then(() => {
|
||||
console.log(`Resized ${getFilename(backgroundFile)} to ${getFilename(avifPath)}`)
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
console.error("Error:", error)
|
||||
}
|
||||
}
|
||||
|
||||
function getFilename(path) {
|
||||
return path.split("/").pop()
|
||||
}
|
||||
|
||||
resizeSourceBackgrounds()
|
||||
Reference in New Issue
Block a user