Skip to content

Commit

Permalink
Feed Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofzerbe committed Aug 12, 2024
1 parent f4c4bee commit cc5498e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 23 additions & 17 deletions scripts/generators/generator-dynamic-blogroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,31 @@ hexo.extend.generator.register("dynamic-blogroll", async function(locals) {
item.feedSize = `${feedSize.toFixed(2)} KB`
}
// console.log(item.title + ": " + item.feedSize);
// console.log(response.status);

feed2json.fromString(response.data, item.feed, { log: false }, (error, json) => {
if (response.status === 200) {
feed2json.fromString(response.data, item.feed, (error, json) => {

if (!error) {
// json.items.sort((a,b) => a.date_published - b.date_published).reverse();
json.items.sort((a,b) => _helpers.moment(a.date_published).diff(b.date_published)).reverse();

item.feedLength = json.items.length;

let feedItem = json.items[0];
item.latest_post = {
"url": feedItem.url,
"title": feedItem.title || "- no title -",
"date_published": feedItem.date_published
};
} else {
log.error("Parsing feed from " + item.title + " failed");
}
});
if (!error) {
// json.items.sort((a,b) => a.date_published - b.date_published).reverse();
json.items.sort((a,b) => _helpers.moment(a.date_published).diff(b.date_published)).reverse();

item.feedLength = json.items.length;

let feedItem = json.items[0];
item.latest_post = {
"url": feedItem.url,
"title": feedItem.title || "- no title -",
"date_published": feedItem.date_published
};
} else {
log.error("Parsing feed from " + item.title + " failed");
}
});
} else {
log.error("Fetching feed from " + item.title + " responded with status " + response.status);
item.errorStatus = response.status;
}
resolve();
}).catch(err => {
log.error("Fetching feed from " + item.title + " failed");
Expand Down
2 changes: 2 additions & 0 deletions themes/landscape/layout/blogroll.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
<span><%= new Date(item.latest_post.date_published).toLocaleString('en-GB', { year:"numeric", month:"long", day:"numeric"}) ?? "---" %></span>:
</small>
<a href="<%= item.latest_post.url %>"><%= item.latest_post.title %></a>
<% } else if (item.errorStatus) { %>
<small class="label">Error <%= item.errorStatus %> while fetching the feed. Tryin' again tomorrow...</small>
<% } else { %>
<small class="label">Failed to read the feed. Tryin' again tomorrow...</small>
<% } %>
Expand Down

0 comments on commit cc5498e

Please sign in to comment.