BaseHub
Publish BaseHub content as docs.
BaseHub needs no Vuesho package. Its SDK reads the items on the server, with their rich text as Markdown, which markdown-it renders.
Setup
Prepare the Repository
Create a collection with a rich text field in BaseHub, or fork the Fumadocs template, whose documentation collection has a richText field.
Install the Packages
npm i basehub markdown-itStore the Token
Put the repository token, from the Developers tab in BaseHub, in .env:
BASEHUB_TOKEN=bshb_...npx basehub writes your repository's types to basehub-types.d.ts. Run it again after the schema changes, or run npx basehub dev next to vuesho dev to keep the types current.
Query the Collection
Write a function that lists the items as pages. Each page keeps its Markdown under a symbol key, so the browser doesn't receive it with the page data:
import { basehub } from "basehub";
export const body = Symbol("body");
export async function listPages() {
const { documentation } = await basehub().query({
documentation: {
items: { _slug: true, _title: true, richText: { markdown: true } },
},
});
return documentation.items.map((item) => ({
type: "page" as const,
path: `${item._slug}.md`,
data: { title: item._title, [body]: item.richText?.markdown ?? "" },
}));
}basehub() reads BASEHUB_TOKEN from the environment, and reads the drafts under vuesho dev.
Connect the Source
Pass listPages as a dynamic source's files, and render its pages with a plugin. Create md and render() in a module, as in Rendering Markdown:
import { createSite, recommendedPreset } from "vuesho/config";
import { extractStructuredData, buildToc } from "vuesho/markdown";
import { md, render } from "./src/server/markdown";
import { body, listPages } from "./src/server/basehub";
export default createSite({ files: listPages, staleTime: 60_000 }).plugins(
recommendedPreset(),
{
name: "site:basehub",
getPageBody: async (page) => ({ html: await render(page.data[body]) }),
getPageToc: (page) => buildToc(md.parse(page.data[body], {})),
getPageStructuredData: (page) => extractStructuredData(md.parse(page.data[body], {})),
getPageText: (page) => page.data[body],
},
);To use the BaseHub pages next to the Markdown in content/, give their source a baseDir, as in Multiple Collections:
createSite({
docs: docs.toSource(),
basehub: { baseDir: "basehub", files: listPages, staleTime: 60_000 },
});Pages
An item's slug sets its URL. A slug like guides/install makes a folder in the sidebar, and the slug index is its folder's index page.
- A query returns at most 500 items, so page through a larger collection with
skipin__args. - BaseHub leaves out custom component blocks from the Markdown.
- HTML in the Markdown renders as text.
- With an image optimizer, add
assets.basehub.comto itsremotePatterns, as Remote Images shows, or the images fail to load.
Refreshing Content
The server reads the items again once staleTime passes, or when a webhook calls revalidateLoader(), as in Dynamic Rendering. authenticateWebhook() from basehub/workflows checks the request's signature:
import { authenticateWebhook } from "basehub/workflows";
createSite({ files: listPages, staleTime: 60_000 }).plugins({
name: "site:basehub",
getPageBody: (page) => ({ html: md.render(page.data[body]) }),
// The other hooks, as above
routes({ createApi }) {
createApi({
path: "/api/revalidate",
POST: async (request) => {
const secret = process.env.BASEHUB_WEBHOOK_SECRET as `bshb_workflow_${string}:${string}`;
const result = await authenticateWebhook({
body: request.body,
signature: request.headers,
secret,
});
if (!result.success) return new Response(null, { status: 401 });
await this.revalidateLoader();
return new Response();
},
});
},
});In BaseHub, add a Workflow block that runs on each commit and calls https://docs.example.com/api/revalidate. Put its signing secret in BASEHUB_WEBHOOK_SECRET.
A static build queries the collection once and prerenders every page.