feat: add getSyndicationUrl hook to syndicator interface - #882
aciccarello wants to merge 4 commits into
Conversation
getSyndicationUrl hook to syndicator interface
67b3847 to
fa1d368
Compare
|
The hook solves the ordering problem in the right place — running it in One thing worth surfacing, because this PR works around it without naming it. const targetOrigin = new URL(target.info.uid).origin;
const syndicateToOrigin = new URL(syndicateTo).origin;
return targetOrigin === syndicateToOrigin;IndieNews registers one target per language on a single origin, so those collapse into one. With This PR matches Smaller point: |
Indiekit selects a syndication target by comparing URL origins, and every IndieNews language shares one. A request for `https://news.indieweb.org/fr` is therefore handed to whichever IndieNews target registered first, which is usually the English one. That is not only a wrong label. The webmention names the channel it is submitted to, and IndieNews requires the post to link to that same channel, so a post carrying a `u-syndication` link to `/fr` submitted with a target of `/en` is rejected. Read the language back out of `mp-syndicate-to`, which Indiekit passes to `syndicate()`, and fall back to the configured one when no IndieNews target was requested. This covers one language per post. Requesting two in a single post still loses the second: `hasSyndicationUrl` also compares origins, so once one IndieNews permalink is recorded the rest are treated as already syndicated. That needs the exact matching proposed upstream in getindiekit/indiekit#882. Adds the first tests for this package, run with `node --test`.
|
That's a good point about But the same-origin issue needs to be addressed better. I was thinking syndication targets should be able to match themselves using their own logic with the origin check as a fallback. This would probably look like another method hook on the targets. So the indienews targets would match the whole URL, while other syndicators can match more loosely. But I'm not sure that's really needed. The alternative would be to move all syndicators to match the URL completely. Since the syndicators are setting the UID themselves, I believe that should be fine, no? The difficult logic is the "hasSyndicationUrl" which checks the processed syndication URL for pre-existing values. The url for the post isn't going to match the UID for the syndicator, at least not exactly. To address the IndieNews case, a more general string includes match over checking the origin might be suffice. But I'm not 100% sure about that. Still, it seems better than needlessly complicating the syndication target API. In summary I'm proposing:
|
|
Both moves make sense, and sharing the two helpers between One caution on swapping the origin check for "URL contains the UID": it doesn't fix the IndieNews case I described on #880. The pre-submission link is exactly What would fix it is distinguishing "a syndication value pointing at this target" from "a syndication value this target produced". |
Closes #860
Summary
Adds an optional
getSyndicationUrl(publication)hook to the syndicator plugin interface, enabling syndication URLs to be written into post files at creation time — without requiring a database or async syndication step.This is needed for webmention-based syndication targets where the syndication URL is known at post creation time, but
mp-syndicate-tois stripped before the file is written (correct per the Micropub spec — it is a server command, not a content property).Changes
endpoint-syndicatesyndicate()is now optional on syndicator targets. Targets without it are skipped rather than throwing. This allows syndicators that only implementgetSyndicationUrl()to register without providing an empty no-op.endpoint-micropubpost-content.jscreate(), after resolving syndication targets and beforegetPostTemplateProperties()stripsmp-*keys, callsgetSyndicationUrl(publication)on any target whoseinfo.uidis inmp-syndicate-to.syndicationvalues (exact string match), and appended toproperties.syndication.getSyndicationUrl()are caught and logged viadebug()— the create request is never failed.Interface
A syndicator implementing this hook can return the syndication URL synchronously at post creation time. The endpoint handles appending it to
syndicationbefore the file is written.This is scoped to
create()only. Update behaviour is a separate concern.