This PR generates sitemap.xml and feed.xml from the frontend instead of the manual/toolbox script, so
the public URL scheme lives in one place and the documents are never hand-mutated.
New SvelteKit server routes /sitemap.xml and /feed.xml, generated on demand with a short
Cache-Control (public, max-age=300). There is no server-side cache, so the app regenerates on a
cache miss; browsers, crawlers and any intermediary honour the header.
A shared PostPage entity and ListPostPagesUseCase map published posts to their public URLs using
resolve(), so the frontend route table stays the single source of truth.
sitemap.xml (sitemap package) lists every published post plus the static pages only the frontend
knows about: home, post list, and the terms documents.
feed.xml (feed package) contains only posts, capped at the 20 most recent. Static pages never
appear in the feed.
The backend now exposes, per post, the preview image mime type and size (for a valid RSS enclosure)
and the post updated_time. The frontend uses updated_time as sitemap lastmod, while the feed pubDate
remains the published time.
## Description
This PR generates sitemap.xml and feed.xml from the frontend instead of the manual/toolbox script, so
the public URL scheme lives in one place and the documents are never hand-mutated.
- New SvelteKit server routes /sitemap.xml and /feed.xml, generated on demand with a short
Cache-Control (public, max-age=300). There is no server-side cache, so the app regenerates on a
cache miss; browsers, crawlers and any intermediary honour the header.
- A shared PostPage entity and ListPostPagesUseCase map published posts to their public URLs using
resolve(), so the frontend route table stays the single source of truth.
- sitemap.xml (sitemap package) lists every published post plus the static pages only the frontend
knows about: home, post list, and the terms documents.
- feed.xml (feed package) contains only posts, capped at the 20 most recent. Static pages never
appear in the feed.
- The backend now exposes, per post, the preview image mime type and size (for a valid RSS enclosure)
and the post updated_time. The frontend uses updated_time as sitemap lastmod, while the feed pubDate
remains the published time.
## Package Changes
| Package | Action | Version |
| --- | --- | --- |
| feed | Added | 6.0.0 |
| sitemap | Added | 9.0.1 |
| sanitize-html | Updated | 2.17.3 -> 2.17.7 |
No Cargo.toml changes.
## Screenshots
N/A (XML endpoints).
## Reference
Resolves #117
## Checklist
- [x] A milestone is set
- [x] The related issues has been linked to this branch
---
Generated by Zed coding agent with Deepseek Flash
squid
added this to the 0.8 milestone 2026-09-23 21:21:54 +08:00
The frontend now serves sitemap.xml and feed.xml, so the toolbox container that generated feed.xml is no longer needed. Drop its deployment build step and document the new frontend endpoints in frontend/README.md.
ad9206dBLOG-117 fix: use the semantic id as the feed guid PostPage 新增 semanticId,feed 改設 guid: page.semanticId(feed 會輸出 <guid isPermaLink="false">,與舊 toolbox 的 {semantic_id} 一致),link 仍為完整 URL,符合「只讓 link 改變」。
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Description
This PR generates sitemap.xml and feed.xml from the frontend instead of the manual/toolbox script, so
the public URL scheme lives in one place and the documents are never hand-mutated.
Cache-Control (public, max-age=300). There is no server-side cache, so the app regenerates on a
cache miss; browsers, crawlers and any intermediary honour the header.
resolve(), so the frontend route table stays the single source of truth.
knows about: home, post list, and the terms documents.
appear in the feed.
and the post updated_time. The frontend uses updated_time as sitemap lastmod, while the feed pubDate
remains the published time.
Package Changes
No Cargo.toml changes.
Screenshots
N/A (XML endpoints).
Reference
Resolves #117
Checklist
Generated by Zed coding agent with Deepseek Flash
Code review(BLOG-117 Auto generate sitemap and RSS file)
整體品質很好,分層清楚(domain / application / adapter / framework 都遵守),用
PostPage+ListPostPagesUseCase當作公開 URL 的單一來源是個好設計,前端字串也依規範集中到Strings、重用Links.RSS。後端用一次批次查詢get_image_meta_data_by_ids取代 N+1,值得肯定。實際跑過的驗證(在
BLOG-117_auto_gen_sitemap_and_rss上):SQLX_OFFLINE=true cargo check -p post -p image@0.7.0 -p servercargo test -p post -p image@0.7.0 --libtest_extract_preview_image_id_only)bun run check(svelte-check)bun run lint(prettier + eslint)cargo clippy/cargo fmt --checksearch、configuration/embedding.rs)另外確認:
post.updated_time欄位存在且有 trigger;建置產物build/server/chunks/*已把feed/sitemap打包進去(放在devDependencies、runner 只複製 productionnode_modules沒問題);RSS<enclosure>的type/length確實會採用我們提供的值(feed的 RSS2formatEnclosure會用...enclosure覆蓋預設值),且GET /image/{id}公開且原樣回傳檔案,length與實際位元組一致。🟡 需要處理 / 確認(Important)
1. 圖片檔案遺失會讓「文章列表 + sitemap + feed + 圖片管理」整批 500
backend/feature/image/src/adapter/gateway/image_repository_impl.rs的to_image_meta_data現在對每筆 metadata 都呼叫self.image_storage.size(id)?,而size()用fs::metadata(...),檔案不存在就回Err。這個路徑被list_image_meta_data、get_image_meta_data_by_id以及新增的get_image_meta_data_by_ids共用;後者又經由get_all_post_info_use_case的attach_preview_image_metadata進到get_all_post_info。結果是只要任何一張 DB 有紀錄(deleted_time IS NULL)但磁碟檔案不存在的圖片,就會讓GET /image、GET /image/{id}/info、GET /post、/sitemap.xml、/feed.xml整體回 500。改動前文章列表完全不碰 storage 層,所以這是新引進的單點失效(volume 被清、還原不全、手動改 DB 都可能觸發)。建議讓單一
size()失敗不致命,例如size().ok()(拿不到就略過 enrichment),至少讓列表 / sitemap / feed 不會因一張壞圖全掛。2.
guid變了,會讓既有訂閱者把所有文章當成新品重現舊的
script/toolbox/generate_rss.py用guid isPermaLink="false">{semantic_id}</guid;新的frontend/src/lib/seo/framework/xml/feedDocument.ts設id: page.url.href,而feed的 RSS2 會把id當成guid。也就是 guid 從 semantic-id 變成完整 URL。RSS 讀者以 guid 判斷項目身分,這個變更會讓所有既有文章在讀者端變成未讀新項目(Footer 早已掛Links.RSS,既有訂閱者存在)。若不是你想要的,請把 guid 固定成 semantic id,只讓link改變。3. 舊的 toolbox 產生器沒被移除,形成雙重來源
PR 描述說取代 manual/toolbox script,但
script/toolbox/generate_rss.py、已提交的script/toolbox/feed.xml、README.md、.env、Containerfile都還在,deployment.yaml也仍會 build/push toolbox image,README 現在與新設計互相矛盾。建議在本 PR 或另開 issue 清掉這條路徑。🟢 建議 / nit
GET /post(列表)會回preview_image_mime_type/size,但GET /post/{id}(詳情,走GetFullPostUseCaseImpl)永遠是null。建議在 DTO 註記「僅列表端填入」。Regex每次重新編譯:ImageExtractor::image_regex()每次呼叫都Regex::new().unwrap(),而attach_preview_image_metadata對每篇文章呼叫extract_preview_image_id兩次。可考慮std::sync::OnceLock<Regex>。attach_preview_image_metadata對每次get_all_post_info都執行(含 keyword 搜尋路徑,之後才篩掉結果),每次列表多一個查詢 + N 次fs::metadata。可只在 feed/sitemap 路徑做,或加旗標。image_ids未去重:收集成Vec可能有重複 id(= ANY無害);用HashSet較乾淨。robots.txt未指向 sitemap:可加Sitemap: <APP_BASE_URL>/sitemap.xml。feedDocument.ts同時設date與published:RSS2 只有published決定pubDate,date實際沒作用。preview_image_url是外部 URL(非.../image/{id}),extract_preview_image_id回None就不產生 enclosure(行為與舊 toolbox 不同)。.vscode/settings.json、sqlx UPDATE 空白調整(導致.sqlx快取檔改名)、sanitize-htmlpatch 升版。都無害,但增加 review 噪音。結論
沒有發現真正的邏輯 bug,程式碼品質與測試都到位。傾向 Request changes,主要卡在第 1、2 點(圖片檔案遺失的失效模式、guid 變更),第 3 點建議順手清掉或明確列為 follow-up,其餘為非阻擋性建議。
補充:CI 目前只有
frontend-ci/pr-title-check,這支 PR 的 Rust 變更在 CI 並沒有被編譯(我是用SQLX_OFFLINE在本機驗證可編譯、測試可過)。建議替後端也加一個 CI job。Generated by Zed coding agent with Deepseek Flash
逐條回覆 code review(BLOG-117 Auto generate sitemap and RSS file)
感謝 review。以下逐條對應「在哪個 commit 修復」,commit 皆在
BLOG-117_auto_gen_sitemap_and_rss分支上。🟡 需要處理 / 確認
2f6c70dBLOG-117 fix: tolerate missing image files when reading metadataImageMetaData.size改為Option<i64>,to_image_meta_data改用self.image_storage.size(id).ok(),get_image_meta_data_by_id也跟著回傳Ok(...)。單一size()失敗不再致命,壞圖只會讓自身size為null(GET /image、GET /image/{id}/info、/post、/sitemap.xml、/feed.xml都不再 500)。guid從 semantic id 變成完整 URL,既有訂閱者會把舊文重現ad9206dBLOG-117 fix: use the semantic id as the feed guidPostPage新增semanticId,feed 改設guid: page.semanticId(feed會輸出<guid isPermaLink="false">,與舊 toolbox 的{semantic_id}一致),link仍為完整 URL,符合「只讓 link 改變」。b409c4eBLOG-117 remove: retire the toolbox rss generator刪除整個
script/toolbox/(Containerfile、generate_rss.py、README.md、.env.example、requirements.txt、.gitignore)與deployment.yaml的 Toolbox build/push step,並在frontend/README.md補上新的 sitemap / feed 說明。補充:repo 內並沒有被 git 追蹤的
script/toolbox/feed.xml(從來沒進版控),應該是本機被.gitignore忽略的產物。🟢 建議 / nit
GET /post/{id}、走GetFullPostUseCaseImpl的preview_image_*永遠null)573b673BLOG-117 fix: return preview image metadata from the post detail response把 enrichment 抽成
PreviewImageMetadataService,list 與 detail 共用;GetFullPostUseCaseImpl也套用。連帶修好GET /post/{semanticId}與 create / update 的回傳。Regex每次重新編譯9286428BLOG-117 update: cache the image extractor regexes用
std::sync::LazyLock<Regex>快取(IMAGE_REGEX,以及extract_image_ids內原本每次Regex::new()的 markdown regex);attach也改成每篇只解析 image id 一次,不再呼叫兩次。robots.txt未指向 sitemap3321cd4BLOG-117 add: sitemap directive to robots.txt已加上
Sitemap: /sitemap.xml,但用的是相對路徑而非建議的<APP_BASE_URL>/sitemap.xml:robots.txt是static/下的靜態檔,取不到PUBLIC_APP_BASE_URL。若要照建議用絕對 URL,得改成+server.tsroute 動態產生(或 hardcode production origin)。這點想先確認要走哪個方向。get_all_post_info都做,keyword 搜尋路徑之後才篩掉)image_ids未去重Vec行為,= ANY無害);要改HashSet隨時可以。feedDocument.ts同時設date與publisheddate是feed的Item型別必填欄位(供 Atom / JSON 輸出使用),RSS2 的pubDate由published覆蓋,因此沒有多餘行為。preview_image_url(非.../image/{id})沒有 DB 的 mime / size,就不產生 enclosure;舊 toolbox 是對該 URL 發 HEAD 取得。若要一致需另外設計。.vscode/ sqlx 空白 /sanitize-html).vscode/settings.json刪除為10a9d24、.sqlx快取檔改名來自9248643(UPDATE query 空白調整)、sanitize-htmlpatch 升版為9a98d64。如要縮小 PR 可另外拆出。補充:後端 CI
目前 workflows 只有
deployment.yaml、frontend-ci.yaml、pr-title-check.yaml,這支 PR 的 Rust 變更在 CI 並沒有被編譯。⏳ 未處理,建議另開 issue(或在本 PR 追加一個 backend CI job)。上述修改都已在本機驗證:
SQLX_OFFLINE=true cargo check / cargo clippy --all-targets / cargo test,以及bun run format / lint / check / build全部通過。Generated by Zed coding agent with Deepseek Flash