Skip to content

Commit

Permalink
Refactoring interactions source.title + syndication text
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofzerbe committed Nov 1, 2024
1 parent 45bc47c commit 3328be2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 42 deletions.
9 changes: 5 additions & 4 deletions themes/landscape/layout/_partial/post/interaction.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
<div id="send-webmention" class="article-webmention" data-pagefind-ignore>
<p>
You can interact with this <%= type %> (applause, criticism, whatever) by mention it in one of
your posts and sending <a href="https://indieweb.org/Webmention">Webmention</a> or
by replying to one of its syndications above, most of which are displayed here as an interaction.
You can interact with this <%= type %> (applause, criticism, whatever) by mention it in one of your posts
and sending a <a href="https://indieweb.org/Webmention">Webmention</a><% if(syndications) { %> or by replying to one of its syndications above, most of which are displayed here as an interaction<% } %>.
</p>
<form class="webmention-form" name="webmention-form" method="post"
Expand Down Expand Up @@ -106,13 +105,15 @@
<% synPixelfed?.forEach(syn => { %>
mentionsUnited.register(new MentionsUnitedProvider_Pixelfed({
sourceUrl: "<%- syn.url %>",
sourceTitle: "<%- syn.title %>",
apiBaseUrl: "<%- config.api_proxy_base_url %>/pixelfed"
}));
<% }); %>
<% synLemmy?.forEach(syn => { %>
mentionsUnited.register(new MentionsUnitedProvider_Lemmy({
sourceUrl: "<%- syn.url %>"
sourceUrl: "<%- syn.url %>",
sourceTitle: "<%- syn.title %>"
}));
<% }); %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class MentionsUnitedProvider_NAME extends MentionsUnited.Provider {
r.source.sender = this.key;
// r.source.url = entry...;
// r.source.id = entry...;
// r.source.title = entry...;

// r.author.name = entry...;
// r.author.avatar = entry...;
Expand Down
4 changes: 3 additions & 1 deletion themes/landscape/source/js/mentions-united-provider_devto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Mentions United Provider plugin class for retreiving interaction from DevTo
*
* @author Kristof Zerbe
* @version 1.0.1
* @version 1.0.2
* @see {@link https://github.com/kristofzerbe/MentionsUnited|GitHub}
*
* API Documentation: https://developers.forem.com/api/v1
Expand Down Expand Up @@ -99,6 +99,7 @@ class MentionsUnitedProvider_DevTo extends MentionsUnited.Provider {
r.source.sender = this.key;
r.source.url = this.options.sourceUrl;
r.source.id = this.sourceId;
r.source.title = "";

r.author.name = entry.user.name;
r.author.avatar = entry.user.profile_image_90;
Expand Down Expand Up @@ -133,4 +134,5 @@ class MentionsUnitedProvider_DevTo extends MentionsUnited.Provider {
*
* 1.0.0 - Initial
* 1.0.1 - No data fix -> #processJsonData: entries not iterable
* 1.0.2 - Set source.title explicit to empty
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
* Mentions United Provider plugin class for retreiving interactions from Pixelfed
*
* @author Kristof Zerbe
* @version 1.0.0
* @version 1.0.1
* @see {@link https://github.com/kristofzerbe/MentionsUnited|GitHub}
*
* API Documentation: There is no proper API documentation, but the source code is freely available at:
* https://github.com/pixelfed/pixelfed/blob/dev/app/Http/Controllers/Api/ApiV1Controller.php
*
* Options:
* - {String} sourceUrl = Full URL of the mentioning page on Pixelfed
* - {String} sourceTitle = Title of the post on Pixelfed, if multiple
* - {String} [apiBaseUrl] = Base URL of API proxy, if existing
* - {String} [apiTokenReadOnly] = Token to access Pixelfed's API in Read-Only mode, if no proxy
*
Expand Down Expand Up @@ -42,6 +43,7 @@ class MentionsUnitedProvider_Pixelfed extends MentionsUnited.Provider {

options = {
sourceUrl: "",
sourceTitle: "",
apiBaseUrl: "",
apiTokenReadOnly: ""
}
Expand Down Expand Up @@ -140,6 +142,7 @@ class MentionsUnitedProvider_Pixelfed extends MentionsUnited.Provider {
r.source.sender = this.key;
r.source.url = this.options.sourceUrl;
r.source.id = entry.id;
r.source.title = this.options.sourceTitle;

r.author.name = (type === "reply") ? entry.account.display_name : entry.display_name;
r.author.avatar = (type === "reply") ? entry.account.avatar : entry.avatar;
Expand All @@ -154,5 +157,6 @@ class MentionsUnitedProvider_Pixelfed extends MentionsUnited.Provider {
/**
* Changelog
*
* 1.0.0 - Initial
* 1.0.0 - Initial
* 1.0.1 - Introduction of 'sourceTitle', to be able to distinguish several Pixelfed sources textually
*/
73 changes: 38 additions & 35 deletions themes/landscape/source/js/mentions-united-renderer_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Mentions United Renderer plugin for displaying Interactions as a list
*
* @author Kristof Zerbe
* @version 1.0.0
* @version 1.0.1
* @see {@link https://github.com/kristofzerbe/MentionsUnited|GitHub}
*
* Options:
Expand Down Expand Up @@ -146,9 +146,7 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {

let parts = {};
parts.received = this.#part_received(ia);
parts.source = (ia.source.origin === "web")
? this.#part_origin_title(ia)
: this.#part_origin(ia);
parts.source = this.#part_origin(ia);
parts.content = (ia.content.html)
? this.#part_content_html(ia)
: this.#part_content_text(ia);
Expand All @@ -166,9 +164,7 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {

let parts = {};
parts.received = this.#part_received(ia);
parts.source = (ia.source.origin === "web")
? this.#part_origin_title(ia)
: this.#part_origin(ia);
parts.source = this.#part_origin(ia);
parts.content = (ia.content.html)
? this.#part_content_html(ia)
: this.#part_content_text(ia);
Expand All @@ -186,9 +182,7 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {

let parts = {};
parts.received = this.#part_received(ia);
parts.source = (ia.source.origin === "web")
? this.#part_origin_title(ia)
: this.#part_origin(ia);
parts.source = this.#part_origin(ia);
parts.content = (ia.content.text)
? this.#part_content_text_excerpt(ia)
: "";
Expand All @@ -207,7 +201,7 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {
let parts = {};
parts.received = this.#part_received(ia);
parts.source = (ia.source.origin === "web")
? this.#part_origin_title(ia)
? this.#part_origin(ia)
: "";

return this.#base(ia, parts);
Expand Down Expand Up @@ -327,33 +321,41 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {
}

/**
* Template part for origin
* Template part for origin with or without title
* @param {MentionsUnited.Interaction} ia
*/
#part_origin(ia) {
return this.helper.fillLiteralTemplate(
`
<span class="prep">on</span>
<a href="${ia.source.url}" class="origin">${this.helper.capitalize(ia.source.origin)}</a>
`,
ia
);
}

/**
* Template part for origin with post (title)
* @param {MentionsUnited.Interaction} ia
*/
#part_origin_title(ia) {
return this.helper.fillLiteralTemplate(
`
<span class="prep">in</span>
<a href="${ia.source.url}" class="title">${ia.source.title}</a>
<span class="prep">on</span>
<span class="origin">${ia.source.sender}</span>
`,
ia
);
if (ia.source.origin === "web") {
return this.helper.fillLiteralTemplate(
`
<span class="prep">in</span>
<a href="${ia.source.url}" class="title">${ia.source.title}</a>
<span class="prep">on</span>
<span class="origin">${ia.source.sender}</span>
`,
ia
);
} else {
if (ia.source.title && ia.source.title.length != 0) {
return this.helper.fillLiteralTemplate(
`
<span class="prep">on</span>
<a href="${ia.source.url}" class="origin">${this.helper.capitalize(ia.source.origin) + " (" + ia.source.title + ")"}</a>
`,
ia
);
} else {
return this.helper.fillLiteralTemplate(
`
<span class="prep">on</span>
<a href="${ia.source.url}" class="origin">${this.helper.capitalize(ia.source.origin)}</a>
`,
ia
);
}
}

}

/**
Expand Down Expand Up @@ -405,5 +407,6 @@ class MentionsUnitedRenderer_List extends MentionsUnited.Renderer {
/**
* Changelog
*
* 1.0.0 - Initial
* 1.0.0 - Initial
* 1.0.1 - Refactored '#part_origin', including title depending on origin
*/

0 comments on commit 3328be2

Please sign in to comment.