Skip to content

[codex] Share redirect URL normalization - #209

Merged
big-mon merged 2 commits into
mainfrom
codex/issue-203-redirects
Jun 23, 2026
Merged

[codex] Share redirect URL normalization#209
big-mon merged 2 commits into
mainfrom
codex/issue-203-redirects

Conversation

@big-mon

@big-mon big-mon commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #203.

  • Move URL segment helpers into a shared JS module so Astro code and the redirect generator use the same tag/category/slug normalization.
  • Replace the hand-written redirect frontmatter parsing with @estrivault/content-processor metadata extraction, which uses gray-matter internally.
  • Collapse generated _redirects rules from per-post/per-tag/per-category enumeration into placeholder-based canonical rules.

Redirect behavior

The generated _redirects file now has 34 lines instead of 720. This is an intentional behavior change: category and tag archive trailing-slash redirects are preserved with placeholder rules, while post/note document proxy and trailing-slash redirects are generalized by slug.

This means generic rules may match non-existent slugs too; those should still resolve to 404 when the backing asset is absent.

Validation

  • pnpm --filter astro-blog run generate:redirects
  • pnpm type-check
  • git diff --check
  • git diff --find-renames -- content/blog
  • URL正規化ロジックの共有化: アプリケーションのスラッグ生成・タグ/カテゴリ正規化処理を、url-segments.mjs の共通ヘルパーに統一し、リダイレクト生成スクリプトで同じロジックを再利用できるようにした(コード重複の排除と保守性向上)

  • リダイレクト定義の簡略化: _redirects ファイルを個別スラッグ列挙型から、プレースホルダベースの宣言型ルール(:category:tag:slug など)に変更し、720行から34行に削減した(保守性向上・可読性改善)

  • Frontmatter解析の置き換え: カスタムフロントマター解析をメタデータ抽出用の標準ヘルパーに統一し、記事・メモのスラッグ生成を共通の getSlugFromMarkdownPath で一元化した(実装の統一・冗長性排除)

  • アーカイブページング: リダイレクト生成時に公開済み記事数に基づいてアーカイブのページ数を動的に計算し、固定的な個別ルールではなく計算ベースのプレースホルダルールで対応するようにした(スケーラビリティ向上・自動化)

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11c4ee28-8592-42a0-ae59-f13b6342de0f

📥 Commits

Reviewing files that changed from the base of the PR and between 633a889 and aa15b4d.

📒 Files selected for processing (6)
  • apps/astro-blog/scripts/generate-redirects.mjs
  • apps/astro-blog/src/lib/content.ts
  • apps/astro-blog/src/lib/url-segments.mjs
  • apps/astro-blog/src/lib/url-segments.ts
  • apps/astro-blog/src/pages/category/[category]/[...page].astro
  • apps/astro-blog/src/pages/sitemap.xml.ts

📝 Walkthrough

Walkthrough

url-segments.mjs を新規作成し、getTagRouteSegmentgetCategoryRouteSegmentencodeRouteSegmentgetSlugFromMarkdownPathgetArchivePagePathgetArchivePageUrl を実装した。url-segments.ts はその再エクスポートに全面置き換えられ、getCategoryRouteSegmentgetSlugFromMarkdownPath が新たに公開された。content.ts のローカル generateSlugFromPath を削除して getSlugFromMarkdownPath に統一。カテゴリページと sitemap.xml.ts もそれぞれ共有ヘルパーを使う形に変更。generate-redirects.mjs は個別スラッグ列挙型から、公開記事数ベースのアーカイブページ数算出とプレースホルダテンプレート行出力へ再実装された。

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-203-redirects

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@big-mon

big-mon commented Jun 23, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 23, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
estrilda aa15b4d Commit Preview URL

Branch Preview URL
Jun 23 2026, 04:53 AM

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b711c7107

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

return lines;
return meta.draft !== true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3 Badge Match Astro's draft filtering when counting posts

When a post uses quoted frontmatter such as draft: "true", gray-matter returns a string; extractMetadata passes that through, while the Astro content loader drops drafts with a truthy check (apps/astro-blog/src/lib/content.ts line 238). This strict comparison counts that post as published, so _redirects can emit root pagination redirects for pages Astro does not generate once drafts affect the 12-post boundary. Use the same truthy draft check here.

Useful? React with 👍 / 👎.

@big-mon
big-mon marked this pull request as ready for review June 23, 2026 04:53
@big-mon
big-mon merged commit 9e41e30 into main Jun 23, 2026
3 checks passed
@big-mon
big-mon deleted the codex/issue-203-redirects branch June 23, 2026 04:53
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.

astro-blog: _redirects 生成を共有ロジックまたは標準パーサへ寄せる

1 participant