Skip to content

fix(build): stabilize build assets and remove redundant render - #747

Open
markd3ng wants to merge 3 commits into
CuteLeaf:masterfrom
markd3ng:ff/build-assets
Open

markd3ng wants to merge 3 commits into
CuteLeaf:masterfrom
markd3ng:ff/build-assets

Conversation

@markd3ng

@markd3ng markd3ng commented Nov 29, 2026 •

Copy link
Copy Markdown

Summary

  • FF-17: resolve the sakura texture through import.meta.env.BASE_URL in both the DOM image and the OffscreenCanvas worker, so subpath deployments load the effect instead of 404-ing.
  • FF-21: reuse the single render(entry) result for content and remarkPluginFrontmatter; the previous second call reran the full remark/rehype pipeline (including Mermaid SSR and wiki-link metadata collection) for every post.
  • FF-35: recompute all LQIP placeholders on each generation run. Incremental keys were path-only, so replacing an image in place kept its old 2×2 gradient forever. 36 images are processed in well under a second.
  • FF-37: extend the font-subset charset scan beyond dist/**/*.html to content and locale sources; runtime/memo text that never appears in a static page no longer risks missing glyphs.
  • FF-46: replace Math.random() ids with a per-tree diagram counter and a SHA-256-derived GitHub card id, making rebuild output stable.

Verification

  • pnpm exec biome check on the 7 changed source files: no diagnostics (only the pre-existing biome schema-version notice).
  • pnpm run check: 0 errors, 0 warnings, 0 hints.
  • Full pnpm run build: completed, 40 pages, all post-build scripts included.
  • Built HTML uses plantuml-0…8 and stable GC862bb9-* ids; no Math.random() remains in either plugin; no unexpanded import.meta.env.BASE_URL remains in built JS.
  • Regenerated src/constants/lqips.json keeps the same 36 values (only ordering changed) and the discovery of previously stale entries.

Sourcery 摘要

稳定资源生成与构建输出,同时避免重复渲染文章。

错误修复:

  • 修复网站部署在子路径下时樱花特效的资源加载问题。
  • 确保重新生成图片占位符,避免替换资源后仍保留过期的 LQIP 数据。
  • 在发现字体子集字符时纳入运行时文本和本地化源文本,以防缺少字形。
  • 确保生成的图表和 GitHub 卡片标识符在不同构建之间保持一致。

增强功能:

  • 生成页面内容和 frontmatter 元数据时复用同一份文章渲染结果,避免重复处理。

构建:

  • 更新生成的 LQIP 数据,以反映完整的图片重新生成。
Original summary in English

Sourcery 摘要

稳定构建资源生成和渲染输出,同时消除冗余的文章处理。

错误修复:

  • 修复 Sakura 效果资源在部署于子路径下时的加载问题。
  • 重新生成所有 LQIP 占位图,避免图片原位替换后遗留过时数据。
  • 收集用于字体子集化的字符时,纳入内容和本地化资源。
  • 确保生成的 PlantUML 和 GitHub 卡片标识符在不同构建之间保持确定性。

增强功能:

  • 页面内容和 frontmatter 元数据复用同一份文章渲染结果,避免重复处理。

构建:

  • 根据完整的图片集重新生成 LQIP 数据。
Original summary in English

Sourcery 摘要

稳定生成的资源和构建产物,同时避免重复渲染文章。

错误修复:

  • 修复 Sakura 特效资源在部署于子路径下时的加载问题。
  • 重新生成所有 LQIP 占位图,避免替换图片后仍保留过期数据。
  • 收集字体子集化所需字符时,纳入内容和本地化源文本。
  • 确保生成的 PlantUML 和 GitHub 卡片标识符在不同构建之间保持一致。

改进:

  • 页面内容和 frontmatter 元数据复用同一份文章渲染结果,避免重复处理。

构建:

  • 根据完整图片集刷新生成的 LQIP 数据。
Original summary in English

Summary by Sourcery

Stabilize generated assets and build output while eliminating redundant article rendering.

