Installation
This guide will help you install and set up Ptero in your project. Choose the installation method that best fits your workflow.
Prerequisites
Before installing Ptero, make sure you have:
- Node.js version 18.0 or above
- pnpm, npm, or yarn package manager
- A SvelteKit project (or willingness to create one)
Quick Start
The fastest way to get started is using the Ptero CLI in an existing SvelteKit project:
# Install Ptero packages
pnpm add -D ptero-cli mdsvex
# Run the initialization command
pnpm ptero init
# Start your development server
pnpm devVisit http://localhost:5173/docs/latest to see your documentation site.
:::note
The ptero init command is idempotent - you can run it multiple times safely. It will only add missing files and configurations.
:::
Starting from Scratch
If you donβt have a SvelteKit project yet:
# Create a new SvelteKit project
pnpm create svelte@latest my-docs
cd my-docs
# Install dependencies
pnpm install
# Add Ptero
pnpm add -D ptero-cli mdsvex
pnpm ptero init
# Start developing
pnpm devWhat Gets Installed
When you run ptero init, the CLI will:
Install docs packages (if not already present):
mdsvex- Markdown processing with Svelte support- UI components added via
ptero add <component>
Create configuration files:
ptero.config.ts- Main configuration file- Updates to
svelte.config.jsfor MDsveX integration
Scaffold directory structure:
src/ βββ content/ β βββ docs/ # Your markdown files go here β βββ intro/ β β βββ index.md β βββ guides/ β βββ getting-started.md βββ routes/ β βββ docs/ β βββ [version]/ β β βββ +layout.svelte β β βββ +layout.server.ts β β βββ +page.svelte β β βββ [...slug]/ β β βββ +page.svelte β β βββ +page.server.tsAdd example content:
- Sample markdown files to help you get started
- Frontmatter examples
- Basic navigation structure
Manual Installation
If you prefer more control over the installation process:
Step 1: Install Dependencies
pnpm add -D mdsvexStep 2: Configure MDsveX
Update your svelte.config.js:
import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { mdsvex } from 'mdsvex';
/** @type {import('@sveltejs/kit').Config} */
const config = {
extensions: ['.svelte', '.md'],
preprocess: [
vitePreprocess(),
mdsvex({
extensions: ['.md'],
layout: {
docs: './src/lib/layouts/DocsLayout.svelte'
}
})
],
kit: {
adapter: adapter()
}
};
export default config;Step 3: Create Configuration
Create ptero.config.ts in your project root:
import type { PteroConfig } from 'ptero-core';
const config: PteroConfig = {
site: {
title: 'My Documentation',
description: 'Comprehensive documentation for my project',
url: 'https://docs.example.com'
},
versions: {
current: 'latest',
available: [{ id: 'latest', label: 'Latest', status: 'latest' }]
},
sidebar: {
sections: [
{
title: 'Introduction',
items: [{ title: 'Getting Started', slug: 'intro/getting-started' }]
}
]
}
};
export default config;Step 4: Set Up Routes
Create the following route structure:
src/routes/docs/[version]/+layout.server.ts:
import { loadSidebar, loadConfig } from 'ptero-core';
export async function load({ params }) {
const config = await loadConfig();
const sidebar = await loadSidebar(params.version);
return {
sidebar,
config,
version: params.version
};
}src/routes/docs/[version]/+layout.svelte:
<script lang="ts">
let { children, data } = $props();
</script>
<DocsLayout sidebar={data.sidebar} currentVersion={data.version}>
{@render children()}
</DocsLayout>src/routes/docs/[version]/[...slug]/+page.server.ts:
import { loadDoc } from 'ptero-core';
import { error } from '@sveltejs/kit';
export async function load({ params }) {
const doc = await loadDoc(params.version, params.slug);
if (!doc) {
throw error(404, 'Page not found');
}
return { doc };
}src/routes/docs/[version]/[...slug]/+page.svelte:
<script lang="ts">
let { data } = $props();
</script>
<svelte:component this={data.doc.component} />Step 5: Create Content
Create your first documentation file at src/content/docs/intro/getting-started.md:
---
title: Getting Started
description: Learn the basics
section: Introduction
order: 1
---
# Getting Started
Welcome to your documentation!Add components (optional)
Use the CLI to pull in prebuilt UI components (shadcn-style):
pnpm ptero add avatarPackage Managers
Ptero works with all major package managers:
pnpm (Recommended)
pnpm add -D ptero-cli mdsvex
pnpm ptero initnpm
npm install --save-dev ptero-cli mdsvex
npm exec ptero inityarn
yarn add -D ptero-cli mdsvex
yarn ptero initTroubleshooting
Port Already in Use
If port 5173 is already in use, you can specify a different port:
pnpm dev -- --port 3000MDsveX Not Processing Files
Make sure your svelte.config.js includes .md in the extensions array and has mdsvex in the preprocess chain.
TypeScript Errors in Config
Ensure you have the correct types installed:
pnpm add -D @types/nodeBuild Errors
If you encounter build errors, try clearing the .svelte-kit directory:
rm -rf .svelte-kit
pnpm devNext Steps
Now that you have Ptero installed:
Upgrading
To upgrade to the latest version of Ptero:
pnpm update ptero-cliCheck the changelog for breaking changes before upgrading major versions.