Guides
@skyscribe-sdk/core exports generateFeed, which takes a fetched StandardPublication and returns a complete RSS 2.0 XML string. Call it from a server-side route handler and return the result as the response.
generateFeed needs a baseUrl: your website's origin. Pass feedUrl too (the feed's own URL), so the feed identifies itself to readers:
import { fetchPublication, generateFeed } from '@skyscribe-sdk/core';
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social');
const xml = generateFeed(publication, {
baseUrl: 'https://alice.example.com',
feedUrl: 'https://alice.example.com/feed.xml',
});
The options:
| Option | Default | Meaning |
|---|---|---|
baseUrl | (required) | Your website's origin, used to build each Document's link |
feedUrl | none | The feed's own URL, added as an atom:link rel="self" |
language | "en" | The channel's <language> |
limit | all | Include at most this many Documents |
// app/routes/feed.ts
import { fetchPublication, generateFeed } from '@skyscribe-sdk/core';
export async function loader({ request }: { request: Request }) {
const origin = new URL(request.url).origin;
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social', request.signal);
const xml = generateFeed(publication, {
baseUrl: origin,
feedUrl: `${origin}/feed.xml`,
});
return new Response(xml, {
headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' },
});
}
// app/feed.xml/route.ts
import { fetchPublication, generateFeed } from '@skyscribe-sdk/core';
export async function GET(request: Request) {
const origin = new URL(request.url).origin;
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social', request.signal);
const xml = generateFeed(publication, {
baseUrl: origin,
feedUrl: `${origin}/feed.xml`,
});
return new Response(xml, {
headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' },
});
}
// src/routes/feed.xml/+server.ts
import { fetchPublication, generateFeed } from '@skyscribe-sdk/core';
import type { RequestHandler } from './$types';
export const GET: RequestHandler = async ({ url }) => {
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social');
const xml = generateFeed(publication, {
baseUrl: url.origin,
feedUrl: `${url.origin}/feed.xml`,
});
return new Response(xml, {
headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' },
});
};
Tip
Take the origin from request.url at runtime rather than hardcoding it, so the same code works in development and production without any configuration.
generateFeed includes the Documents in the Publication's Categories, which are its published Documents. Items come out in Category order, then in each Category's Document order, not sorted by date, and limit applies to that order. To get newest first, sort the Categories' Documents by publishedAt before calling generateFeed.
Each item contains:
<title>: the Document's title<description>: the Document's description (empty if none)<link>: {baseUrl}/{basePath}/{category slug}/{document slug}<pubDate>: publishedAt, or createdAt if the Document has no publish date<guid>: the same URL as <link>Add a <link> tag in your HTML <head> so feed readers can discover the feed automatically:
<link
rel="alternate"
type="application/rss+xml"
title="My Blog"
href="/feed.xml"
/>
publicationMeta and the other meta helpers don't add this tag, so add it in your root layout.