リンクカード フォールバック処理を追加#9958
Conversation
既存のテストは、「og:urlが存在しない」のではなく、「og:urlが""」なことで失敗していた。
📝 WalkthroughWalkthroughOpenGraphReader の parse 結果が nil の場合に、meta タグから title、description、images、site_name を抽出する fallback パスを追加。favicon 抽出ロジックも調整され、test ファイルで empty/missing og:url シナリオのカバレッジが拡張。 Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@app/models/metadata.rb`:
- Around line 67-85: The fallback_* helpers stop the fallback chain when a meta
tag returns an empty string because they use ||; change each method
(fallback_title, fallback_description, fallback_images, fallback_site_name) to
call .presence on the card_content() result (and on the secondary extraction if
needed) so empty strings are treated as nil and the chain continues (e.g. use
card_content(doc, 'title').presence ||
doc.at_css('title')&.text&.strip.presence). Update fallback_title,
fallback_description, fallback_images, fallback_site_name and keep card_content
as-is.
In `@test/system/markdown_test.rb`:
- Line 155: The assertion uses the wrong href: replace the hardcoded selector
string 'a.before-replacement-link-card[href="https://bootcamp.fjord.jp/"]' in
the test (test/system/markdown_test.rb) with the actual URL used as input in
this test (e.g. 'https://ja.wikipedia.org/wiki/日本語') or reference the
variable/fixture that holds the test URL so assert_no_selector checks the same
link the test inserted; ensure the selector matches
'a.before-replacement-link-card[href="https://ja.wikipedia.org/wiki/日本語"]' (or
the variable) so the test fails if the pre-replacement link remains.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cf1544f4-50a5-4f8e-a347-6f46dc792463
📒 Files selected for processing (2)
app/models/metadata.rbtest/system/markdown_test.rb
🚀 Review AppURL: https://bootcamp-pr-9958-fvlfu45apq-an.a.run.app
|
| url: @url, | ||
| site_url: site_url | ||
| } | ||
| return nil if metadata[:title].blank? |
There was a problem hiding this comment.
issueにある通り、titleがなければリンクカードの展開を失敗させます。
(urlはユーザー入力である@[card](url)のurlをそのまま流用しているのでtitleのみのチェックとしています)
#9920 (comment)
GemのOGP取得に失敗した場合フォールバック処理をする。
基本的にmetadataのプロパティは全て埋めるようにする。
ただしリンクカードとして必須のプロパティであるtitle、image, urlが揃っていなければカードの展開を失敗させる。
imageは必須ではないのではないかと思いました。
|
@mousu-a |


Issue
概要
このPRは
https://ja.wikipedia.org/wiki/日本語のURLがリンクカードとして展開できないバグを修正するものです。リンクカードでOGPを取得する際、OGP取得に使っているGemが
nilを返す場合のフォールバック処理を追加しました。変更確認方法
bug/fix-link-card-expansion-opengraph-fallbackをローカルに取り込み、チェックアウトbin/devでサーバーを起動Screenshot
変更前
変更後
Summary by CodeRabbit
リリースノート