add rss feeds!

This commit is contained in:
James Shiffer 2020-09-10 19:41:22 -07:00
parent 124a0da9e3
commit 47d464f5f7
No known key found for this signature in database
GPG Key ID: C0DB8774A1B3BA45
4 changed files with 61 additions and 0 deletions

29
package-lock.json generated
View File

@ -5760,6 +5760,30 @@
"inherits": "^2.0.1"
}
},
"rss": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/rss/-/rss-1.2.2.tgz",
"integrity": "sha1-UKFpiHYTgTOnT5oF0r3I240nqSE=",
"requires": {
"mime-types": "2.1.13",
"xml": "1.0.1"
},
"dependencies": {
"mime-db": {
"version": "1.25.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.25.0.tgz",
"integrity": "sha1-wY29fHOl2/b0SgJNwNFloeexw5I="
},
"mime-types": {
"version": "2.1.13",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.13.tgz",
"integrity": "sha1-4HqqnGxrmnyjASxpADrSWjnpKog=",
"requires": {
"mime-db": "~1.25.0"
}
}
}
},
"run-queue": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/run-queue/-/run-queue-1.0.3.tgz",
@ -7205,6 +7229,11 @@
"resolved": "https://registry.npmjs.org/x-xss-protection/-/x-xss-protection-1.3.0.tgz",
"integrity": "sha512-kpyBI9TlVipZO4diReZMAHWtS0MMa/7Kgx8hwG/EuZLiA6sg4Ah/4TRdASHhRRN3boobzcYgFRUFSgHRge6Qhg=="
},
"xml": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/xml/-/xml-1.0.1.tgz",
"integrity": "sha1-eLpyAgApxbyHuKgaPPzXS0ovweU="
},
"xtend": {
"version": "4.0.2",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz",

View File

@ -29,6 +29,7 @@
"passport": "^0.4.1",
"passport-local": "^1.0.0",
"rate-limiter-flexible": "^2.1.10",
"rss": "^1.2.2",
"session-file-store": "^1.4.0",
"useragent": "^2.3.0"
},

30
src/routes/rss.xml.js Normal file
View File

@ -0,0 +1,30 @@
import RSS from 'rss';
import Article from '../models/article.js';
export async function get(req, res)
{
let feed = new RSS();
let articles = await Article.find().populate({
path: 'author',
select: 'realname avatar'
}).populate({
path: 'category'
});
for (let article of articles) {
feed.item({
title: article.title,
description: article.html,
url: `http://howfeed.biz/a/${article.slug}`,
categories: [ article.category.name ],
author: article.author.realname,
date: article.created_at,
enclosure: {
url: `http://howfeed.biz/a/${article.image}`
}
});
}
res.writeHead(200);
res.end(feed.xml());
}

View File

@ -9,6 +9,7 @@
<link rel='stylesheet' href='global.css'>
<link rel='icon' type='image/png' href='favicon.png'>
<link href='https://fonts.googleapis.com/css2?family=EB+Garamond:wght@400;700&display=swap' rel='stylesheet'>
<link rel='alternate' type='application/rss+xml' title='RSS Feed for petefreitag.com' href='/rss.xml'>
%sapper.styles%
%sapper.head%
<!-- Global site tag (gtag.js) - Google Analytics -->