yet-another-blog/backend/core/external_api.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

const feed_lib = require("feed").Feed;
const core = require("./core");
function getBaseFeed() {
return new feed_lib({
title: core.settings.WEBSITE_NAME,
description: `${core.settings.WEBSITE_NAME} RSS Feed`,
id: process.env.BASE_URL,
link: process.env.BASE_URL,
favicon: `${process.env.BASE_URL}/favicon.ico`,
feedLinks: {
json: `${process.env.BASE_URL}/json`,
atom: `${process.env.BASE_URL}/atom`,
},
});
}
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
Generic Theme (#1) * Theme work Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * User registration. Cleanup CSS. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Post Creation and Manipulation Uploading images now easier. Just drag and drop onto the text area. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Author Page. Edit author page. Author display name. Generic media uploads. Core refactoring. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Texteditor bugfix. PGAdmin docker container for management of database. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Tags. Search by tags. Return tags used by posts. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * New post button. Fix index "page" param not being honored. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Post drafts Users can now only have one "unpublished" draft. Improved password handling. Minor cleanup. Admin panel navigation link. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Post visibility flairs Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Publish date autofill to now. Fix deleteBlog. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Removed unused function Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Media upload pruning. Uploaded media is now pruned automatically every time a post is updated. Minor cleanup. Groundwork for media types other than images. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> * Updated name. Use the manifest data. Signed-off-by: Armored Dragon <publicmail@armoreddragon.com> --------- Signed-off-by: Armored Dragon <publicmail@armoreddragon.com>
2024-04-30 15:26:35 +00:00
let posts = await core.getPost(null, null, { limit: 20 });
// For each post, add a formatted object to the feed
posts.data.forEach((post) => {
let formatted = {
title: post.title,
description: post.description,
id: post.id,
link: `${process.env.BASE_URL}/blog/${post.id}`,
content: post.content,
date: new Date(post.publish_date),
image: post.thumbnail,
author: [
{
name: post.owner.username,
link: `${process.env.BASE_URL}/author/${post.owner.username}`,
},
],
};
feed.addItem(formatted);
});
// if (type === "rss") return feed.rss2();
if (type === "atom") return feed.atom1();
if (type === "json") return feed.json1();
}
module.exports = { getFeed };