summaryrefslogtreecommitdiffstats
path: root/src/utils/helpers/rss.ts
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-24 19:35:12 +0200
committerGitHub <noreply@github.com>2022-05-24 19:35:12 +0200
commitc85ab5ad43ccf52881ee224672c41ec30021cf48 (patch)
tree8058808d9bfca19383f120c46b34d99ff2f89f63 /src/utils/helpers/rss.ts
parent52404177c07a2aab7fc894362fb3060dff2431a0 (diff)
parent11b9de44a4b2f305a6a484187805e429b2767118 (diff)
refactor: use storybook and atomic design (#16)
BREAKING CHANGE: rewrite most of the Typescript types, so the content format (the meta in particular) needs to be updated.
Diffstat (limited to 'src/utils/helpers/rss.ts')
-rw-r--r--src/utils/helpers/rss.ts51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/utils/helpers/rss.ts b/src/utils/helpers/rss.ts
index 10a8e77..8ee774c 100644
--- a/src/utils/helpers/rss.ts
+++ b/src/utils/helpers/rss.ts
@@ -1,20 +1,35 @@
-import { getPostsTotal, getPublishedPosts } from '@services/graphql/queries';
-import { ArticlePreview } from '@ts/types/articles';
-import { PostsList } from '@ts/types/blog';
+import {
+ getArticleFromRawData,
+ 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 rawArticles = await getArticles({ first: totalArticles });
+ const articles: Article[] = [];
- const postsList: PostsList = await getPublishedPosts({ first: totalPosts });
- posts.push(...postsList.posts);
+ rawArticles.edges.forEach((edge) =>
+ articles.push(getArticleFromRawData(edge.node))
+ );
- 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 +53,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,
});
});