PR Check / Security scan (Snyk) (pull_request) Skipped
PR Check / Lint + typecheck (pull_request) Successful in 1m6s
PR Check / Secret scan (gitleaks) (pull_request) Successful in 7s
PR Check / Dependency audit (pull_request) Successful in 9s
PR Check / Dockerfile lint (droast) (pull_request) Successful in 5s
PR Check / AI code review (opencode) (pull_request) Successful in 1m11s
- generate favicon.ico and favicon.svg from the header avatar; the sprite moves to app/utils/avatar.js so component and generators share one source - register @nuxtjs/seo with site and Person schema.org data from site.config.mjs; canonical, robots, sitemap and llms.txt follow the routes - title "Noel Sabia — <role>", summary_large_image, and no duplicate "| Noel Sabia" suffix from SEO Utils - add a committed 1200x630 OG card generated by pnpm og-image; the dynamic OG renderer and skew protection stay off for the static deployment - pin the Node version @nuxtjs/seo 6 requires and document the setup in the OKF bundle
109 lines
3.7 KiB
JavaScript
109 lines
3.7 KiB
JavaScript
// Generates public/favicon.svg and public/favicon.ico from the pixel avatar in
|
|
// app/utils/avatar.js, so the sprite exists once. Run with `pnpm favicon`.
|
|
//
|
|
// No image library: the sprite is 32x32 cells, so the ICO is written as an
|
|
// uncompressed 32bpp BMP inside a one-image ICO container (4.2 kB), and the SVG
|
|
// merges each run of same-coloured cells per row into one rect.
|
|
|
|
import { mkdirSync, writeFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { AVATAR_PALETTE, AVATAR_SPRITE } from '../app/utils/avatar.js'
|
|
|
|
const SIZE = 32
|
|
// Same chip colour the logo sits on in the header, so the portrait stays
|
|
// readable on a dark browser tab bar. Set to null for a transparent icon.
|
|
const BACKGROUND = '#1b2b3f'
|
|
const OUT_DIR = join(import.meta.dirname, '..', 'public')
|
|
|
|
const hex = (value) => {
|
|
const n = Number.parseInt(value.slice(1), 16)
|
|
return [n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff]
|
|
}
|
|
|
|
const colorAt = (x, y) => {
|
|
const cell = AVATAR_SPRITE[y]?.[x] ?? '.'
|
|
return AVATAR_PALETTE[cell] ?? BACKGROUND
|
|
}
|
|
|
|
// --- SVG -------------------------------------------------------------------
|
|
|
|
const svg = () => {
|
|
const rects = []
|
|
for (let y = 0; y < SIZE; y++) {
|
|
let x = 0
|
|
while (x < SIZE) {
|
|
const color = colorAt(x, y)
|
|
let run = 1
|
|
while (x + run < SIZE && colorAt(x + run, y) === color) run++
|
|
if (color && color !== BACKGROUND) rects.push(`<rect x="${x}" y="${y}" width="${run}" height="1" fill="${color}"/>`)
|
|
x += run
|
|
}
|
|
}
|
|
const background = BACKGROUND
|
|
? `<rect width="${SIZE}" height="${SIZE}" fill="${BACKGROUND}"/>`
|
|
: ''
|
|
return [
|
|
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${SIZE} ${SIZE}" width="${SIZE}" height="${SIZE}" shape-rendering="crispEdges">`,
|
|
...(background ? [background] : []),
|
|
...rects,
|
|
'</svg>',
|
|
// Keep the trailing newline: the end-of-file-fixer pre-commit hook wants it.
|
|
'',
|
|
].join('\n')
|
|
}
|
|
|
|
// --- ICO -------------------------------------------------------------------
|
|
|
|
const ico = () => {
|
|
const xorSize = SIZE * SIZE * 4
|
|
const maskRow = Math.ceil(SIZE / 32) * 4
|
|
const maskSize = maskRow * SIZE
|
|
const bitmap = Buffer.alloc(40 + xorSize + maskSize)
|
|
|
|
bitmap.writeUInt32LE(40, 0) // BITMAPINFOHEADER size
|
|
bitmap.writeInt32LE(SIZE, 4) // width
|
|
bitmap.writeInt32LE(SIZE * 2, 8) // height: XOR image + AND mask
|
|
bitmap.writeUInt16LE(1, 12) // planes
|
|
bitmap.writeUInt16LE(32, 14) // bits per pixel
|
|
bitmap.writeUInt32LE(xorSize + maskSize, 20) // image size
|
|
|
|
// XOR bitmap: bottom-up rows of BGRA.
|
|
let offset = 40
|
|
for (let y = SIZE - 1; y >= 0; y--) {
|
|
for (let x = 0; x < SIZE; x++) {
|
|
const [r, g, b] = hex(colorAt(x, y) ?? '#000000')
|
|
bitmap[offset++] = b
|
|
bitmap[offset++] = g
|
|
bitmap[offset++] = r
|
|
bitmap[offset++] = 0xff
|
|
}
|
|
}
|
|
// AND mask stays zeroed: every pixel is opaque.
|
|
|
|
const header = Buffer.alloc(6)
|
|
header.writeUInt16LE(0, 0) // reserved
|
|
header.writeUInt16LE(1, 2) // type: icon
|
|
header.writeUInt16LE(1, 4) // image count
|
|
|
|
const entry = Buffer.alloc(16)
|
|
entry[0] = SIZE // width
|
|
entry[1] = SIZE // height
|
|
entry[2] = 0 // palette colours
|
|
entry[3] = 0 // reserved
|
|
entry.writeUInt16LE(1, 4) // planes
|
|
entry.writeUInt16LE(32, 6) // bits per pixel
|
|
entry.writeUInt32LE(bitmap.length, 8)
|
|
entry.writeUInt32LE(header.length + entry.length, 12)
|
|
|
|
return Buffer.concat([header, entry, bitmap])
|
|
}
|
|
|
|
// --- write -----------------------------------------------------------------
|
|
|
|
mkdirSync(OUT_DIR, { recursive: true })
|
|
const svgFile = join(OUT_DIR, 'favicon.svg')
|
|
const icoFile = join(OUT_DIR, 'favicon.ico')
|
|
writeFileSync(svgFile, svg())
|
|
writeFileSync(icoFile, ico())
|
|
console.log(`wrote ${svgFile} and ${icoFile}`)
|