JavaScript SDK
EngineersRead published content, assets, search results and draft previews from a site with the JavaScript SDK.
- Overview and install
The JavaScript SDK, @quilletcms/sdk, is the package a website uses to read what content managers have published in Quillet: documents, files, search results and, when asked, a draft.
- Configure the SDK
The SDK takes its settings from your code, the environment and a .quilletrc file, in that order, and it takes the delivery key from the environment alone.
- Reading content
Four methods read published content: get for one document, list for one folder, tree for a folder's whole subtree as navigation, and walk for every document under a folder with its body.
- Assets
Every file a document uses arrives inlined in its body as an Asset, with a url to render, and the SDK serves private files from your own site so readers never see the CMS or a token.
- Variables and Markdown
The SDK fills {{ variables }} that content managers write into their text, and turns a Markdown body into sanitised HTML whose images point where your site serves them and whose headings carry the anchors search links to.
- Search
q.search asks an environment's published content a question in words and answers with the pages that match, the heading on each page the match sits under, and a plain-text snippet around it.
- Previewing drafts
A content manager can open the draft they are editing on the real site, drawn by the site's own code, and the SDK reads that draft with the short-lived preview token the dashboard hands the site.
- Types
quillet-sdk types writes a TypeScript declaration for every component in an environment, so a site's code that reads a page knows its fields and is told at compile time when a component changes under it.
- Next.js
@quilletcms/sdk/next gives a Next.js App Router site a client whose every read is stored in Next's data cache under tags, so a webhook from Quillet can refresh exactly the pages a publish changed.
- Static sites
A static site reads Quillet once, at build time, and ships plain files; the SDK's tree, walk and get do the reading, and this documentation site is built exactly that way.