RSS content delivery (#13)
YAB now supports RSS content delivery which can be enabled or disabled though the admin panel Reviewed-on: #13 Co-authored-by: Armored Dragon <publicmail@armoreddragon.com> Co-committed-by: Armored Dragon <publicmail@armoreddragon.com>pull/2/head
parent
a403b114e8
commit
50f30f227d
|
@ -1,17 +1,14 @@
|
|||
const feed_lib = require("feed").Feed;
|
||||
const internal = require("./internal_api");
|
||||
const core = require("./core");
|
||||
|
||||
// TODO: Expose ATOM Feed items
|
||||
function getBaseFeed() {
|
||||
return new feed_lib({
|
||||
title: process.env.WEBSITE_NAME,
|
||||
description: `${process.env.S3_REGION} RSS Feed`,
|
||||
title: core.settings.WEBSITE_NAME,
|
||||
description: `${core.settings.WEBSITE_NAME} RSS Feed`,
|
||||
id: process.env.BASE_URL,
|
||||
link: process.env.BASE_URL,
|
||||
// image: "http://example.com/image.png",
|
||||
// favicon: "http://example.com/favicon.ico",
|
||||
// copyright: "All rights reserved 2013, John Doe",
|
||||
// generator: "awesome", // optional, default = 'Feed for Node.js'
|
||||
favicon: `${process.env.BASE_URL}/favicon.ico`,
|
||||
feedLinks: {
|
||||
json: `${process.env.BASE_URL}/json`,
|
||||
atom: `${process.env.BASE_URL}/atom`,
|
||||
|
@ -20,11 +17,14 @@ function getBaseFeed() {
|
|||
}
|
||||
|
||||
async function getFeed({ type = "rss" }) {
|
||||
// Don't serve RSS feed if disabled by admin
|
||||
if (!core.settings.CD_RSS) return;
|
||||
|
||||
// Get the base feed
|
||||
let feed = getBaseFeed();
|
||||
|
||||
// Get posts
|
||||
let posts = await internal.getBlogList({}, { limit: 20 });
|
||||
let posts = await core.getBlog({ limit: 20 }); // internal.getBlogList({}, { limit: 20 });
|
||||
|
||||
// For each post, add a formatted object to the feed
|
||||
posts.data.forEach((post) => {
|
||||
|
@ -48,7 +48,7 @@ async function getFeed({ type = "rss" }) {
|
|||
});
|
||||
// if (type === "rss") return feed.rss2();
|
||||
if (type === "atom") return feed.atom1();
|
||||
// if (type === "json") return feed.json1();
|
||||
if (type === "json") return feed.json1();
|
||||
}
|
||||
|
||||
module.exports = { getFeed };
|
||||
|
|
|
@ -38,7 +38,6 @@ async function postLogin(req, res) {
|
|||
async function postSetting(request, response) {
|
||||
const user = await core.getUser({ id: request.session.user.id });
|
||||
|
||||
// TODO: Permissions for changing settings
|
||||
if (!user.success) return response.json({ success: false, message: user.message });
|
||||
if (user.data.role !== "ADMIN") return response.json({ success: false, message: "User is not permitted" });
|
||||
|
||||
|
|
|
@ -75,7 +75,10 @@ async function atom(req, res) {
|
|||
res.type("application/xml");
|
||||
res.send(await external.getFeed({ type: "atom" }));
|
||||
}
|
||||
|
||||
async function jsonFeed(req, res) {
|
||||
res.type("application/json");
|
||||
res.send(await external.getFeed({ type: "json" }));
|
||||
}
|
||||
// Internal API ------------------------------
|
||||
|
||||
module.exports = {
|
||||
|
@ -89,4 +92,5 @@ module.exports = {
|
|||
blogSingle,
|
||||
admin,
|
||||
atom,
|
||||
jsonFeed,
|
||||
};
|
||||
|
|
1
yab.js
1
yab.js
|
@ -46,6 +46,7 @@ app.get("/blog/new", checkAuthenticated, page_scripts.blogNew);
|
|||
app.get("/blog/:blog_id", page_scripts.blogSingle);
|
||||
app.get("/blog/:blog_id/edit", checkAuthenticated, page_scripts.blogEdit);
|
||||
app.get("/atom", page_scripts.atom);
|
||||
app.get("/json", page_scripts.jsonFeed);
|
||||
|
||||
function checkAuthenticated(req, res, next) {
|
||||
if (req.session.user) return next();
|
||||
|
|
Loading…
Reference in New Issue