fix(ui): skip README badge markdown in package card summaries#2775
fix(ui): skip README badge markdown in package card summaries#2775Adebesin-Cell wants to merge 3 commits into
Conversation
Closes npmx-dev#2767. npm's search API sometimes returns the README's leading badge markdown as the package description (e.g. @nuxtjs/opencollective). Extends the markdown stripper to handle reference-style image badges and collapses the side-column metadata into a single flex-wrap row so the card layout stays consistent when the description ends up empty. Also drops the duplicated mobile downloads row.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughRefactors markdown image stripping to remove reference-style badge and image markdown, adds regression tests, and consolidates the Package Card metadata into a single definition list with a new ChangesPackage Card Summary and Layout
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/components/Package/Card.vue`:
- Line 113: The template currently uses a truthy check on
result.downloads?.weekly in the div's v-if which hides a valid 0 value; update
the v-if on that div (the element referencing result.downloads?.weekly) to use a
null/undefined check (i.e., render when weekly is not null/undefined) so that 0
will still display.
🪄 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: b26355cf-2c9f-4bb1-8961-a9cb36a5ed69
📒 Files selected for processing (2)
app/components/Package/Card.vuei18n/schema.json
| <dt class="sr-only">{{ $t('package.card.license') }}</dt> | ||
| <dd>{{ result.package.license }}</dd> | ||
| </div> | ||
| <div v-if="result.downloads?.weekly" class="flex items-center gap-1.5 sm:ms-auto"> |
There was a problem hiding this comment.
Render weekly downloads when the value is 0
v-if="result.downloads?.weekly" hides a valid 0 value. Use a nullish check so zero still renders.
Suggested patch
- <div v-if="result.downloads?.weekly" class="flex items-center gap-1.5 sm:ms-auto">
+ <div v-if="result.downloads?.weekly != null" class="flex items-center gap-1.5 sm:ms-auto">📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| <div v-if="result.downloads?.weekly" class="flex items-center gap-1.5 sm:ms-auto"> | |
| <div v-if="result.downloads?.weekly != null" class="flex items-center gap-1.5 sm:ms-auto"> |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@app/components/Package/Card.vue` at line 113, The template currently uses a
truthy check on result.downloads?.weekly in the div's v-if which hides a valid 0
value; update the v-if on that div (the element referencing
result.downloads?.weekly) to use a null/undefined check (i.e., render when
weekly is not null/undefined) so that 0 will still display.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
app/components/Package/Card.vue (1)
113-113:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winRender weekly downloads when the value is
0.The current truthy check hides valid zero downloads. Use a nullish check to ensure zero still renders.
🔧 Proposed fix
- <div v-if="result.downloads?.weekly" class="flex items-center gap-1.5 sm:ms-auto"> + <div v-if="result.downloads?.weekly != null" class="flex items-center gap-1.5 sm:ms-auto">🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@app/components/Package/Card.vue` at line 113, The v-if currently hides valid zero values because it checks truthiness on result.downloads?.weekly; change the condition to a nullish check so 0 still renders, e.g. replace the v-if on the element that references result.downloads?.weekly with a check like result.downloads?.weekly != null (or result.downloads && result.downloads.weekly != null) so the node renders when weekly is 0 but stays hidden when weekly is null/undefined.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@app/components/Package/Card.vue`:
- Line 113: The v-if currently hides valid zero values because it checks
truthiness on result.downloads?.weekly; change the condition to a nullish check
so 0 still renders, e.g. replace the v-if on the element that references
result.downloads?.weekly with a check like result.downloads?.weekly != null (or
result.downloads && result.downloads.weekly != null) so the node renders when
weekly is 0 but stays hidden when weekly is null/undefined.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a598e92e-6174-4379-9a05-7a8bdc0236de
📒 Files selected for processing (1)
app/components/Package/Card.vue
Closes #2767.
Problem
When a package has no
descriptionin itspackage.json, npm's search API falls back to the README's leading content. For READMEs that start with badge markdown, the raw markdown leaks into the card (e.g.@nuxtjs/opencollectiveshows[![npm version][npm-v-src]][npm-v-href] ...).Fix
stripMarkdownImagesinuseMarkdownto also handle reference-style image badges (![alt][ref],[![alt][ref]][ref],[][ref], etc.) and orphan reference link definitions ([ref]: url). Refactored to one alternation + fixed-point loop so any nesting collapses without a per-shape regex.Card.vuemetadata into a single flex-wrap row (version → provenance → publisher → date → license → downloadswithsm:ms-autopinning downloads to the right). Removed the duplicated mobile downloads row.Test plan
pnpm test test/nuxt/composables/use-markdown.spec.ts), including 4 new regression tests for Package summary falls back to raw README markdown (badges/images) when no description is set #2767/search?q=@nuxtjs/opencollective,/search?q=vite,/org/nuxtjs