Create and link RSS feed
This commit is contained in:
39
src/routes/feed/_feed.js
Normal file
39
src/routes/feed/_feed.js
Normal file
@ -0,0 +1,39 @@
|
||||
import { Feed } from 'feed'
|
||||
import { getBlogListing } from '../blog/_content'
|
||||
|
||||
export async function getFeed() {
|
||||
const feed = new Feed({
|
||||
title: 'michalvanko.dev latest posts',
|
||||
id: 'https://michalvanko.dev',
|
||||
link: 'https://michalvanko.dev',
|
||||
description: 'Latest posts published on michalvanko.dev',
|
||||
copyright: 'All rights reserved 2020, Michal Vanko',
|
||||
generator: 'sapper with Feed for node.js',
|
||||
updated: new Date(),
|
||||
image: 'https://michalvanko.dev/eye.png',
|
||||
favicon: 'https://michalvanko.dev/m-favicon-192x192.png',
|
||||
language: 'en',
|
||||
author: {
|
||||
name: 'Michal Vanko',
|
||||
email: 'michalvankosk@gmail.com',
|
||||
link: 'https://michalvanko.dev',
|
||||
},
|
||||
feedLinks: {
|
||||
json: 'https://michalvanko.dev/feed.json',
|
||||
rss: 'https://michalvanko.dev/feed.xml',
|
||||
},
|
||||
})
|
||||
|
||||
const blogListing = await getBlogListing()
|
||||
blogListing.forEach(post => {
|
||||
feed.addItem({
|
||||
title: post.title,
|
||||
id: `https://michalvanko.dev/blog/${post.slug}`,
|
||||
link: `https://michalvanko.dev/blog/${post.slug}`,
|
||||
description: post.preview,
|
||||
date: post.date,
|
||||
image: post.thumbnail ? `https://michalvanko.dev/${post.thumbnail}` : undefined,
|
||||
})
|
||||
})
|
||||
return feed
|
||||
}
|
11
src/routes/feed/index.json.js
Normal file
11
src/routes/feed/index.json.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { getFeed } from './_feed'
|
||||
|
||||
export async function get(req, res) {
|
||||
const feed = await getFeed()
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json',
|
||||
})
|
||||
res.end(feed.json1())
|
||||
}
|
||||
|
11
src/routes/feed/index.xml.js
Normal file
11
src/routes/feed/index.xml.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { getFeed } from './_feed'
|
||||
|
||||
export async function get(req, res) {
|
||||
const feed = await getFeed()
|
||||
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/xml',
|
||||
})
|
||||
res.end(feed.rss2())
|
||||
}
|
||||
|
Reference in New Issue
Block a user