generated from edmundhung/remix-cloudflare-template
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: setup rss feed * chore: align route file naming pattern * feat: add robots.txt
- Loading branch information
1 parent
a5e6fca
commit e4d5fe8
Showing
3 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { LoaderArgs } from '@remix-run/cloudflare'; | ||
import { search } from '~/resources'; | ||
|
||
interface FeedEntry { | ||
title: string; | ||
description: string | null | undefined; | ||
pubDate: string; | ||
guid: string; | ||
} | ||
|
||
export async function loader({ context }: LoaderArgs) { | ||
const domain = 'https://remix.guide'; | ||
const resources = await context.resourceStore.list(); | ||
const list = search(resources, { | ||
limit: 25, | ||
sort: 'new', | ||
}); | ||
|
||
const entries = list.entries.map<FeedEntry>((resource) => ({ | ||
title: resource.title ?? '', | ||
description: resource.description, | ||
pubDate: new Date(resource.createdAt).toUTCString(), | ||
guid: `${domain}/resources/${resource.id}`, | ||
})); | ||
|
||
const rss = ` | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||
<channel> | ||
<title>Remix Guide</title> | ||
<description>A platform for the Remix community</description> | ||
<link>https://remix.guide</link> | ||
<language>en-us</language> | ||
<generator>remix-guide</generator> | ||
<ttl>60</ttl> | ||
<atom:link href="https://remix.guide/rss.xml" rel="self" type="application/rss+xml" /> | ||
${entries | ||
.map((entry) => | ||
` | ||
<item> | ||
<title><![CDATA[${entry.title}]]></title> | ||
<description><![CDATA[${entry.description}]]></description> | ||
<pubDate>${entry.pubDate}</pubDate> | ||
<guid>${entry.guid}</guid> | ||
</item> | ||
`.trim(), | ||
) | ||
.join('\n')} | ||
</channel> | ||
</rss> | ||
`.trim(); | ||
|
||
return new Response(rss, { | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
'Content-Length': String(new TextEncoder().encode(rss).length), | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
User-agent: * | ||
Allow: / | ||
|
||
Sitemap: https://remix.guide/sitemap.xml |