mirror of
https://github.com/georgemandis/bubo-rss.git
synced 2025-10-15 03:05:06 +00:00
Initial release
This commit is contained in:
14
src/feeds.json
Normal file
14
src/feeds.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"Blogs": [
|
||||
"https://george.mand.is/feed.xml"
|
||||
],
|
||||
"GitHub": [
|
||||
"https://github.com/georgemandis.atom?tab=repositories",
|
||||
"https://github.com/snaptortoise/konami-js/releases.atom",
|
||||
"https://github.com/snaptortoise/konami-js/commits/master.atom",
|
||||
"https://github.com/javascriptforartists/cheer-me-up-and-sing-me-a-song/commits/master.atom",
|
||||
"https://github.com/georgemandis/circuit-playground-midi-multi-tool/commits/master.atom",
|
||||
"https://github.com/georgemandis/remote-working-list/commits/master.atom",
|
||||
"https://github.com/georgemandis/tweeter-totter/commits/master.atom"
|
||||
]
|
||||
}
|
87
src/index.js
Normal file
87
src/index.js
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 🦉 Bubo RSS Reader
|
||||
* ====
|
||||
* Dead, dead simple feed reader that renders an HTML
|
||||
* page with links to content from feeds organized by site
|
||||
*
|
||||
*/
|
||||
|
||||
const fetch = require("node-fetch");
|
||||
const Parser = require("rss-parser");
|
||||
const parser = new Parser();
|
||||
|
||||
const nunjucks = require("nunjucks");
|
||||
const env = nunjucks.configure({ autoescape: true });
|
||||
|
||||
const feeds = require("./feeds.json");
|
||||
|
||||
env.addFilter("formatDate", function(dateString) {
|
||||
const formattedDate = new Date(dateString).toLocaleDateString()
|
||||
return formattedDate !== 'Invalid Date' ? formattedDate : dateString;
|
||||
});
|
||||
|
||||
// parse XML or JSON feeds
|
||||
function parseFeed(response) {
|
||||
const contentType = response.headers.get("content-type")
|
||||
? response.headers.get("content-type").split(";")[0]
|
||||
: false;
|
||||
|
||||
const rssFeed = [contentType]
|
||||
.map(item =>
|
||||
[
|
||||
"application/atom+xml",
|
||||
"application/rss+xml",
|
||||
"application/xml",
|
||||
"text/xml",
|
||||
"text/html" // this is kind of a gamble
|
||||
].includes(item)
|
||||
? response.text()
|
||||
: false
|
||||
)
|
||||
.filter(_ => _)[0];
|
||||
|
||||
const jsonFeed = [contentType]
|
||||
.map(item =>
|
||||
["application/json"].includes(item) ? response.json() : false
|
||||
)
|
||||
.filter(_ => _)[0];
|
||||
|
||||
return rssFeed || jsonFeed || false;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const contentFromAllFeeds = {};
|
||||
const errors = [];
|
||||
|
||||
for (group in feeds) {
|
||||
contentFromAllFeeds[group] = [];
|
||||
|
||||
for (let index = 0; index < feeds[group].length; index++) {
|
||||
try {
|
||||
const response = await fetch(feeds[group][index]);
|
||||
const body = await parseFeed(response);
|
||||
const contents =
|
||||
typeof body === "string" ? await parser.parseString(body) : body;
|
||||
|
||||
contents.feed = feeds[group][index];
|
||||
contents.title = contents.title ? contents.title : contents.link;
|
||||
contentFromAllFeeds[group].push(contents);
|
||||
|
||||
// try to normalize date attribute naming
|
||||
contents.items.forEach(item => {
|
||||
const timestamp = new Date(item.pubDate || item.isoDate || item.date).getTime();
|
||||
item.timestamp = isNaN(timestamp) ? (item.pubDate || item.isoDate || item.date) : timestamp;
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
errors.push(feeds[group][index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const output = env.render("./src/template.html", {
|
||||
data: contentFromAllFeeds,
|
||||
errors: errors
|
||||
});
|
||||
console.log(output);
|
||||
})();
|
43
src/template.html
Normal file
43
src/template.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>🦉 Bubo Reader</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>🦉 Bubo Reader</h1>
|
||||
|
||||
{% for group, feeds in data %}
|
||||
<h2>{{ group }}</h2>
|
||||
{% for feed in feeds %}
|
||||
<details>
|
||||
<summary>
|
||||
<span class="feed-title">{{ feed.title }}</span>
|
||||
<span class="feed-url">({{ feed.feed }})</span>
|
||||
</summary>
|
||||
<ul>
|
||||
{% for item in feed.items %}
|
||||
<li>
|
||||
{{ item.timestamp | formatDate }} - <a href="{{ item.link }}" target='_blank' rel='noopener norefferer nofollow'>{{ item.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</details>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
{% if errors | length > 0 %}
|
||||
<h2>Errors</h2>
|
||||
<p>There were errors trying to parse these feeds:</p>
|
||||
<ul>
|
||||
{% for error in errors %}
|
||||
<li>{{ error }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user