From 412d011c98cdf9951b858c529b83b4ded9ee7ca1 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Fri, 29 Oct 2021 02:01:44 +0100 Subject: [PATCH] Fix author links --- src/index.11tydata.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/index.11tydata.js b/src/index.11tydata.js index 1ee62ab..7937848 100644 --- a/src/index.11tydata.js +++ b/src/index.11tydata.js @@ -12,6 +12,19 @@ const DESCRIPTION_LENGTH = 200; global.feed_items = null; global.feed_authors_error = null; +function normalise_link_list(links) { + if(links instanceof Array) { + let links_temp = links.filter(link => link.rel != "self"); + if(links.length == 0) links = links[0]; + else links = links_temp[0]; + } + if(typeof(links) == "object") { + if(typeof(links.href) == "string") + links = links.href; + } + return links; +} + async function do_feeds() { const pReflect = (await import("p-reflect")).default; const dateformat = (await import("dateformat")).default; @@ -38,8 +51,9 @@ async function do_feeds() { item.author_name = feed.author_name; item.author_image = feed.author_image; item.parent = feed.data; - if(typeof(item.link) == "object" && typeof(item.link.href) == "string") - item.link = item.link.href; + + item.link = normalise_link_list(item.link); + item.parent.link = normalise_link_list(item.parent.link); if(!item.content) item.content = item["content:encoded"] || "";