Skip to content

Commit

Permalink
Fix rss feed
Browse files Browse the repository at this point in the history
  • Loading branch information
drewlyton committed Jan 14, 2024
1 parent 70b4a58 commit 71cec4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/data/sanityClient.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
6 changes: 3 additions & 3 deletions app/routes/[feed.atom.xml].tsx
Original file line number Diff line number Diff line change
@@ -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) =>
Expand All @@ -24,7 +24,7 @@ export const loader: LoaderFunction = async ({ request }) => {
date: new Date(publishedAt),
author: [
{
name: author.name,
name: author?.name || "Drew Lyton",
email: "[email protected]"
}
],
Expand Down
6 changes: 3 additions & 3 deletions app/routes/[feed.rss.xml].tsx
Original file line number Diff line number Diff line change
@@ -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) =>
Expand All @@ -24,7 +24,7 @@ export const loader: LoaderFunction = async ({ request }) => {
date: new Date(publishedAt),
author: [
{
name: author.name,
name: author?.name || "Drew Lyton",
email: "[email protected]"
}
],
Expand Down

0 comments on commit 71cec4a

Please sign in to comment.