From 71cec4a31766e75c489559a0644c8e814412520b Mon Sep 17 00:00:00 2001 From: Drew Lytle Date: Sun, 14 Jan 2024 10:10:00 -0500 Subject: [PATCH] Fix rss feed --- app/data/sanityClient.server.ts | 4 ++++ app/routes/[feed.atom.xml].tsx | 6 +++--- app/routes/[feed.rss.xml].tsx | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/data/sanityClient.server.ts b/app/data/sanityClient.server.ts index 7aae1f2..e6551b4 100644 --- a/app/data/sanityClient.server.ts +++ b/app/data/sanityClient.server.ts @@ -19,6 +19,10 @@ export function getAllPosts() { return `*[_type == "post"]{_id, title, description, mainImage, tags[]->{title}, "slug": slug.current}`; } +export function getPostsFeed() { + return `*[_type == "post"]{_id, title, description, mainImage, tags[]->{title}, "slug": slug.current, author->{...}, publishedAt}| order(publishedAt desc)`; +} + export function getPostBySlug(slug: string) { return `*[_type == "post" && slug.current match "${slug}" ][0]{_id, title, description, mainImage, tags[]->{title}, "slug": slug.current, body, author->{...}, publishedAt}`; } diff --git a/app/routes/[feed.atom.xml].tsx b/app/routes/[feed.atom.xml].tsx index 021ced0..b4da392 100644 --- a/app/routes/[feed.atom.xml].tsx +++ b/app/routes/[feed.atom.xml].tsx @@ -1,12 +1,12 @@ import type { LoaderFunction } from "@remix-run/node"; -import { getAllPosts, sanity } from "~/data/sanityClient.server"; +import { getPostsFeed, sanity } from "~/data/sanityClient.server"; import { Post } from "~/data/types"; import { feed } from "~/helpers/feed"; import { getHost } from "~/helpers/getHost.server"; import { imageBuilder } from "~/helpers/imageBuilder"; export const loader: LoaderFunction = async ({ request }) => { - const stories = (await sanity.fetch(getAllPosts())) as Post[]; + const stories = (await sanity.fetch(getPostsFeed())) as Post[]; const origin = new URL(request.url).origin; const storyURL = (slug: string) => @@ -24,7 +24,7 @@ export const loader: LoaderFunction = async ({ request }) => { date: new Date(publishedAt), author: [ { - name: author.name, + name: author?.name || "Drew Lyton", email: "contact@drewis.cool" } ], diff --git a/app/routes/[feed.rss.xml].tsx b/app/routes/[feed.rss.xml].tsx index 74945c8..a314a19 100644 --- a/app/routes/[feed.rss.xml].tsx +++ b/app/routes/[feed.rss.xml].tsx @@ -1,12 +1,12 @@ import type { LoaderFunction } from "@remix-run/node"; -import { getAllPosts, sanity } from "~/data/sanityClient.server"; +import { getPostsFeed, sanity } from "~/data/sanityClient.server"; import { Post } from "~/data/types"; import { feed } from "~/helpers/feed"; import { getHost } from "~/helpers/getHost.server"; import { imageBuilder } from "~/helpers/imageBuilder"; export const loader: LoaderFunction = async ({ request }) => { - const stories = (await sanity.fetch(getAllPosts())) as Post[]; + const stories = (await sanity.fetch(getPostsFeed())) as Post[]; const origin = new URL(request.url).origin; const storyURL = (slug: string) => @@ -24,7 +24,7 @@ export const loader: LoaderFunction = async ({ request }) => { date: new Date(publishedAt), author: [ { - name: author.name, + name: author?.name || "Drew Lyton", email: "contact@drewis.cool" } ],