Frameworks
For SvelteKit, Astro, Remix, or any other framework that loads data on the server, install @skyscribe-sdk/core and call its functions directly in your loaders or server components. They're plain async functions that work anywhere JavaScript runs.
// src/routes/blog/+page.server.ts
import { fetchPublication } from '@skyscribe-sdk/core';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ request }) => {
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social', request.signal);
return { publication };
};
<!-- src/routes/blog/+page.svelte -->
<script lang="ts">
import type { PageData } from './$types';
export let data: PageData;
</script>
<h1>{data.publication.name}</h1>
{#each data.publication.categories as category}
<section>
<h2>{category.title}</h2>
<ul>
{#each category.documents as ref}
<li><a href="/blog/{category.slug}/{ref.slug}">{ref.title}</a></li>
{/each}
</ul>
</section>
{/each}
For Document pages, look the Document up by the slug in params:
// src/routes/blog/[category]/[slug]/+page.server.ts
import { error } from '@sveltejs/kit';
import { fetchDocumentBySlug, NotFoundError } from '@skyscribe-sdk/core';
import type { PageServerLoad } from './$types';
export const load: PageServerLoad = async ({ params, request }) => {
try {
const document = await fetchDocumentBySlug(
'alice.bsky.social',
'https://alice.bsky.social',
params.slug,
request.signal,
);
return { document };
} catch (err) {
if (err instanceof NotFoundError) error(404, 'Not found');
throw err;
}
};
---
// src/pages/blog/index.astro
import { fetchPublication } from '@skyscribe-sdk/core';
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social');
---
<h1>{publication.name}</h1>
{publication.categories.map((category) => (
<section>
<h2>{category.title}</h2>
<ul>
{category.documents.map((ref) => (
<li><a href={`/blog/${category.slug}/${ref.slug}`}>{ref.title}</a></li>
))}
</ul>
</section>
))}
For static Document pages, getStaticPaths already has each Document's DocumentRef, so pass its location along and fetch the Document directly. Take the account from the ref's AT URI rather than assuming the Publication owner's: a Document credited to a contributor can live in their account.
---
// src/pages/blog/[category]/[slug].astro
import { fetchPublication, fetchDocument, slugFromUri } from '@skyscribe-sdk/core';
export async function getStaticPaths() {
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social');
return publication.categories.flatMap((category) =>
category.documents.map((ref) => ({
params: { category: category.slug, slug: ref.slug },
// at://{did}/site.standard.document/{rkey}
props: { did: ref.uri.split('/')[2], rkey: slugFromUri(ref.uri) },
}))
);
}
const { did, rkey } = Astro.props;
const document = await fetchDocument(did, rkey);
---
<article>
<h1>{document.title}</h1>
<div class="scribe-content" set:html={document.content} />
</article>
If you render Documents from accounts you don't control, sanitise content first (see Rendering the HTML).
Show the Publication's owner visit figures on its Insights tab in SkyScribe (free, cookie-free):
import { siteAnalyticsScriptTag, loadSiteAnalytics } from '@skyscribe-sdk/core';
// Print siteAnalyticsScriptTag() into your page template before </body>,
// or call loadSiteAnalytics() from a script that runs in the browser.
Figures only appear once your website serves the Publication verification file. See the Site Analytics guide for that, privacy, and CSP.