Bug Fixes:

  • Fix Sakura effect asset loading for deployments hosted under a subpath.
  • Regenerate all LQIP placeholders so replaced images cannot retain stale data.
  • Include content and localization source text when collecting characters for font subsetting.
  • Make generated PlantUML and GitHub card identifiers deterministic across builds.

Enhancements:

  • Reuse a single article rendering result for page content and frontmatter metadata to avoid redundant processing.

Build:

  • Refresh the generated LQIP data from the complete image set.

- FF-17: resolve sakura asset through BASE_URL in both main thread and worker
- FF-21: reuse the single render() result instead of running the pipeline twice per post
- FF-35: recompute all 2x2 LQIP placeholders on each generation run
- FF-37: include content and runtime locale text in the font-subset charset scan
- FF-46: derive plantuml and GitHub card ids deterministically
@netlify

netlify Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

👷 Deploy request for demo-firefly pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 4b9a8d4

@sourcery-ai

sourcery-ai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

审阅者指南

数据结构

审阅 LQIP 映射的更新:现在会重新计算每张图片,同时在处理失败时保留先前的值,并移除过时的键。

  • scripts/generate-lqips.ts L69(已删除的行)、L78-120、L127
  • src/constants/lqips.json L4-8(+4 处小改动)

实现

检查为 GitHub 卡片和 PlantUML 图表新增的确定性树级标识符及冲突处理。

  • src/plugins/rehype-component-github-card.mjs L17-20、L34-37(+2 处小改动)
  • src/plugins/rehype-plantuml.mjs L13(已删除的行)、L26-31、L66-70

审阅字体子集字符扫描是否将内容和区域设置源文本与构建后的 HTML 一并纳入。

  • scripts/subset-fonts.ts L21-26、L139-146(+2 处小改动)

确认文章渲染在处理页面内容和 frontmatter 元数据时复用了同一个渲染结果。

  • src/pages/posts/[...slug].astro L68

配置

检查 Sakura 图片加载的两条路径是否都通过配置的基础 URL 解析纹理,以支持子路径部署。

  • src/components/features/SakuraEffect.astro L216
  • src/workers/sakura.worker.ts L197-199

提示和命令

与 Sourcery 交互

  • 触发新一轮审阅: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审阅评论。
  • 根据审阅评论创建 GitHub issue: 回复审阅评论,请 Sourcery 根据该评论创建 issue。你也可以回复审阅评论并发送 @sourcery-ai issue,以此创建 issue。
  • 生成拉取请求标题: 在拉取请求标题的任意位置写入 @sourcery-ai,即可随时生成标题。你也可以在拉取请求中评论 @sourcery-ai title,以便随时生成或重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。你也可以在拉取请求中评论 @sourcery-ai summary,以便随时生成或重新生成摘要。
  • 生成审阅者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时生成或重新生成审阅者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论,且不想再看到这些评论,此功能会很有用。
  • 关闭所有 Sourcery 审阅: 在拉取请求中评论 @sourcery-ai dismiss,即可关闭所有现有的 Sourcery 审阅。如果你想从头开始进行新一轮审阅,这项功能尤其有用——别忘了评论 @sourcery-ai review 来触发新一轮审阅!

自定义使用体验

访问你的控制面板,即可:

  • 启用或停用审阅功能,例如 Sourcery 生成的拉取请求摘要、审阅者指南等。
  • 更改审阅语言。
  • 添加、移除或编辑自定义审阅指令。
  • 调整其他审阅设置。

获取帮助

Original review guide in English

Reviewer's Guide

Data structures

Review the LQIP map update, which now recomputes every image while preserving prior values on processing failures and removing stale keys.

  • scripts/generate-lqips.ts L69 (removed lines), L78-120, L127
  • src/constants/lqips.json L4-8 (+4 small edits)

Implementation

Check the deterministic per-tree identifiers and collision handling added for GitHub cards and PlantUML diagrams.

  • src/plugins/rehype-component-github-card.mjs L17-20, L34-37 (+2 small edits)
  • src/plugins/rehype-plantuml.mjs L13 (removed lines), L26-31, L66-70

