v0.10.26: /blog/ 归档(archive_cards 皮肤/BlogArchive/WP 分页窗口)+ 文章详情 single 模板(hero/面包屑/三列正文+侧栏)+ page_css 全站导入(254篇) + 图片 WP 尺寸变体解析

This commit is contained in:
bigcode
2026-11-03 04:52:05 +08:00
parent 9a51994860
commit d016be03ae
12 changed files with 505 additions and 96 deletions
+26 -7
View File
@@ -113,30 +113,49 @@ function filterCss(css: string, ids: Set<string>, pid: number): string {
const slugs = process.argv.slice(2).length ? process.argv.slice(2) : SOLUTION_SLUGS;
const sql = new SQL("postgres://dusuniot:dusuniot@127.0.0.1:25432/dusuniot", { max: 1 });
/** 已导入过的跳过(断点续传;meta.page_css 键存在即视为完成) */
let done = 0;
let skipped = 0;
for (const slug of slugs) {
const rows = await sql`select id, legacy_id, meta::text as meta from contents where slug = ${slug} and type = ${"post"} limit 1`;
const row = rows[0];
if (!row) {
console.log("SKIP(无内容):", slug);
skipped++;
continue;
}
const meta = JSON.parse(row.meta);
if (meta.page_css !== undefined) {
skipped++;
continue;
}
const ids = collectIds(meta.elementor);
const pid = row.legacy_id;
if (!pid) {
console.log("SKIP(无 legacy_id):", slug);
skipped++;
continue;
}
const res = await fetch(CSS_URL(pid), { headers: { "User-Agent": "Mozilla/5.0" } });
if (!res.ok) {
console.log("SKIP(css", res.status, "):", slug, CSS_URL(pid));
// 重试 3 次、间隔 300ms(原站偶发 ECONNRESET/限流)
let raw: string | null = null;
for (let attempt = 0; attempt < 3 && raw === null; attempt++) {
try {
const res = await fetch(CSS_URL(pid), { headers: { "User-Agent": "Mozilla/5.0" } });
if (res.ok) raw = await res.text();
else if (res.status === 404) break;
} catch {
await new Promise((r) => setTimeout(r, 300));
}
}
if (raw === null) {
console.log("SKIP(fetch失败):", slug, pid);
skipped++;
continue;
}
const raw = await res.text();
const pageCss = filterCss(raw, ids, pid);
meta.page_css = pageCss;
// ::text::jsonb 双重转换:Bun SQL 绑定字符串直接 ::jsonb 会把整串存成 JSON 字符串值
await sql`update contents set meta = ${JSON.stringify(meta)}::text::jsonb where id = ${row.id}`;
console.log("OK:", slug, "post", pid, "css", raw.length, "->", pageCss.length);
done++;
if (done % 50 === 0) console.log(`... ${done} imported`);
}
console.log("imported:", done, "skipped:", skipped);
await sql.end();