Frameworks
@skyscribe-sdk/react-router-framework provides loader factories for React Router v7/v8 framework mode. The loaders pass request.signal through, so a fetch is cancelled if the visitor navigates away before it finishes.
Note
This package is for framework (server) mode only. For React Router in SPA or library mode, use @skyscribe-sdk/react instead.
npm install @skyscribe-sdk/react-router-framework
createPublicationLoader creates a loader for a route that shows the whole Publication: its Categories and their Documents.
// app/routes/blog.tsx
import { createPublicationLoader } from '@skyscribe-sdk/react-router-framework';
import { useLoaderData } from 'react-router';
export const loader = createPublicationLoader('alice.bsky.social', 'https://alice.bsky.social');
export default function Blog() {
const publication = useLoaderData<typeof loader>();
return (
<main>
<h1>{publication.name}</h1>
{publication.categories.map((category) => (
<section key={category.slug}>
<h2>{category.title}</h2>
<ul>
{category.documents.map((ref) => (
<li key={ref.uri}>
<a href={`/blog/${category.slug}/${ref.slug}`}>{ref.title}</a>
</li>
))}
</ul>
</section>
))}
</main>
);
}
createDocumentRouteLoader creates a loader for a route whose URL contains the Document's slug. It looks the slug up in the Publication, fetches the Document, and returns the StandardDocument, with its AT URI as uri.
// app/routes/blog.$categorySlug.$documentSlug.tsx
import { createDocumentRouteLoader } from '@skyscribe-sdk/react-router-framework';
import { useLoaderData } from 'react-router';
export const loader = createDocumentRouteLoader('alice.bsky.social', 'https://alice.bsky.social');
export default function DocumentPage() {
const { title, content, uri } = useLoaderData<typeof loader>();
return (
<article>
<h1>{title}</h1>
<div className="scribe-content" dangerouslySetInnerHTML={{ __html: content }} />
</article>
);
}
The slug is read from the documentSlug route param by default, so name the segment $documentSlug (or :documentSlug in routes.ts). If your param has a different name, pass it as the third argument: createDocumentRouteLoader(author, publicationUrl, 'slug').
Pass uri to @skyscribe-sdk/social's LikeButton as documentUri if you want social buttons on the Document page. If you render Documents from accounts you don't control, sanitise content first (see Rendering the HTML).
documentMeta returns Open Graph and Twitter Card tags for rich link previews, and the site.standard link tags. It needs the Publication as well, so fetch both in your loader:
import { createDocumentRouteLoader, documentMeta } from '@skyscribe-sdk/react-router-framework';
import { fetchPublication } from '@skyscribe-sdk/core';
import type { Route } from './+types/blog.$categorySlug.$documentSlug';
const loadDocument = createDocumentRouteLoader('alice.bsky.social', 'https://alice.bsky.social');
export async function loader(args: Route.LoaderArgs) {
const [document, publication] = await Promise.all([
loadDocument(args),
fetchPublication('alice.bsky.social', 'https://alice.bsky.social', args.request.signal),
]);
return { document, publication };
}
export function meta({ loaderData }: Route.MetaArgs) {
if (!loaderData) return [{ title: 'My Blog' }];
return [
...documentMeta(loaderData.document, loaderData.publication),
{ title: `${loaderData.document.title} | My Blog` },
];
}
publicationMeta(publication) does the same for the home and Category pages, and standardSiteLinks(publication) gives just the link tags. See the meta tags guide for more.
The site.standard spec lets apps confirm that a website really belongs to a Publication by requesting /.well-known/site.standard.publication, which should return the Publication's AT URI. createWellKnownLoader serves exactly that. Add it even if you don't use Site Analytics: readers and aggregators that show site.standard content check it, and Site Analytics only shows figures once it names your Publication. A SkyScribe Publication's URL is a bare domain, so the file is always at the root, even when your Documents live under a base path.
// app/routes.ts
route(".well-known/site.standard.publication", "routes/well-known-publication.ts"),
// app/routes/well-known-publication.ts
import { createWellKnownLoader } from '@skyscribe-sdk/react-router-framework';
export const loader = createWellKnownLoader('alice.bsky.social', 'https://alice.bsky.social');
Show the Publication's owner visit figures on its Insights tab in SkyScribe (free, cookie-free):
// Once, in app/root.tsx
import { SiteAnalytics } from '@skyscribe-sdk/react';
<SiteAnalytics />
Figures only appear once your website serves the Publication verification file. See the Site Analytics guide for that, privacy, and CSP.
The main types from @skyscribe-sdk/core are re-exported:
import type { StandardPublication, StandardDocument, DocumentRef, Category } from '@skyscribe-sdk/react-router-framework';