Improve feeds
This commit is contained in:
parent
d69492a2e4
commit
11b34ddf3e
3
index.js
3
index.js
@ -9,7 +9,8 @@ app.set('port', process.env.PORT || 3000)
|
|||||||
|
|
||||||
app.use('/', require('./routes/main'))
|
app.use('/', require('./routes/main'))
|
||||||
app.use('/', require('./routes/static'))
|
app.use('/', require('./routes/static'))
|
||||||
app.use('/rss', require('./routes/rss'))
|
app.use('/feed', require('./routes/feed'))
|
||||||
|
app.use('/rss', require('./routes/feed'))
|
||||||
|
|
||||||
app.listen(app.get('port'), () => {
|
app.listen(app.get('port'), () => {
|
||||||
console.log(`Node server listening at http://localhost:${app.get('port')}`)
|
console.log(`Node server listening at http://localhost:${app.get('port')}`)
|
||||||
|
|||||||
45
routes/feed.js
Normal file
45
routes/feed.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
const router = require('express').Router()
|
||||||
|
const fs = require('fs')
|
||||||
|
const _ = require('lodash')
|
||||||
|
const util = require('../server/util')
|
||||||
|
|
||||||
|
router.get('/all', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/rss+xml')
|
||||||
|
res.end(await util.getRSS({ channel: 'all', format: 'rss' }))
|
||||||
|
})
|
||||||
|
router.get('/all.atom', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/atom+xml')
|
||||||
|
res.end(await util.getRSS({ channel: 'all', format: 'atom' }))
|
||||||
|
})
|
||||||
|
router.get('/all.json', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/feed+json')
|
||||||
|
res.end(await util.getRSS({ channel: 'all', format: 'json' }))
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/blog', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/rss+xml')
|
||||||
|
res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'rss' }))
|
||||||
|
})
|
||||||
|
router.get('/blog.atom', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/atom+xml')
|
||||||
|
res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'atom' }))
|
||||||
|
})
|
||||||
|
router.get('/blog.json', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/feed+json')
|
||||||
|
res.end(await util.getRSS({ include: ['blog'], channel: 'blog', format: 'json' }))
|
||||||
|
})
|
||||||
|
|
||||||
|
router.get('/notes', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/rss+xml')
|
||||||
|
res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'rss' }))
|
||||||
|
})
|
||||||
|
router.get('/notes.atom', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/atom+xml')
|
||||||
|
res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'atom' }))
|
||||||
|
})
|
||||||
|
router.get('/notes.json', async (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/feed+json')
|
||||||
|
res.end(await util.getRSS({ include: ['notes'], channel: 'notes', format: 'json' }))
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
||||||
@ -1,19 +0,0 @@
|
|||||||
const router = require('express').Router()
|
|
||||||
const fs = require('fs')
|
|
||||||
const _ = require('lodash')
|
|
||||||
const util = require('../server/util')
|
|
||||||
|
|
||||||
router.get('/all', async (req, res) => {
|
|
||||||
res.setHeader('Content-Type', 'application/xml')
|
|
||||||
res.end(await util.getRSS())
|
|
||||||
})
|
|
||||||
router.get('/blog', async (req, res) => {
|
|
||||||
res.setHeader('Content-Type', 'application/xml')
|
|
||||||
res.end(await util.getRSS({ include: ['blog'] }))
|
|
||||||
})
|
|
||||||
router.get('/notes', async (req, res) => {
|
|
||||||
res.setHeader('Content-Type', 'application/xml')
|
|
||||||
res.end(await util.getRSS({ include: ['notes'] }))
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = router
|
|
||||||
@ -110,8 +110,8 @@ const getWebmentions = async (url) => {
|
|||||||
const getRSS = async (opts) => {
|
const getRSS = async (opts) => {
|
||||||
if (!opts) { opts = {} }
|
if (!opts) { opts = {} }
|
||||||
opts.include = 'include' in opts ? opts.include : ['blog', 'notes']
|
opts.include = 'include' in opts ? opts.include : ['blog', 'notes']
|
||||||
// opts.excludeBlogPosts = 'excludeBlogPosts' in opts ? opts.excludeBlogPosts : false
|
opts.channel = 'channel' in opts ? opts.channel : 'all'
|
||||||
// opts.excludeNotes = 'excludeNotes' in opts ? opts.excludeNotes : false
|
opts.format = 'format' in opts ? opts.format : 'rss'
|
||||||
|
|
||||||
const feed = new Feed({
|
const feed = new Feed({
|
||||||
title: "Yarmo's blog and notes",
|
title: "Yarmo's blog and notes",
|
||||||
@ -122,6 +122,11 @@ const getRSS = async (opts) => {
|
|||||||
favicon: "https://yarmo.eu/favicon.png",
|
favicon: "https://yarmo.eu/favicon.png",
|
||||||
copyright: "All rights reserved 2020 Yarmo Mackenbach",
|
copyright: "All rights reserved 2020 Yarmo Mackenbach",
|
||||||
updated: new Date(Date.now()),
|
updated: new Date(Date.now()),
|
||||||
|
feedLinks: {
|
||||||
|
rss: `https://yarmo.eu/feed/${opts.channel}`,
|
||||||
|
json: `https://yarmo.eu/feed/${opts.channel}.json`,
|
||||||
|
atom: `https://yarmo.eu/feed/${opts.channel}.atom`
|
||||||
|
},
|
||||||
author: {
|
author: {
|
||||||
name: "Yarmo Mackenbach",
|
name: "Yarmo Mackenbach",
|
||||||
email: "yarmo@yarmo.eu",
|
email: "yarmo@yarmo.eu",
|
||||||
@ -165,7 +170,22 @@ const getRSS = async (opts) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return feed.rss2()
|
let response
|
||||||
|
switch (opts.format) {
|
||||||
|
case 'rss':
|
||||||
|
case 'xml':
|
||||||
|
default:
|
||||||
|
response = feed.rss2()
|
||||||
|
break;
|
||||||
|
case 'atom':
|
||||||
|
response = feed.atom1()
|
||||||
|
break;
|
||||||
|
case 'json':
|
||||||
|
response = feed.json1()
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
@ -13,8 +13,29 @@ block content
|
|||||||
main
|
main
|
||||||
ul
|
ul
|
||||||
li
|
li
|
||||||
a(href="/rss/all") RSS blog and notes
|
p
|
||||||
|
| Feed for blog posts and notes (
|
||||||
|
a(href="/feed/all") RSS
|
||||||
|
| -
|
||||||
|
a(href="/feed/all.atom") ATOM
|
||||||
|
| -
|
||||||
|
a(href="/feed/all.") JSON
|
||||||
|
| )
|
||||||
li
|
li
|
||||||
a(href="/rss/blog") RSS blog
|
p
|
||||||
|
| Feed for blog posts (
|
||||||
|
a(href="/feed/blog") RSS
|
||||||
|
| -
|
||||||
|
a(href="/feed/blog.atom") ATOM
|
||||||
|
| -
|
||||||
|
a(href="/feed/blog.json") JSON
|
||||||
|
| )
|
||||||
li
|
li
|
||||||
a(href="/rss/notes") RSS notes
|
p
|
||||||
|
| Feed for notes (
|
||||||
|
a(href="/feed/notes") RSS
|
||||||
|
| -
|
||||||
|
a(href="/feed/notes.atom") ATOM
|
||||||
|
| -
|
||||||
|
a(href="/feed/notes.json") JSON
|
||||||
|
| )
|
||||||
|
|||||||
@ -9,7 +9,9 @@ html
|
|||||||
link(rel="stylesheet", href="/static/norm.css")
|
link(rel="stylesheet", href="/static/norm.css")
|
||||||
link(rel="stylesheet", href="/static/style.css")
|
link(rel="stylesheet", href="/static/style.css")
|
||||||
link(rel="shortcut icon", href="/favicon.png")
|
link(rel="shortcut icon", href="/favicon.png")
|
||||||
link(rel="alternate", href="/rss/all", title="RSS blog feed for yarmo.eu", type="application/rss+xml")
|
link(rel="alternate", href="/feed/all", title="RSS blog feed for yarmo.eu", type="application/rss+xml")
|
||||||
|
link(rel="alternate", href="/feed/all.atom", title="RSS blog feed for yarmo.eu", type="application/atom+xml")
|
||||||
|
link(rel="alternate", href="/feed/all.json", title="RSS blog feed for yarmo.eu", type="application/feed+json")
|
||||||
link(rel="webmention", href="https://webm.yarmo.eu/receive")
|
link(rel="webmention", href="https://webm.yarmo.eu/receive")
|
||||||
script(asyc, defer, data-domain="yarmo.eu", src="https://plausible.io/js/plausible.js")
|
script(asyc, defer, data-domain="yarmo.eu", src="https://plausible.io/js/plausible.js")
|
||||||
body
|
body
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user