Review the font-subset character scan’s inclusion of content and locale source text alongside built HTML.

  • scripts/subset-fonts.ts L21-26, L139-146 (+2 small edits)

Verify post rendering reuses one render result for page content and frontmatter metadata.

  • src/pages/posts/[...slug].astro L68

Configuration

Check that both Sakura image-loading paths resolve the texture through the configured base URL for subpath deployments.

  • src/components/features/SakuraEffect.astro L216
  • src/workers/sakura.worker.ts L197-199

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 5 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/generate-lqips.ts" line_range="79" />
<code_context>
-
-	const lqips: LqipMap = { ...existingLqips };
+	// 每次全量重算:仅 2×2 缩放,代价很小;避免原位换图后沿用旧占位色
+	const lqips: LqipMap = {};
 	let processed = 0;
-
</code_context>
<issue_to_address>
**Existing image placeholders disappear**

When an image with an existing LQIP entry fails processing during regeneration, `processImage()` returns `null`, so the newly empty `lqips` map omits the image and replaces the previous JSON entry; the image loses its usable LQIP placeholder.

Preserve the existing entry when processing fails, or fail generation instead of writing an incomplete map.

Also at `scripts/generate-lqips.ts:85-86`.
</issue_to_address>

### Comment 2
<location path="src/plugins/rehype-component-github-card.mjs" line_range="31" />
<code_context>

 	const repo = properties.repo;
-	const cardUuid = `GC${Math.random().toString(36).slice(-6)}`; // Collisions are not important
+	const cardUuid = `GC${createHash("sha256").update(repo).digest("hex").slice(0, 6)}`;
 	const data = githubCardData[repo.toLowerCase()] ?? null;
 	const hasData = data !== null;
</code_context>
<issue_to_address>
**Repeated cards have ambiguous targets**

When the same repository card is rendered more than once on a page, `cardUuid` hashes only `repo`, so repeated cards emit duplicate IDs for their cards and child elements; fragment links and ID-based lookups cannot reliably target the intended card.

Generate a distinct ID for each rendered card and use it for that card's child elements.
</issue_to_address>

### Comment 3
<location path="scripts/subset-fonts.ts" line_range="23" />
<code_context>

+// 静态 HTML 之外可能只在工作表中出现的文本(memos、七种语言文案等)
+const RUNTIME_TEXT_GLOBS = [
+	"src/content/**/*.{md,mdx,json}",
+	"src/i18n/languages/*.ts",
+];
</code_context>
<issue_to_address>
**Runtime memo text loses glyphs**

When memos is enabled and its API returns characters absent from the files and static HTML scanned for font subsetting, `collectChars()` omits those runtime characters, so `subset-fonts.ts` produces a font without their glyphs and memo text renders with a fallback font or missing characters.

Include runtime memo characters in the subset character set or ensure memo text uses a font that contains them.
</issue_to_address>

### Comment 4
<location path="src/plugins/rehype-plantuml.mjs" line_range="62" />
<code_context>
 			}

