mirror of
https://github.com/direct-img/vibegif.direct-img.link.git
synced 2026-10-29 19:54:51 +00:00
Add transparent WebP versions of the two GIFs, one gallery tile per name
heart/wink.webp is the keyed-out version of heart/wink.gif. The standing
cat in cat/tail.gif is now cat/wag.{webp,gif} since cat/tail.webp is a
different drawing; cat/tail.gif stays so old links work but is no longer
listed. Gallery images get a content hash in the query so browsers pick
up changed files instead of showing cached copies.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 7.1 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 5.0 KiB |
+16
-12
@@ -1,17 +1,21 @@
|
|||||||
// fills <!--gallery--> in index.html from whatever is in public/
|
// fills <!--gallery--> in index.html from whatever is in public/
|
||||||
// anything rendered from gen/ gets one tile with webp + gif links, older hand-made files get a tile each
|
// one tile per name: shows the .webp (or the .gif if that's all there is) and links every format
|
||||||
import{readdirSync as rd,readFileSync as rf,existsSync as ex}from'fs'
|
// tile images get ?v=<hash> so browsers drop old copies when a file changes, links stay clean for hotlinking
|
||||||
|
import{readdirSync as rd,readFileSync as rf}from'fs'
|
||||||
|
import{createHash}from'crypto'
|
||||||
|
const hidden=['cat/tail.gif'] // same drawing as cat/wag.gif, kept so old links still work
|
||||||
const walk=d=>rd(d,{withFileTypes:true}).flatMap(e=>e.isDirectory()?walk(`${d}/${e.name}`):`${d}/${e.name}`)
|
const walk=d=>rd(d,{withFileTypes:true}).flatMap(e=>e.isDirectory()?walk(`${d}/${e.name}`):`${d}/${e.name}`)
|
||||||
const dims=f=>{const b=rf(f);return f.endsWith('.gif')?[b.readUInt16LE(6),b.readUInt16LE(8)]:[b.readUIntLE(24,3)+1,b.readUIntLE(27,3)+1]}
|
const dims=(b,x)=>x=='gif'?[b.readUInt16LE(6),b.readUInt16LE(8)]:[b.readUIntLE(24,3)+1,b.readUIntLE(27,3)+1]
|
||||||
const gallery=()=>{
|
const gallery=()=>{
|
||||||
const seen=new Set
|
const g={}
|
||||||
return walk('public').filter(f=>/\.(webp|gif)$/.test(f)).sort().map(f=>{
|
for(const f of walk('public').filter(f=>/\.(webp|gif)$/.test(f)).sort()){
|
||||||
const id=f.slice(7).replace(/\.\w+$/,''),g=ex(`gen/${id}.js`)
|
const p=f.slice(7),x=p.split('.').pop()
|
||||||
if(g&&seen.has(id))return''
|
if(!hidden.includes(p))(g[p.slice(0,-x.length-1)]??={})[x]=f
|
||||||
seen.add(id)
|
}
|
||||||
const src=g?`/${id}.webp`:f.slice(6),[w,h]=dims('public'+src)
|
return Object.entries(g).map(([id,fm])=>{
|
||||||
const links=(g?['webp','gif']:[f.split('.').pop()]).map(x=>`<a href="/${id}.${x}">${x}</a>`).join(' ')
|
const x=fm.webp?'webp':'gif',b=rf(fm[x]),[w,h]=dims(b,x),v=createHash('md5').update(b).digest('hex').slice(0,8)
|
||||||
return`<figure><a href="${src}"><img src="${src}" alt="${id.replace('/',' ')}" width="${w}" height="${h}" loading="lazy" decoding="async"></a><figcaption>${links}</figcaption></figure>`
|
const links=['webp','gif'].filter(k=>fm[k]).map(k=>`<a href="/${id}.${k}">${k}</a>`).join(' ')
|
||||||
}).filter(Boolean).join('\n')
|
return`<figure><a href="/${id}.${x}"><img src="/${id}.${x}?v=${v}" alt="${id.replace('/',' ')}" width="${w}" height="${h}" loading="lazy" decoding="async"></a><figcaption>${links}</figcaption></figure>`
|
||||||
|
}).join('\n')
|
||||||
}
|
}
|
||||||
export default{plugins:[{name:'gallery',transformIndexHtml:h=>h.replace('<!--gallery-->',gallery())}]}
|
export default{plugins:[{name:'gallery',transformIndexHtml:h=>h.replace('<!--gallery-->',gallery())}]}
|
||||||
|
|||||||
Reference in New Issue
Block a user