Skip to content

Commit

Permalink
Improve RSS feed image parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
George Stone authored and George Stone committed Sep 11, 2024
1 parent 1d08c21 commit 5cef493
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ input,
select,
textarea,
button {
font-family: InterVariable,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";
font-family: InterVariable,ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji",sans-serif;
}

h1,
Expand Down
17 changes: 10 additions & 7 deletions src/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ function cleanUpExpiredCache() {
}

function decodeHtmlEntities(str) {
return str
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&amp;', '&')
.replaceAll('&quot;', '"')
.replaceAll('&#39;', "'");
const entities = {
'&lt;': '<',
'&gt;': '>',
'&amp;': '&',
'&quot;': '"',
'&#39;': "'"
};

return str.replace(/&(lt|gt|amp|quot|#39);/g, (match, p1) => entities[match] || match);
}

function areDatesOnTheSameDay(date1, date2) {
Expand Down Expand Up @@ -84,7 +87,7 @@ function fetchFeed(url) {
let potentialImage;
if (content.innerHTML) {
placeholder.innerHTML = decodeHtmlEntities(content.innerHTML);
potentialImage = (item.getElementsByTagName("media:thumbnail").src) || (placeholder.querySelector("img") ? placeholder.querySelector("img").src : `https://logo.clearbit.com/${url.split("/")[2]}`);
potentialImage = (item.getElementsByTagName("media:thumbnail").src || item.getElementsByTagName("media:content")[0]?.getAttribute("url")) || (placeholder.querySelector("img") ? placeholder.querySelector("img").src : `https://logo.clearbit.com/${url.split("/")[2]}`);
} else {
placeholder.innerHTML = description ? description : new Date(item.querySelector("pubDate, published") ? item.querySelector("pubDate, published").textContent : "").toDateString();
potentialImage = item.getElementsByTagName("media:thumbnail")?.url || `https://logo.clearbit.com/${url.split("/")[2]}`;
Expand Down

0 comments on commit 5cef493

Please sign in to comment.