import fs from 'node:fs'; import path from 'node:path'; import {createHash} from 'node:crypto'; const root=process.cwd(); const source=path.resolve(root,'public'); const dest=path.resolve(root,'dist'); // Guard the exact build-output path before any replacement. if(dest!==path.join(root,'dist')||!fs.existsSync(path.join(source,'index.html'))) throw new Error('Invalid output or missing captured homepage'); fs.rmSync(dest,{recursive:true,force:true}); fs.mkdirSync(dest,{recursive:true}); const excluded=['fragments','official-price/close','llm-gateway/close','model-leaderboard/close','llm-gateway/open-submit']; fs.cpSync(source,dest,{recursive:true,filter:file=>{ const relative=path.relative(source,file).replaceAll('\\','/'); return !excluded.some(p=>relative===p||relative.startsWith(p+'/')); }}); const adapterCode=fs.readFileSync(path.join(source,'market-adapter.js')); const adapterUrl='/market-adapter.'+createHash('sha256').update(adapterCode).digest('hex').slice(0,12)+'.js'; fs.writeFileSync(path.join(dest,adapterUrl.slice(1)),adapterCode); const runtimeCode=fs.readFileSync(path.join(root,'scripts','offline-runtime.js'),'utf8').replace("'/market-adapter.js'",JSON.stringify(adapterUrl)); const runtimeUrl='/offline-runtime.'+createHash('sha256').update(runtimeCode).digest('hex').slice(0,12)+'.js'; fs.writeFileSync(path.join(dest,'offline-runtime.js'),runtimeCode); fs.writeFileSync(path.join(dest,runtimeUrl.slice(1)),runtimeCode); let count=0,removed=0; function processTree(dir) { for(const entry of fs.readdirSync(dir,{withFileTypes:true})) { const file=path.join(dir,entry.name); if(entry.isDirectory()) {processTree(file);continue;} if(!entry.name.endsWith('.html')) continue; let html=fs.readFileSync(file,'utf8'); // Remove remote tracking only; retain all authentic presentation and interaction scripts. html=html.replace(/'); // Indexing enabled: strip captured noindex directives, keep pages crawlable. html=html.replace(/]*>/gi,''); html=html.replace('',''); if (entry.name==='index.html' && html.includes('')) { html=html.replace('','
非官方复刻演示 · 数据为静态快照 · 源码说明
'); } fs.writeFileSync(file,html);if(entry.name==='index.html')count++; } } processTree(dest); // Sitemap for the pages that are crawlable (the /source/ notice page stays noindex). const siteOrigin='https://cardnav.online'; const urlEntries=[]; function collectPages(dir){ for(const entry of fs.readdirSync(dir,{withFileTypes:true})){ const file=path.join(dir,entry.name); if(entry.isDirectory()){collectPages(file);continue;} if(entry.name!=='index.html')continue; const route='/'+path.relative(dest,path.dirname(file)).replaceAll('\\','/').replace(/^\.?\/?/,''); if(route==='/source'||route.startsWith('/source/'))continue; const canonical=(route==='/'?'/':route+'/').replace(/\/{2,}/g,'/'); urlEntries.push(canonical); } } collectPages(dest); urlEntries.sort(); const sitemap=['','你访问的地址不在这个静态快照站里。
'); fs.writeFileSync(path.join(dest,'robots.txt'),'User-agent: *\nAllow: /\nSitemap: https://cardnav.online/sitemap.xml\n'); fs.writeFileSync(path.join(dest,'_headers'),'/assets/*\n Cache-Control: public, max-age=86400\n/_astro/*\n Cache-Control: public, max-age=31536000, immutable\n/data/*\n Cache-Control: public, max-age=3600\n/*\n X-Content-Type-Options: nosniff\n Referrer-Policy: strict-origin-when-cross-origin\n'); for(const file of ['LICENSE','DATA_LICENSE.md','TRADEMARKS.md']) { const original=path.join(root,'upstream',file); if(fs.existsSync(original)) fs.copyFileSync(original,path.join(dest,file)); } fs.writeFileSync(path.join(dest,'SOURCE_NOTICE.txt'),'Static demonstration reproduction of CardNav. Not the official CardNav service.\nOriginal website: https://cardnav.xyz/\nSource code: https://github.com/charleslee8266/cardnav-web\nSoftware code is AGPL-3.0; original copyright/license notices are retained.\nOriginal brand, production data and editorial content have separate terms.\nNo database, login, payment backend or live submission is included.\nModified frontend code: /source/\n'); fs.mkdirSync(path.join(dest,'source'),{recursive:true}); const sourceFiles=['scripts/offline-runtime.js','scripts/market-adapter.ts','scripts/build.mjs','scripts/split-catalog.mjs','scripts/serve.mjs','package.json']; for(const file of sourceFiles) fs.copyFileSync(path.join(root,file),path.join(dest,'source',path.basename(file)+'.txt')); fs.writeFileSync(path.join(dest,'source','index.html'),'本站不是 CardNav 官方服务。数据是固定快照,没有真实提交、付款或后台。
原项目:CardNav 开源代码,参考提交 cb4e2fd20c88fb6593ca64bedef049c35e40b56a。软件采用 AGPL-3.0;数据与品牌说明单独保留。
页面 HTML、CSS、图片和客户端模块是本域名公开静态资源。原站:cardnav.xyz。
返回演示首页'); const files=[]; function inventory(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true})){const f=path.join(dir,e.name);if(e.isDirectory())inventory(f);else files.push({file:path.relative(dest,f).replaceAll('\\','/'),bytes:fs.statSync(f).size});}} inventory(dest); const report={builtAt:new Date().toISOString(),htmlPages:count,files:files.length,totalBytes:files.reduce((n,f)=>n+f.bytes,0),largestFiles:files.sort((a,b)=>b.bytes-a.bytes).slice(0,10),trackersRemoved:removed,backend:false,deployed:false}; fs.mkdirSync(path.join(root,'RECON'),{recursive:true}); fs.writeFileSync(path.join(root,'RECON','build-report.json'),JSON.stringify(report,null,2)); console.log(JSON.stringify(report,null,2));