hiparquia.dog — sitio F0-lite: Astro estático, cero JS, candado del protocolo en código
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import pw from '/home/claude/.npm-global/lib/node_modules/playwright/index.js';
|
||||
import http from 'http'; import fs from 'fs'; import path from 'path';
|
||||
const {chromium}=pw;
|
||||
const TIPO={'.html':'text/html;charset=utf-8','.woff2':'font/woff2','.png':'image/png'};
|
||||
const srv=http.createServer((req,res)=>{let p=decodeURIComponent(req.url.split('?')[0]);
|
||||
if(p.endsWith('/'))p+='index.html'; const f=path.join('dist',p);
|
||||
if(!fs.existsSync(f)||fs.statSync(f).isDirectory()){res.writeHead(404);return res.end()}
|
||||
res.writeHead(200,{'content-type':TIPO[path.extname(f)]??'application/octet-stream'});
|
||||
res.end(fs.readFileSync(f))});
|
||||
await new Promise(r=>srv.listen(4322,'127.0.0.1',r));
|
||||
const b=await chromium.launch({executablePath:'/opt/pw-browsers/chromium'});
|
||||
fs.mkdirSync('fotos',{recursive:true});
|
||||
for (const [n,vp,ruta,full] of [
|
||||
['inicio-1280',{width:1280,height:1000},'/',true],
|
||||
['ficha-1280',{width:1280,height:1000},'/ficha/nada-te-turbe/',false],
|
||||
['inicio-390',{width:390,height:844},'/',true],
|
||||
['ficha-390',{width:390,height:844},'/ficha/hombres-necios/',false]]){
|
||||
const p=await b.newPage({viewport:vp,deviceScaleFactor:1});
|
||||
await p.goto('http://127.0.0.1:4322'+ruta,{waitUntil:'networkidle'});
|
||||
await p.screenshot({path:`fotos/${n}.png`,fullPage:full});
|
||||
await p.close();
|
||||
}
|
||||
await b.close(); srv.close();
|
||||
console.log('fotos listas');
|
||||
Reference in New Issue
Block a user