aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/rss.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-02 18:36:09 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-02 18:36:09 +0200
commitca921d7536cfe950b5a7d442977bbf900b48faf4 (patch)
tree2e8bb3f4b81414ee881c3d92d9bdfed411c569db /src/utils/helpers/rss.ts
parent9308a6dce03bd0c616e0ba6fec227473aaa44b33 (diff)
chore: fetch posts for rss feed
Diffstat (limited to 'src/utils/helpers/rss.ts')
-rw-r--r--src/utils/helpers/rss.ts44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/utils/helpers/rss.ts b/src/utils/helpers/rss.ts
index 10a8e77..95d3b7b 100644
--- a/src/utils/helpers/rss.ts
+++ b/src/utils/helpers/rss.ts
@@ -1,20 +1,26 @@
-import { getPostsTotal, getPublishedPosts } from '@services/graphql/queries';
-import { ArticlePreview } from '@ts/types/articles';
-import { PostsList } from '@ts/types/blog';
+import { getArticles, getTotalArticles } from '@services/graphql/articles';
+import { Article } from '@ts/types/app';
import { settings } from '@utils/config';
import { Feed } from 'feed';
-const getAllPosts = async (): Promise<ArticlePreview[]> => {
- const totalPosts = await getPostsTotal();
- const posts: ArticlePreview[] = [];
+/**
+ * Retrieve the data for all the articles.
+ *
+ * @returns {Promise<Article[]>} - All the articles.
+ */
+const getAllArticles = async (): Promise<Article[]> => {
+ const totalArticles = await getTotalArticles();
+ const { articles } = await getArticles({ first: totalArticles });
- const postsList: PostsList = await getPublishedPosts({ first: totalPosts });
- posts.push(...postsList.posts);
-
- return posts;
+ return articles;
};
-export const generateFeed = async () => {
+/**
+ * Generate a new feed.
+ *
+ * @returns {Promise<Feed>} - The feed.
+ */
+export const generateFeed = async (): Promise<Feed> => {
const author = {
name: settings.name,
email: process.env.APP_AUTHOR_EMAIL,
@@ -38,16 +44,16 @@ export const generateFeed = async () => {
title,
});
- const posts = await getAllPosts();
+ const articles = await getAllArticles();
- posts.forEach((post) => {
+ articles.forEach((article) => {
feed.addItem({
- content: post.intro,
- date: new Date(post.dates.publication),
- description: post.intro,
- id: post.id,
- link: `${settings.url}/article/${post.slug}`,
- title: post.title,
+ content: article.intro,
+ date: new Date(article.meta!.dates.publication),
+ description: article.intro,
+ id: `${article.id}`,
+ link: `${settings.url}/article/${article.slug}`,
+ title: article.title,
});
});