mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
fix: include interaction target URL in timeline content
Interaction types with comment text (e.g. repost with a comment) were showing only the comment, losing the repost-of/bookmark-of/like-of URL. Now always includes the target URL for interaction types, combining it with any body text.
This commit is contained in:
@@ -290,49 +290,70 @@ export function createSyndicator(plugin) {
|
|||||||
// ─── Timeline helpers ───────────────────────────────────────────────────────
|
// ─── Timeline helpers ───────────────────────────────────────────────────────
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build content from JF2 properties. Synthesizes content for interaction
|
* Build content from JF2 properties for the ap_timeline entry.
|
||||||
* types (likes, bookmarks, reposts) that have no body text.
|
* For interaction types (likes, bookmarks, reposts), always includes
|
||||||
|
* the target URL — even when there's comment text alongside it.
|
||||||
*/
|
*/
|
||||||
function buildTimelineContent(properties) {
|
function buildTimelineContent(properties) {
|
||||||
const content = properties.content;
|
const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||||
if (content) {
|
|
||||||
if (typeof content === "string") return { text: content, html: `<p>${content}</p>` };
|
// Extract any existing body content
|
||||||
if (content.text || content.html) {
|
const raw = properties.content;
|
||||||
return {
|
let bodyText = "";
|
||||||
text: content.text || content.value || "",
|
let bodyHtml = "";
|
||||||
html: content.html || content.text || content.value || "",
|
if (raw) {
|
||||||
};
|
if (typeof raw === "string") {
|
||||||
|
bodyText = raw;
|
||||||
|
bodyHtml = `<p>${raw}</p>`;
|
||||||
|
} else {
|
||||||
|
bodyText = raw.text || raw.value || "";
|
||||||
|
bodyHtml = raw.html || raw.text || raw.value || "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synthesize for interaction types
|
// Interaction types: prepend label + target URL, append any comment
|
||||||
const esc = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
||||||
const likeOf = properties["like-of"];
|
const likeOf = properties["like-of"];
|
||||||
if (likeOf) {
|
if (likeOf) {
|
||||||
|
const prefix = `Liked: ${likeOf}`;
|
||||||
|
const prefixHtml = `<p>Liked: <a href="${esc(likeOf)}">${esc(likeOf)}</a></p>`;
|
||||||
return {
|
return {
|
||||||
text: `Liked: ${likeOf}`,
|
text: bodyText ? `${prefix}\n\n${bodyText}` : prefix,
|
||||||
html: `<p>Liked: <a href="${esc(likeOf)}">${esc(likeOf)}</a></p>`,
|
html: bodyText ? `${prefixHtml}\n${bodyHtml}` : prefixHtml,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const bookmarkOf = properties["bookmark-of"];
|
const bookmarkOf = properties["bookmark-of"];
|
||||||
if (bookmarkOf) {
|
if (bookmarkOf) {
|
||||||
const label = properties.name || bookmarkOf;
|
const label = properties.name || bookmarkOf;
|
||||||
|
const prefix = `Bookmarked: ${label}`;
|
||||||
|
const prefixHtml = `<p>Bookmarked: <a href="${esc(bookmarkOf)}">${esc(label)}</a></p>`;
|
||||||
return {
|
return {
|
||||||
text: `Bookmarked: ${label}`,
|
text: bodyText ? `${prefix}\n\n${bodyText}` : prefix,
|
||||||
html: `<p>Bookmarked: <a href="${esc(bookmarkOf)}">${esc(label)}</a></p>`,
|
html: bodyText ? `${prefixHtml}\n${bodyHtml}` : prefixHtml,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const repostOf = properties["repost-of"];
|
const repostOf = properties["repost-of"];
|
||||||
if (repostOf) {
|
if (repostOf) {
|
||||||
const label = properties.name || repostOf;
|
const label = properties.name || repostOf;
|
||||||
|
const prefix = `Reposted: ${label}`;
|
||||||
|
const prefixHtml = `<p>Reposted: <a href="${esc(repostOf)}">${esc(label)}</a></p>`;
|
||||||
return {
|
return {
|
||||||
text: `Reposted: ${label}`,
|
text: bodyText ? `${prefix}\n\n${bodyText}` : prefix,
|
||||||
html: `<p>Reposted: <a href="${esc(repostOf)}">${esc(label)}</a></p>`,
|
html: bodyText ? `${prefixHtml}\n${bodyHtml}` : prefixHtml,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Regular post — return body content as-is
|
||||||
|
if (bodyText || bodyHtml) {
|
||||||
|
return { text: bodyText, html: bodyHtml };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Article with title but no body
|
||||||
if (properties.name) {
|
if (properties.name) {
|
||||||
return { text: properties.name, html: `<p>${esc(properties.name)}</p>` };
|
return { text: properties.name, html: `<p>${esc(properties.name)}</p>` };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { text: "", html: "" };
|
return { text: "", html: "" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rmdes/indiekit-endpoint-activitypub",
|
"name": "@rmdes/indiekit-endpoint-activitypub",
|
||||||
"version": "3.10.2",
|
"version": "3.10.3",
|
||||||
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
"description": "ActivityPub federation endpoint for Indiekit via Fedify. Adds full fediverse support: actor, inbox, outbox, followers, following, syndication, and Mastodon migration.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"indiekit",
|
"indiekit",
|
||||||
|
|||||||
Reference in New Issue
Block a user