v0.10.27: /product/$slug 产品单模板一比一(模板2741/29972 补录、Woo 图廊/meta/tabs/相关产品组件、page_css 130 篇、动态按钮落地)+ css-translate 共享模块

This commit is contained in:
bigcode
2026-11-03 05:18:10 +08:00
parent d016be03ae
commit 35d154870a
9 changed files with 472 additions and 277 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* # 脚本 为全部已发布产品抓 post-<legacy_id>.css → products.meta.page_css
* 与 import-page-css 相同的翻译(css-translate);断点续传(已有 page_css 键跳过)。
* 用法:bun scripts/import-product-css.ts
*/
import { SQL } from "bun";
import { collectDocIds, filterCssForIds } from "../src/utils/css-translate";
const sql = new SQL("postgres://dusuniot:dusuniot@127.0.0.1:25432/dusuniot", { max: 1 });
const rows = await sql`select id, legacy_id, meta::text as meta from products where status = ${"published"} and legacy_id is not null`;
let done = 0, skipped = 0, fail = 0;
for (const row of rows) {
const meta = JSON.parse(row.meta);
if (meta.page_css !== undefined) { skipped++; continue; }
const ids = collectDocIds(meta.elementor);
let raw: string | null = null;
for (let a = 0; a < 3 && raw === null; a++) {
try {
const res = await fetch(`https://www.dusuniot.com/wp-content/uploads/elementor/css/post-${row.legacy_id}.css`, { 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) { fail++; continue; }
meta.page_css = filterCssForIds(raw, ids, row.legacy_id);
await sql`update products set meta = ${JSON.stringify(meta)}::text::jsonb where id = ${row.id}`;
done++;
if (done % 25 === 0) console.log(`... ${done}`);
}
console.log("imported:", done, "skipped:", skipped, "fail:", fail);
await sql.end();