Skip to content

Commit

Permalink
Add glossary terms to RSS feed
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Jun 16, 2024
1 parent 49cf7b6 commit b47b3dd
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions app/routes/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { LoaderFunctionArgs } from "@remix-run/cloudflare";
import { xml } from "remix-utils/responses";

import { Article } from "~/models/article.server";
import { Glossary } from "~/models/glossary.server";
import { Like } from "~/models/like.server";
import { Tutorial } from "~/models/tutorial.server";
import { Logger } from "~/modules/logger.server";
Expand All @@ -13,20 +14,25 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
void new Logger(context).http(request);

let db = database(context.db);
let [articles, likes, tutorials] = await Promise.all([
let [articles, likes, tutorials, glossary] = await Promise.all([
Article.list({ db }),
Like.list({ db }),
Tutorial.list({ db }),
Glossary.list({ db }),
]);

let feed = [
...articles.map((article) => {
let link = new URL(article.pathname, "https://sergiodxa.com").toString();

let description = article.excerpt
? `${article.excerpt}\n<a href="${link}">Read it on the web</a>`
: `<a href="${link}">Read it on the web</a>`;

return {
guid: article.id,
title: article.title,
description: `${article.excerpt}\n<a href="${link}">Read it on the web</a>`,
description,
link,
pubDate: article.createdAt.toUTCString(),
};
Expand All @@ -41,22 +47,43 @@ export async function loader({ request, context }: LoaderFunctionArgs) {
...tutorials.map((tutorial) => {
let link = new URL(tutorial.pathname, "https://sergiodxa.com").toString();

let description = tutorial.excerpt
? `${tutorial.excerpt}\n<a href="${link}">Read it on the web</a>`
: `<a href="${link}">Read it on the web</a>`;

return {
guid: tutorial.id,
title: tutorial.title,
description: `${tutorial.excerpt}\n<a href="${link}">Read it on the web</a>`,
description,
link,
pubDate: tutorial.createdAt.toUTCString(),
};
}),
...glossary.map((glossaryTerm) => {
let url = new URL("https://sergiodxa.com/glossary");
url.hash = glossaryTerm.slug;

let link = url.toString();
let title = glossaryTerm.title
? `${glossaryTerm.term} (aka ${glossaryTerm.title})`
: glossaryTerm.term;

return {
guid: glossaryTerm.id,
title,
description: glossaryTerm.definition,
link,
pubDate: glossaryTerm.createdAt.toUTCString(),
};
}),
].sort(
(a, b) => new Date(b.pubDate).getTime() - new Date(a.pubDate).getTime(),
);

let rss = new RSS({
title: "Sergio Xalambrí",
description:
"The complete list of articles, bookmarks and tutorials of @sergiodxa.",
"The complete list of articles, bookmarks, tutorials, and glossary terms of @sergiodxa.",
link: "https://sergiodxa.com/rss",
});

Expand Down

0 comments on commit b47b3dd

Please sign in to comment.