Make the 'last updated' time relative

This commit is contained in:
Carter McBride 2024-07-04 14:34:29 -06:00
parent dde2294c2b
commit 5c37a1494e
4 changed files with 39 additions and 131 deletions

View file

@ -5,97 +5,5 @@
"https://hejibits.com/rss#_=_", "https://hejibits.com/rss#_=_",
"http://www.hrwiki.org/wiki/Special:Updates", "http://www.hrwiki.org/wiki/Special:Updates",
"http://rockpapercynic.tumblr.com/rss" "http://rockpapercynic.tumblr.com/rss"
],
"Podcasts & Videos": [
"https://lilyandsam.show/feed",
"https://www.youtube.com/feeds/videos.xml?channel_id=UC3g-w83Cb5pEAu5UmRrge-A",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCakAg8hC_RFJm4RI3DlD7SA",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCHZOwvEh9FAG95RO3PWhe5g",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCvVsD2hFZRgKNH7x5Q1wwug",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCDq5v10l4wkV5-ZBIJJFbzQ",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCMkbjxvwur30YrFWw8kpSaw",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCSuT9FSddzI6W5Bij9XwtmA",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCqqJQ_cXSat0KIAVfIfKkVA",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCuvSqzfO_LV_QzHdmEj84SQ",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCSdma21fnJzgmPodhC9SJ3g",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCj1VqrHhDte54oLgPG4xpuQ",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCy0tKL1T7wFoYcxCe0xjN6Q",
"https://www.youtube.com/feeds/videos.xml?channel_id=UCsvn_Po0SmunchJYOWpOxMg"
],
"Friends and Family": [
"https://www.goodreads.com/review/list_rss/132710826?shelf=read",
"https://jgm23333.wixsite.com/my-site/blog-feed.xml",
"https://joekhoury.blog/feed/",
"https://social.warnick.me/users/sam.rss"
],
"Games": [
"https://www.nomanssky.com/news/feed/",
"https://www.lexaloffle.com/bbs/feed.php?uid=1",
"https://www.factorio.com/blog/rss",
"https://kill-the-newsletter.com/feeds/pghhn8aaf264tukg.xml",
"http://www.suppermariobroth.com/rss",
"http://unknownworlds.com/subnautica/feed/",
"https://store.steampowered.com/feeds/news/app/1675200/?cc=US&l=english"
],
"Finance": [
"http://feeds.feedburner.com/MrMoneyMustache",
"http://feeds.feedburner.com/DoctorOfCredit",
"https://kill-the-newsletter.com/feeds/tgor1vrwcf3f0uyo.xml",
"https://kill-the-newsletter.com/feeds/5q4gs79dfh32yr3h.xml"
],
"News": [
"http://www.economist.com/rss/the_world_this_week_rss.xml",
"https://newsroom.churchofjesuschrist.org/rss",
"http://feeds.feedburner.com/LdsChurchGrowth",
"https://www.sltrib.com/arc/outboundfeeds/news/?outputType=xml",
"https://www.ksl.com/rss/news/news_utah",
"https://www.readtangle.com/posts/rss/"
],
"Parenting": [
"https://technosapiens.substack.com/feed",
"https://parentdata.org/feed/"
],
"Fashion": [
"http://www.heddels.com/feed/",
"http://putthison.com/rss",
"https://articlesofinterest.substack.com/feed",
"https://dappered.com/feed/",
"https://dieworkwear.com/feed/",
"http://fromsqualortoballer.com/rss",
"https://fabricateurialist.substack.com/feed",
"https://www.menswearmusings.com/feed/",
"https://www.permanentstyle.com/feed"
],
"Products": [
"https://jellyfin.org/index.xml",
"https://gitlab.com/CalcProgrammer1/OpenRGB/-/tags?format=atom",
"http://feeds.feedburner.com/psblog",
"https://matrix.org/blog/feed/",
"https://brave.com/feed/",
"https://bitwarden.com/blog/feed.xml"
],
"Humor": [
"https://kill-the-newsletter.com/feeds/d90ng280lhh3p2nq.xml",
"http://www.altuniversebyu.com/feed/",
"https://aiweirdness.com/rss",
"http://mcmansionhell.tumblr.com/rss"
],
"Other": [
"https://kill-the-newsletter.com/feeds/400aiwxy5ox6ao0d.xml",
"http://brandonsanderson.com/feed/",
"https://kill-the-newsletter.com/feeds/j3c4wngg2hpjmdt8.xml",
"https://astralcodexten.substack.com/feed/"
],
"Tech News": [
"https://samwarnick.com/feed.rss",
"http://feeds.feedburner.com/CssTricks",
"http://chriscoyier.net/feed/",
"https://jenniferdaniel.substack.com/feed/",
"http://www.gamingonlinux.com/article_rss.php",
"http://www.theverge.com/rss/full.xml"
],
"Emulation": [
"http://melonds.kuribo64.net/rss.php",
"https://dolphin-emu.org/blog/feeds/"
] ]
} }

