fix(core): index images inside Portable Text gallery blocks for media usage - #3096
Open
dchaudhari7177 wants to merge 1 commit into
Open
fix(core): index images inside Portable Text gallery blocks for media usage#3096dchaudhari7177 wants to merge 1 commit into
dchaudhari7177 wants to merge 1 commit into
Conversation
… usage The media usage extractor read only top-level image blocks in Portable Text, so the images in a core gallery block (content[n].images[i].asset) were never indexed. A media item used only in galleries showed an empty "Used in" list and a complete coverage state, and looked unused. Gallery images now produce portable_text_image occurrences whose field path points into the gallery, through the same asset-ref handling as image blocks. Closes emdash-cms#2872
🦋 Changeset detectedLatest commit: 1d1a4d0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The media usage extractor only looked at top-level
_type: "image"Portable Text blocks, so images inside a coregalleryblock (content[n].images[i].asset) were never indexed. A media item used only in galleries showed an empty "Used in" list with coveragecomplete, and so looked safe to delete.extractPortableTextOccurrencesnow also walksgalleryblocks. Each image's asset goes through the same ref handling as an image block (factored intoaddPortableTextAssetOccurrence):_reforid, provider, MIME and the external-URL skip all behave identically. I took the second option from the issue: the existingportable_text_imagereference type, with afield_pathpointing into the gallery (body[1].images[0].asset._ref). That needs no change to the reference-type enum, the API schema ornormalizeMediaUsageReferenceType.Closes #2872
One question for you. Sites that already built their usage index keep their old rows until the affected content is refreshed, so gallery-only media stays "unused" there until then.
CONTENT_SOURCE_SCHEMA_VERSIONlooks like the switch that marks scopesstale, but it is the content-source schema version, and I didn't want to bump a shared version just for an extractor change. Happy to add whatever re-index trigger you prefer.Type of change
Checklist
pnpm typecheckpasses: not run astsgo; the change is confined toextractor.tstypes already in usepnpm lintpasses:oxlint --deny-warningson the touched filespnpm testpasses (or targeted tests for my change)pnpm formathas been run:oxfmtAI-generated code disclosure
Screenshots / test output
Not applicable (indexer). New cases in
packages/core/tests/unit/media/usage-extractor.test.ts:_refimage, a Cloudflare Imagesidimage, an external-URL image, an image with no asset, and a non-object entry, plus a second gallery whoseimagesis malformed. Only the two real references come out, with pathsbody[1].images[0].asset._refandbody[1].images[1].asset.id;tests/unit/mediaplusmedia-usage-content-refreshandmedia-usage-read-repositoryintegration tests: 18 files, 182 passed.