Guides
@skyscribe-sdk/core exports getSitemapEntries, which takes a fetched StandardPublication and returns an array of { url, lastmod? } objects. You build the XML from them yourself, so you keep full control of the output and can merge in your own pages.
import { fetchPublication, getSitemapEntries } from '@skyscribe-sdk/core';
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social');
const entries = getSitemapEntries(publication, { baseUrl: 'https://alice.example.com' });
// entries is: Array<{ url: string; lastmod?: string }>
Two kinds of Document are left out: one whose canonical URL is another website's (an imported Document whose author kept the original as canonical), and one whose author turned on noindex in its SEO Settings. Both still appear on your site and in your feed: they just aren't offered to search engines.
// app/routes/sitemap.ts
import { fetchPublication, getSitemapEntries } 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 entries = getSitemapEntries(publication, { baseUrl: origin });
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...entries.map(
(e) =>
`<url><loc>${e.url}</loc>${e.lastmod ? `<lastmod>${e.lastmod}</lastmod>` : ''}</url>`
),
'</urlset>',
].join('');
return new Response(xml, {
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
});
}
// app/sitemap.xml/route.ts
import { fetchPublication, getSitemapEntries } 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 entries = getSitemapEntries(publication, { baseUrl: origin });
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...entries.map(
(e) =>
`<url><loc>${e.url}</loc>${e.lastmod ? `<lastmod>${e.lastmod}</lastmod>` : ''}</url>`
),
'</urlset>',
].join('');
return new Response(xml, {
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
});
}
// src/routes/sitemap.xml/+server.ts
import { fetchPublication, getSitemapEntries } 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 entries = getSitemapEntries(publication, { baseUrl: url.origin });
const xml = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
...entries.map(
(e) =>
`<url><loc>${e.url}</loc>${e.lastmod ? `<lastmod>${e.lastmod}</lastmod>` : ''}</url>`
),
'</urlset>',
].join('');
return new Response(xml, {
headers: { 'Content-Type': 'application/xml; charset=utf-8' },
});
};
getSitemapEntries only knows about the Publication's Documents. Append any other pages your website has, such as an about page:
const entries = getSitemapEntries(publication, { baseUrl: origin });
const allEntries = [
...entries,
{ url: `${origin}/about` },
];
getSitemapEntries returns, in order:
baseUrlbasePath: {baseUrl}/{basePath}{baseUrl}/{basePath}/{category slug}{baseUrl}/{basePath}/{category slug}/{document slug}Document entries have a lastmod date (YYYY-MM-DD) taken from the Document's updatedAt, when it's set. Drafts aren't in the Publication record, so they're never included.
Note
The URLs follow the standard layout. If your website uses different paths for Category pages, or doesn't have them, filter or rewrite the entries before building the XML.