v0.10.18: H18 最新博文(8bc6b68)完成 + 文章分类关系数据修复

- PostsWidget 忠实重写(skin cards):预取架构 loader 按 widget 收集术语→查文章→
  PostsDataContext 分发;卡 DOM/缩略图比率 0.66/NEWS 徽章(uppercase)/日期 F j,Y/
  摘要 18 词(空回退正文);右列纯文本卡(44px 两行钳制+箭头图标,custom_css 注入)
- posts cards 基础 CSS + slim 白名单 cards_*/_skin/posts_include* 全键
- scripts/repair-content-terms.ts:从 legacy dump wp_term_relationships 提取 67709 对,
  经 legacy_id 映射补插 1162 条 content_terms(Blog 302/News 22 篇,原仅 61 篇有关联)
- 补 icon-arrow-light-orange.png;双端节内几何/样式全等(sec 521),截图目视一致
This commit is contained in:
bigcode
2026-11-02 00:27:15 +08:00
parent f614d10c94
commit 27fa9e605f
8 changed files with 297 additions and 44 deletions
+48
View File
@@ -560,3 +560,51 @@ export const getLatestPosts = createServerFn({ method: "GET" }).handler(async ()
.limit(8);
return rows.map((r) => ({ title: r.title, url: "/blog/" + r.slug + "/" }));
});
/** # 类型 文章卡数据(Elementor posts widget 骨架卡) **/
export type PostCardItem = {
slug: string;
title: string;
excerpt: string | null;
publishedAt: Date | null;
imageUrl: string | null;
content: string | null;
categoryName: string | null;
};
/** # Server Function 按 WP 术语 legacy_id 取最新文章(Elementor posts widget 查询)
* 首页 H18:posts_include=terms + posts_include_term_ids=[54](News 分类 legacy 54)等;
* 经 categories.legacy_id 反查本库分类,再经 content_terms 取其下最新发布文章。
* 参数 legacyTermId WP 术语 id(legacy_id);limit 取条数
* 返回值 文章卡数组(标题/摘要/发布时间/特色图/首个分类名)
*/
export async function listPostsByTermLegacy(legacyTermId: number, limit: number) {
const [cat] = await db
.select({ id: categories.id })
.from(categories)
.where(eq(categories.legacyId, legacyTermId))
.limit(1);
if (!cat) return [] as PostCardItem[];
const rows = await db
.select({
slug: contents.slug,
title: contents.title,
excerpt: contents.excerpt,
publishedAt: contents.publishedAt,
imageUrl: media.url,
content: contents.html,
categoryName: sql<string | null>`(SELECT cat.name FROM content_terms ct JOIN categories cat ON cat.id = ct.category_id WHERE ct.content_id = ${contents.id} AND cat.taxonomy = 'category' LIMIT 1)`,
})
.from(contents)
.leftJoin(media, eq(media.id, contents.featuredMediaId))
.where(
and(
eq(contents.type, "post"),
eq(contents.status, "published"),
sql`EXISTS (SELECT 1 FROM content_terms ct WHERE ct.content_id=${contents.id} AND ct.category_id=${cat.id})`,
),
)
.orderBy(desc(contents.publishedAt))
.limit(Math.max(1, Math.min(20, limit)));
return rows as PostCardItem[];
}