Skip to Content
Vuesho

Obsidian

Publish an Obsidian vault as docs.

@vuesho/obsidian publishes an Obsidian vault as it is. The server reads the notes while the site runs, and renders Obsidian's wikilinks, embeds and callouts without converting the files.

Setup

Install the Package

npm i @vuesho/obsidian

Connect the Vault

Connect the vault in the config:

vuesho.config.ts
import { createObsidian, obsidianPlugin } from "@vuesho/obsidian";
import { createSite, recommendedPreset } from "vuesho/config";

const vault = createObsidian({ dir: "vault" }); 

export default createSite(vault.source({ staleTime: 60_000 })).plugins(
  recommendedPreset(),
  obsidianPlugin(), 
);

To use the notes next to the Markdown in content/, give their source a baseDir, as in Multiple Collections:

vuesho.config.ts
createSite({
  docs: docs.toSource(),
  vault: vault.source({ baseDir: "vault", staleTime: 60_000 }), 
}).plugins(recommendedPreset(), obsidianPlugin());

A note's path in the vault sets its URL, and media files are served under /obsidian-files:

FileURL
index.md/
notes/Deep Note.md/notes/Deep Note
attachments/diagram.png/obsidian-files/attachments/diagram.png

dir follows the same rules as createLocalContent(). On a host without a file system, like Cloudflare Workers, use a static build, which renders the notes when the site builds.

Notes

Notes support this Obsidian syntax:

SyntaxRenders as
[[Note]], [[Note#Heading|text]]A link to the note or its heading
![[image.png]]The image
![[Note]], ![[Note#Heading]] on its own lineThe note, or the heading's section
![[Note#^id]] on its own lineThe block or list item marked ^id
![[Note]] in a lineA link to the note
[text](Note.md#Heading), ![](image.png)A link to the note, or the image
> [!warning] TitleA callout
A paragraph ending with ^idA block that ^id links to
%% comment %%Nothing

Links and aliases resolve as in Obsidian, and so do Markdown links without a scheme or a leading /. A link that resolves to nothing, HTML, and a code block of an unknown language, like dataview, render as text.

Frontmatter

The frontmatter is read as leniently as Obsidian reads it, and a note without a title uses its file name.

schema validates the frontmatter with a Standard Schema, and types page.data:

vuesho.config.ts
import { createObsidian } from "@vuesho/obsidian";
import { z } from "zod";

const vault = createObsidian({
  dir: "vault",
  schema: z.object({
    title: z.string().optional(),
    status: z.enum(["draft", "done"]),
  }),
});

An invalid note stops the server from starting, and fails the reload in development. On a running server, the server logs an error and keeps the note's last valid version, or leaves out a new note.

A meta.json or meta.<lang>.json in a vault folder orders the sidebar and names the folder, as in Navigation. metaSchema validates it. The vault's other data files, in .json, .yaml, .yml or .toml, are neither pages nor served.

Rendering

The notes render with the Markdown elements of vuesho/components and Obsidian's callouts. To use other components, replace the obsidian body in your theme. The body receives the note as a hast tree in tree, and toVNodes() from vuesho/ui/hast renders the tree with your components. @vuesho/obsidian/ui has the callouts.

The notes use only the highlight option of the config's markdown. markdownItPlugins adds markdown-it plugins, which run after Obsidian's syntax:

vuesho.config.ts
import { katex } from "@mdit/plugin-katex";
import { createObsidian } from "@vuesho/obsidian";

const vault = createObsidian({ dir: "vault", markdownItPlugins: [katex] }); 

Media

The vault's media files, like images, are served under /obsidian-files, or files.path, and copied into a static build. The route never serves notes, data files, hidden files like those of .obsidian, or files outside include.

An SVG file is sent with a Content-Security-Policy that blocks its scripts, as Local Files shows.

Private Files

Every other file that include matches is public. To keep private files out, narrow include, like ["**/*.{md,mdx}", "attachments/**"].

url returns the URL of a media file served elsewhere, like a copy in public/ or on a CDN. Return undefined to serve the file from the route:

vuesho.config.ts
const vault = createObsidian({ dir: "vault", url: (file) => `/vault/${file}` });

Multiple Vaults

Give each vault a different baseDir and files.path:

vuesho.config.ts
import { createObsidian, obsidianPlugin } from "@vuesho/obsidian";

const work = createObsidian({ dir: "vaults/work", files: { path: "/work-files" } });
const personal = createObsidian({ dir: "vaults/personal", files: { path: "/personal-files" } });

createSite({
  work: work.source({ baseDir: "work" }),
  personal: personal.source({ baseDir: "personal" }),
}).plugins(recommendedPreset(), obsidianPlugin()); 

Refreshing Content

In development, editing a note reloads the page. In production, the server reads the vault again once staleTime passes, or when a webhook calls revalidateLoader(), as in Dynamic Rendering.

Options

createObsidian()

Prop

Type

vault.source()

Prop

Type