✨ Publier v1 is live — a polished docs platform built for the open web.
Skip to content

Snippets

Reuse parameterized MDX content across multiple pages with the Snippet component.

The <Snippet> component lets you write MDX content once and embed it across multiple pages. It inlines the referenced file at build time — no runtime overhead.

Setup

Configure the snippets directory in publier.config.yaml:

publier.config.yaml
snippets:
directory: src/content/snippets # default: content/snippets

The directory is relative to the project root. Snippet support turns on automatically when the snippets option is set.

Creating a snippet

Add an .mdx file to your snippets directory:

src/content/snippets/install.mdx
Install the package:
```bash
pnpm add {{package}}
Snippets are plain MDX — they can contain headings, code blocks, callouts, or any other content.
## Using a snippet
Embed the snippet with the `<Snippet>` component. Pass the filename (including `.mdx`) as the `file` prop:
```mdx
<Snippet file="install.mdx" package="@publier/shell" />

The {{package}} placeholder is replaced with @publier/shell at build time.

Multiple placeholders

Snippets support any number of named placeholders:

src/content/snippets/api-note.mdx
This endpoint requires a {{tier}} plan or higher.
See the [pricing page]({{pricingUrl}}) for details.
<Snippet file="api-note.mdx" tier="Pro" pricingUrl="/pricing" />

Props

PropTypeDescription
filestringFilename of the snippet, including the .mdx extension. Required.
*stringAny additional prop replaces the matching {{propName}} placeholder.

Path safety

The file prop is resolved relative to the snippets directory. Path traversal references (../, /etc/passwd) are rejected with a warning and the <Snippet> node is left untouched.

Directory layout

src/
content/
docs/
getting-started.mdx
snippets/ ← configure via snippets.directory
install.mdx
api-note.mdx
prerequisites.mdx

Snippet files are not added to the page tree or search index — they exist only to be embedded in other pages.