Skip to content

feat(rss2): allow explicit override of guid isPermaLink attribute - #253

Open
mmilanovic4 wants to merge 1 commit into
jpmonette:mainfrom
mmilanovic4:feat/explicit-is-permalink
Open

feat(rss2): allow explicit override of guid isPermaLink attribute#253
mmilanovic4 wants to merge 1 commit into
jpmonette:mainfrom
mmilanovic4:feat/explicit-is-permalink

Conversation

@mmilanovic4

Copy link
Copy Markdown
Contributor

Closes #191

Problem

The isPermaLink attribute on the RSS 2.0 <guid> element is currently inferred purely from which fields are set on an item, with no way to override it:

if (entry.guid) item.guid = { _text: entry.guid, _attributes: { isPermaLink: false } };
else if (entry.id) item.guid = { _text: entry.id, _attributes: { isPermaLink: false } };
else if (entry.link) item.guid = { _text: sanitizeUrl(entry.link), _attributes: { isPermaLink: true } };

This breaks down in two real cases:

  • id/link is a genuine, permanent URL, but setting id currently forces isPermaLink="false" anyway.
  • id is an opaque, non-URL identifier (e.g. a UUID) and a link is also present — there's currently no way to force isPermaLink="false" without dropping link entirely, which is the case raised in Way to set guid isPermaLink attribute #191.

Solution

Adds an optional isPermaLink?: boolean field on Item. When set, it takes precedence over the existing inference:

feed.addItem({
  title: post.title,
  id: post.url,
  link: post.url,
  isPermaLink: true, // guid is a real permalink, force isPermaLink="true"
  // ...
});

When omitted, behavior is fully unchanged — this is a non-breaking, additive change.

Testing

Added 4 new tests in an isolated describe block, using createSampleFeed() rather than the shared, accumulating sampleFeed fixture (so they don't shift snapshot output for other tests):

  • explicit isPermaLink: true with id/link set → isPermaLink="true"
  • explicit isPermaLink: false with only link set → isPermaLink="false"
  • no isPermaLink + guid set → still defaults to isPermaLink="false" (no regression)
  • no isPermaLink + only link set → still defaults to isPermaLink="true" (no regression)

pnpm build, pnpm lint, and pnpm test all pass locally (32/32 tests, no snapshot changes to existing tests).

Related

Closes #191

Currently the isPermaLink attribute on RSS 2.0 <guid> is inferred purely
from which fields are set (guid/id/link), with no way to override it:

  - guid or id present -> isPermaLink="false"
  - only link present  -> isPermaLink="true"

This breaks down in two common cases:
  - id/link is a real, permanent URL, but because id is also set,
    isPermaLink is forced to "false" (see e.g. discussion in jpmonette#191).
  - id is an opaque, non-URL identifier, but a link is also present,
    so there's no way to force isPermaLink="false" without dropping link.

This adds an optional isPermaLink?: boolean field on Item that, when
set, takes precedence over the existing inference. When omitted,
behavior is unchanged (fully backwards compatible).

Related: jpmonette#191, jpmonette#89, jpmonette#213
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.

Way to set guid isPermaLink attribute

1 participant