View file

@ -141,7 +141,7 @@
{% endif %} {% endif %}
<footer> <footer>
<hr> <hr>
<p>Last updated {{ now }}.</p> <p>Last updated <relative-time data-time="{{ now }}">{{ now | relative}}</relative-time>.</p>
<p> <p>
<a href="https://github.com/carterworks/rss-reader">View on GitHub</a> <a href="https://github.com/carterworks/rss-reader">View on GitHub</a>
</p> </p>

View file

@ -116,48 +116,48 @@ const processFeed =
feed: string; feed: string;
startTime: number; startTime: number;
}) => }) =>
async (response: Response): Promise<void> => { async (response: Response): Promise<void> => {
const body = await parseFeed(response); const body = await parseFeed(response);
//skip to the next one if this didn't work out //skip to the next one if this didn't work out
if (!body) return; if (!body) return;
try { try {
const contents: FeedItem = ( const contents: FeedItem = (
typeof body === "string" ? await parser.parseString(body) : body typeof body === "string" ? await parser.parseString(body) : body
) as FeedItem; ) as FeedItem;
contents.feed = feed; contents.feed = feed;
contents.title = getTitle(contents); contents.title = getTitle(contents);
contents.link = getLink(contents); contents.link = getLink(contents);
// try to normalize date attribute naming // try to normalize date attribute naming
for (const item of contents.items) { for (const item of contents.items) {
item.timestamp = getTimestamp(item); item.timestamp = getTimestamp(item);
item.title = getTitle(item); item.title = getTitle(item);
item.link = getLink(item); item.link = getLink(item);
const timestamp = new Date(Number.parseInt(item.timestamp)); const timestamp = new Date(Number.parseInt(item.timestamp));
const eightHoursAgo = new Date(); const eightHoursAgo = new Date();
eightHoursAgo.setHours(eightHoursAgo.getHours() - 8); eightHoursAgo.setHours(eightHoursAgo.getHours() - 8);
item.isRecent = timestamp > eightHoursAgo; item.isRecent = timestamp > eightHoursAgo;
}
contents.hasRecent = contents.items.some((item) => item.isRecent);
contentFromAllFeeds[group].push(contents as object);
process.stdout.write(
`${success("Successfully fetched:")} ${feed} - ${benchmark(startTime)}\n`,
);
} catch (err) {
process.stdout.write(
`${error("Error processing:")} ${feed} - ${benchmark(
startTime,
)}\n${err}\n`,
);
errors.push(`Error processing: ${feed}\n\t${err}`);
} }
finishBuild(); contents.hasRecent = contents.items.some((item) => item.isRecent);
};
contentFromAllFeeds[group].push(contents as object);
process.stdout.write(
`${success("Successfully fetched:")} ${feed} - ${benchmark(startTime)}\n`,
);
} catch (err) {
process.stdout.write(
`${error("Error processing:")} ${feed} - ${benchmark(
startTime,
)}\n${err}\n`,
);
errors.push(`Error processing: ${feed}\n\t${err}`);
}
finishBuild();
};
// go through each group of feeds and process // go through each group of feeds and process
const processFeeds = () => { const processFeeds = () => {

View file

@ -23,7 +23,7 @@ env.addFilter("formatTime", (dateString): string => {
return !Number.isNaN(date.getTime()) ? date.toLocaleTimeString() : dateString; return !Number.isNaN(date.getTime()) ? date.toLocaleTimeString() : dateString;
}); });
env.addGlobal("now", new Date().toUTCString()); env.addGlobal("now", new Date().getTime());
// load the template // load the template
const template: string = ( const template: string = (