Add RSS functionality, minor changes to post css

This commit is contained in:
Monty 2021-09-27 23:47:33 +02:00
parent 28e30d4144
commit db03304803
No known key found for this signature in database
GPG Key ID: 78B405B6520E1012
3 changed files with 60 additions and 11 deletions

View File

@ -25,7 +25,11 @@ header {
.blog-card h3,
.blog-card h4,
.blog-card h5,
.blog-card h6,
.blog-card h6 {
margin: 40px 0 10px;
color: var(--text);
}
.blog-card strong {
color: var(--text);
}

View File

@ -8,17 +8,11 @@ const path = require('path');
const marked = require('marked');
const matter = require('gray-matter');
router.get('/', async (request, response) => {
const reqLocale = request.locale;
const locale = util.getLocale(reqLocale.region, reqLocale.language);
const localeString = reqLocale.toString();
const fileList = fs.readdirSync('blogposts');
const postList = () => {
const files = fs.readdirSync('blogposts');
// We get the info for each blogpost, ignoring the ones starting with _
const postList = fileList
const posts = files
.filter(filename => !filename.startsWith('_'))
.filter(filename => filename.endsWith('.md')) // Ignores other files/folders
.map((filename) => {
@ -30,10 +24,20 @@ router.get('/', async (request, response) => {
};
});
postList.sort((a, b) => {
posts.sort((a, b) => {
return new Date(b.postInfo.date) - new Date(a.postInfo.date);
});
return posts;
};
router.get('/', async (request, response) => {
const reqLocale = request.locale;
const locale = util.getLocale(reqLocale.region, reqLocale.language);
const localeString = reqLocale.toString();
response.render('blog', {
layout: 'main',
locale,
@ -42,6 +46,19 @@ router.get('/', async (request, response) => {
});
});
// RSS feed
router.get('/feed.xml', async (request, response) => {
const pubDate = new Date(postList()[0].postInfo.date).toUTCString();
response.set('Content-Type', 'application/rss+xml');
response.render('blog-rss', {
layout: false,
postList,
pubDate
});
});
router.get('/:slug', async (request, response) => {
const reqLocale = request.locale;

28
views/blog-rss.handlebars Normal file
View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Pretendo Network Blog</title>
<link>https://pretendo.network/blog</link>
<atom:link href="https://pretendo.network/blog/feed.xml" rel="self" type="application/rss+xml" />
<description>The latest updates in condensed chunks.</description>
<pubDate>{{ this.pubDate }}</pubDate>
<category>Web development</category>
<image>
<url>https://pretendo.network/assets/images/opengraph/opengraph-image.png</url>
<title>Pretendo Network Blog</title>
<link>https://pretendo.network/blog</link>
</image>
{{#each postList }}
<item>
<title>{{ this.postInfo.title }}</title>
<link>https://pretendo.network/blog/{{this.slug}}</link>
<description>{{ this.postInfo.caption }}</description>
<guid>https://pretendo.network/blog/{{this.slug}}</guid>
</item>
{{/each}}
</channel>
</rss>