Skip to content

Commit

Permalink
MentionsUnited: Multiple syndication for Pixeldfed
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofzerbe committed Oct 28, 2024
1 parent 40f246e commit 39c1f20
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
6 changes: 4 additions & 2 deletions scripts/generators/generator-dynamic-blogroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ hexo.extend.generator.register("dynamic-blogroll", async function(locals) {
} else {
log.error("Fetching feed from " + item.title + " responded with status " + response.status);
item.errorStatus = response.status;
if (item.errorStatus === 403) { console.log(response); }
if (item.errorStatus === 403) {
//console.log(response);
}
}
resolve();
}).catch(err => {
log.error("Fetching feed from " + item.title + " failed");
console.log(err);
//console.log(err);
resolve(); // Resolve anyway, to suppress errors
});
}));
Expand Down
19 changes: 11 additions & 8 deletions themes/landscape/layout/_partial/post/interaction.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%
let syndications = post.syndication?.filter(s => s.url?.length > 0 && s.host?.length > 0)
let synDevTo = syndications?.find(s => s.host.toLowerCase() === "devto");
let synPixelfed = syndications?.find(s => s.host.toLowerCase() === "pixelfed");
let synPixelfed = syndications?.filter(s => s.host.toLowerCase() === "pixelfed");
let synLemmy = syndications?.filter(s => s.host.toLowerCase() === "lemmy");
//console.log("---------------\n" + post.title + ": " + synPixelfed.length);
%>
<div class="article-share" data-pagefind-ignore>
Expand Down Expand Up @@ -56,7 +59,7 @@
<%- js('js/mentions-united-renderer_avatars-by-type.js') %>
<%- js('js/mentions-united-renderer_list.js') %>
<% if (synDevTo) { %><%- js('js/mentions-united-provider_devto.js'); %><% } %>
<% if (synPixelfed) { %><%- js('js/mentions-united-provider_pixelfed.js'); %><% } %>
<% if (synPixelfed?.length > 0) { %><%- js('js/mentions-united-provider_pixelfed.js'); %><% } %>
<script>
window.addEventListener('load', function () {
Expand Down Expand Up @@ -101,12 +104,12 @@
}));
<% } %>
<% if (synPixelfed) { %>
mentionsUnited.register(new MentionsUnitedProvider_Pixelfed({
sourceUrl: "<%- synPixelfed.url %>",
apiBaseUrl: "<%- config.api_proxy_base_url %>/pixelfed"
}));
<% } %>
<% synPixelfed?.forEach(syn => { %>
mentionsUnited.register(new MentionsUnitedProvider_Pixelfed({
sourceUrl: "<%- syn.url %>",
apiBaseUrl: "<%- config.api_proxy_base_url %>/pixelfed"
}));
<% }); %>
mentionsUnited.load()
.then(() => {
Expand Down
23 changes: 20 additions & 3 deletions themes/landscape/source/js/mentions-united.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Mentions United main class
*
* @author Kristof Zerbe
* @version 1.0.0
* @version 1.0.1
* @see {@link https://github.com/kristofzerbe/MentionsUnited|GitHub}
*
* This script relies on two different types of plug-ins: PROVIDER and RENDERER,
Expand Down Expand Up @@ -100,9 +100,11 @@ class MentionsUnited {
* @param {MentionsUnited plugin class} plugin
*/
register(plugin) {
const { key } = plugin;
let { key } = plugin;

if (plugin instanceof MentionsUnited.Provider) {
let pCount = this.helper.countAttributesByName(this.#providers, key);
if (pCount > 0) key += "_" + (pCount + 1);
this.#providers[key] = plugin;
}

Expand Down Expand Up @@ -256,12 +258,27 @@ class MentionsUnited {
capitalize(value) {
return (value && value[0].toUpperCase() + value.slice(1)) || "";
}

/**
* Count attributes of given object by name which includes namePart
* @param {Object} obj
* @param {String} namePart
*/
countAttributesByName(obj, namePart) {
let count = 0;
for(var name in obj) {
if (name.includes(namePart)) count += 1;
}
return count;
}

}

}
/**
* Changelog
*
* 1.0.0 - Initial
* 1.0.0 - Initial
* 1.0.1 - new helper 'countAttributesByName' for making keys unique in constructor,
* when Provider plugin is registered multiple times with different URL's
*/

0 comments on commit 39c1f20

Please sign in to comment.