Getting started
This guide uses @skyscribe-sdk/core, the framework-agnostic package. If you're using React, Angular, Vue, Next.js, Nuxt or React Router, the framework guides wrap these same functions in your framework's idioms.
npm install @skyscribe-sdk/core
pnpm add @skyscribe-sdk/core
yarn add @skyscribe-sdk/core
A Publication is identified by two things: the author's handle (or DID), and the Publication's canonical HTTPS URL.
import { fetchPublication } from "@skyscribe-sdk/core";
const author = "anthonycregan.dev";
const publication = await fetchPublication(author, "https://anthonycregan.co.uk");
console.log(publication.name);
console.log(publication.description);
// Published Documents, organised into Categories
for (const category of publication.categories) {
console.log(category.title);
for (const document of category.documents) {
console.log(document.title, document.slug);
}
}
With a Document's slug (from the Publication's DocumentRef list, or from your URL), fetch the full Document, including its HTML content:
import { fetchDocumentBySlug } from "@skyscribe-sdk/core";
const document = await fetchDocumentBySlug(
"anthonycregan.dev",
"https://anthonycregan.co.uk",
"my-first-post",
);
console.log(document.title);
console.log(document.description);
console.log(document.content); // Full HTML
console.log(document.createdAt);
console.log(document.uri); // The Document's AT URI
fetchDocumentBySlug looks the slug up in the Publication record, then fetches the Document record it points to. If you already have the record's rkey (from an AT URI), fetchDocument(author, rkey) fetches it directly.
Rendering the HTML
SkyScribe sanitises Document HTML when the author saves it, but the SDK returns whatever is stored in the author's account, and any app can write to an account's records. Rendering your own account's content as-is is fine. If you render Documents from accounts you don't control, sanitise the HTML first, for example with DOMPurify.
To render it, use dangerouslySetInnerHTML in React, v-html in Vue, or [innerHTML] in Angular.
Use the Publication's domain and basePath fields to build canonical Document URLs:
import type { StandardPublication } from "@skyscribe-sdk/core";
function documentUrl(
publication: StandardPublication,
categorySlug: string,
documentSlug: string,
): string {
const base = publication.basePath
? `https://${publication.domain}/${publication.basePath}`
: `https://${publication.domain}`;
return `${base}/${categorySlug}/${documentSlug}`;
}
See Building URLs for the full rules.
Every fetch function accepts an optional AbortSignal as its last argument. Pass request.signal on the server, or an AbortController's signal in client code:
const controller = new AbortController();
const publication = await fetchPublication(
author,
"https://anthonycregan.co.uk",
controller.signal,
);
// Cancel the request if needed (e.g. component unmount, route change)
controller.abort();
The framework adapters wire this up for you. You only manage the signal yourself when using @skyscribe-sdk/core directly.
@skyscribe-sdk/core