-			const diagramId = generateId();
+			const diagramId = `plantuml-${diagramIndex++}`;

 			const img = h("img", {
</code_context>
<issue_to_address>
**Diagram IDs collide with headings**

When a heading slug matches a generated `plantuml-N` ID, `rehypePlantuml` assigns the same ID to the diagram and heading, so fragment and table-of-contents links can target the wrong element.

Assign diagram IDs that are unique within the document and do not collide with heading IDs.

Also at `src/plugins/rehype-plantuml.mjs:71`.
</issue_to_address>

### Comment 5
<location path="scripts/generate-lqips.ts" line_range="79" />
<code_context>
-
-	const lqips: LqipMap = { ...existingLqips };
+	// 每次全量重算:仅 2×2 缩放,代价很小;避免原位换图后沿用旧占位色
+	const lqips: LqipMap = {};
 	let processed = 0;
-
</code_context>
<issue_to_address>
**Older generation overwrites newer gradients**

When two generation jobs overlap while an image is replaced, and the job that processed the old pixels finishes last, the earlier job can finish after the newer job and write a map computed from the old image pixels, overwriting the newer map; subsequent builds then use stale gradients.

Serialize generation jobs or verify that the source inputs are still current before committing the generated map.
</issue_to_address>

Sourcery 评估

待批准。 请先处理 5 项发现。

阻塞性问题:scripts/generate-lqips.ts:79、src/plugins/rehype-component-github-card.mjs:31、scripts/subset-fonts.ts:23、src/plugins/rehype-plantuml.mjs:62、scripts/generate-lqips.ts:79


Sourcery 对开源项目免费使用——如果您喜欢我们的审查意见,欢迎分享 ✨
Original comment in English

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="scripts/generate-lqips.ts" line_range="79" />
<code_context>
-
-	const lqips: LqipMap = { ...existingLqips };
+	// 每次全量重算:仅 2×2 缩放,代价很小;避免原位换图后沿用旧占位色
+	const lqips: LqipMap = {};
 	let processed = 0;
-
</code_context>
<issue_to_address>
**Existing image placeholders disappear**

When an image with an existing LQIP entry fails processing during regeneration, `processImage()` returns `null`, so the newly empty `lqips` map omits the image and replaces the previous JSON entry; the image loses its usable LQIP placeholder.

Preserve the existing entry when processing fails, or fail generation instead of writing an incomplete map.

Also at `scripts/generate-lqips.ts:85-86`.
</issue_to_address>

### Comment 2
<location path="src/plugins/rehype-component-github-card.mjs" line_range="31" />
<code_context>

 	const repo = properties.repo;
-	const cardUuid = `GC${Math.random().toString(36).slice(-6)}`; // Collisions are not important
+	const cardUuid = `GC${createHash("sha256").update(repo).digest("hex").slice(0, 6)}`;
 	const data = githubCardData[repo.toLowerCase()] ?? null;
 	const hasData = data !== null;
</code_context>
<issue_to_address>
**Repeated cards have ambiguous targets**

When the same repository card is rendered more than once on a page, `cardUuid` hashes only `repo`, so repeated cards emit duplicate IDs for their cards and child elements; fragment links and ID-based lookups cannot reliably target the intended card.

Generate a distinct ID for each rendered card and use it for that card's child elements.
</issue_to_address>

### Comment 3
<location path="scripts/subset-fonts.ts" line_range="23" />
<code_context>

+// 静态 HTML 之外可能只在工作表中出现的文本(memos、七种语言文案等)
+const RUNTIME_TEXT_GLOBS = [
+	"src/content/**/*.{md,mdx,json}",
+	"src/i18n/languages/*.ts",
+];
</code_context>
<issue_to_address>
**Runtime memo text loses glyphs**

When memos is enabled and its API returns characters absent from the files and static HTML scanned for font subsetting, `collectChars()` omits those runtime characters, so `subset-fonts.ts` produces a font without their glyphs and memo text renders with a fallback font or missing characters.

Include runtime memo characters in the subset character set or ensure memo text uses a font that contains them.
</issue_to_address>

### Comment 4
<location path="src/plugins/rehype-plantuml.mjs" line_range="62" />
<code_context>
 			}

-			const diagramId = generateId();
+			const diagramId = `plantuml-${diagramIndex++}`;

 			const img = h("img", {
</code_context>
<issue_to_address>
**Diagram IDs collide with headings**

When a heading slug matches a generated `plantuml-N` ID, `rehypePlantuml` assigns the same ID to the diagram and heading, so fragment and table-of-contents links can target the wrong element.

Assign diagram IDs that are unique within the document and do not collide with heading IDs.

Also at `src/plugins/rehype-plantuml.mjs:71`.
</issue_to_address>

### Comment 5
<location path="scripts/generate-lqips.ts" line_range="79" />
<code_context>
-
-	const lqips: LqipMap = { ...existingLqips };
+	// 每次全量重算:仅 2×2 缩放,代价很小;避免原位换图后沿用旧占位色
+	const lqips: LqipMap = {};
 	let processed = 0;
-
</code_context>
<issue_to_address>
**Older generation overwrites newer gradients**

When two generation jobs overlap while an image is replaced, and the job that processed the old pixels finishes last, the earlier job can finish after the newer job and write a map computed from the old image pixels, overwriting the newer map; subsequent builds then use stale gradients.

Serialize generation jobs or verify that the source inputs are still current before committing the generated map.
</issue_to_address>

Sourcery assessment

Approval pending. 5 findings to address first.

Blocking findings: scripts/generate-lqips.ts:79, src/plugins/rehype-component-github-card.mjs:31, scripts/subset-fonts.ts:23, src/plugins/rehype-plantuml.mjs:62, scripts/generate-lqips.ts:79


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread scripts/generate-lqips.ts Resolved
Comment thread scripts/subset-fonts.ts

// 静态 HTML 之外可能只在工作表中出现的文本(memos、七种语言文案等)
const RUNTIME_TEXT_GLOBS = [
"src/content/**/*.{md,mdx,json}",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · 运行时备忘录文本缺少字形

启用备忘录功能后,如果其 API 返回的字符不在字体子集化扫描的文件和静态 HTML 中,collectChars() 就会遗漏这些运行时字符,导致 subset-fonts.ts 生成的字体不包含相应字形,备忘录文本因而会使用后备字体渲染,或显示为缺失字符。

将运行时备忘录字符纳入子集字符集,或者确保备忘录文本使用包含这些字符的字体。

面向 AI 代理的提示
在 `scripts/subset-fonts.ts` 第 23 行:

**运行时备忘录文本缺少字形**

启用备忘录功能后,如果其 API 返回的字符不在字体子集化扫描的文件和静态 HTML 中,`collectChars()` 就会遗漏这些运行时字符,导致 `subset-fonts.ts` 生成的字体不包含相应字形,备忘录文本因而会使用后备字体渲染,或显示为缺失字符。

将运行时备忘录字符纳入子集字符集,或者确保备忘录文本使用包含这些字符的字体。
Original comment in English

🟡 Medium · Runtime memo text loses glyphs

When memos is enabled and its API returns characters absent from the files and static HTML scanned for font subsetting, collectChars() omits those runtime characters, so subset-fonts.ts produces a font without their glyphs and memo text renders with a fallback font or missing characters.

Include runtime memo characters in the subset character set or ensure memo text uses a font that contains them.

Prompt for AI agents
In `scripts/subset-fonts.ts` at line 23:

**Runtime memo text loses glyphs**

When memos is enabled and its API returns characters absent from the files and static HTML scanned for font subsetting, `collectChars()` omits those runtime characters, so `subset-fonts.ts` produces a font without their glyphs and memo text renders with a fallback font or missing characters.

Include runtime memo characters in the subset character set or ensure memo text uses a font that contains them.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这一点在当前仓库结构下不能靠扩大静态 glob 解决:src/utils/memos-adapter.ts 从 /api/v1/memos 取运行时数据,memo.content 的字符在构建期不可知,而 scripts/subset-fonts.ts 必须离线生成子集。真正修复需要产品层面的取舍(运行时加载完整字体、放弃子集,或限制 Memos 字符集),超出 FF-17/21/35/37/46 的构建确定性修复范围。保留给 maintainer 决定,暂不 resolve。

Comment thread src/plugins/rehype-plantuml.mjs Resolved
Comment thread scripts/generate-lqips.ts Resolved
- Seed LQIP recomputation from the existing map so a failed image keeps its placeholder.
- Add per-tree occurrence to GitHub card IDs so repeated repos stay unique.
- Skip authored IDs when assigning PlantUML diagram IDs.
- Compare image size and mtime before and after generation so an overlapping run cannot overwrite a newer gradient map.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant