From VitePress
Move a VitePress site to Vuesho.
Like VitePress, Vuesho runs on Vite and compiles Markdown with Vue's template syntax, so most pages need only small changes. To port a whole site, start from the script that ports the Vitest docs.
Concepts
| VitePress | Vuesho |
|---|---|
.vitepress/config.ts | vuesho.config.ts, and vite.config.ts for Vite's options |
srcDir | content/, or defineDocs({ dir }) |
themeConfig.sidebar | Folders and meta files |
themeConfig.nav | Navbar links |
themeConfig.logo | site.logo |
.vitepress/theme | src/theme.ts |
| Default theme slots | Layout slots |
layout: home | A landing page |
useData() | usePage() and the other composables |
| Data loaders | props in a custom page, or a plugin's data route |
| Dynamic routes | Path params |
transformPageData | A plugin's transformPage hook |
| Local search | The built-in search |
lastUpdated | Git dates |
editLink | site.git in the config |
base | Vite's base, see Deploying |
By default:
- URLs have no
.html. - A relative link to a
.mdfile, like./install.md, resolves to its page. A link from the root is a URL of the site, and a URL ending in.mdis a page's Markdown version, so VitePress's/guide/install.mdbecomes./install.mdor/guide/install. - Dead links fail the build.
Layout and Navigation
Navbar and Logo
export default defineConfig({
themeConfig: {
logo: "/logo.svg",
nav: [
{ text: "Guide", link: "/guide/" },
{ text: "Config", link: "/config" },
],
},
});The notebook layout puts the links in its header, like VitePress. Set it in src/theme.ts:
import { defineTheme } from "vuesho/theme";
import defaultTheme from "vuesho/theme/default";
import NotebookLayout from "vuesho/layouts/notebook";
export default defineTheme({
extends: defaultTheme,
// The links are in the header, and in the sidebar below `lg`.
layouts: { default: NotebookLayout },
});Sidebar
The folders in content/ are the sidebar, and a meta file in a folder names and orders its pages:
export default defineConfig({
themeConfig: {
sidebar: [
{
text: "Guide",
items: [
{ text: "Install", link: "/guide/install" },
{ text: "Getting Started", link: "/guide/getting-started" },
],
},
],
},
});To write the whole sidebar by hand, replace the tree with a page tree transformer:
createSite(docs.toSource(), {
pageTree: {
transformers: [
{
root: (root) => ({
...root,
children: [
{ type: "separator", name: "Guide" },
{ type: "page", name: "Install", url: "/guide/install" },
{ type: "page", name: "GitHub", url: "https://github.com/acme/docs", external: true },
],
}),
},
],
},
});Home Page
---
layout: home
hero:
name: Acme Docs
actions:
- text: Get Started
link: /guide/
---create-vuesho generates a landing page with the same parts:
npm create vuesho@latest my-docsThe docs move under /docs with baseSlugs. See Landing Page for the full example:
export default createSite(docs.toSource(), { baseSlugs: ["docs"] });Converting Pages
admonitionsPlugin() renders containers and GitHub alerts as callouts, so they need no conversion:
import { admonitionsPlugin } from "vuesho/markdown";
createSite(docs.toSource()).plugins(recommendedPreset(), admonitionsPlugin());Code groups and includes have a different syntax:
# Installation
::: code-group
```sh [npm]
npm i -D vitest
```
```sh [pnpm]
pnpm add -D vitest
```
:::
## Writing Tests {#writing}
<!--@include: ./parts/first-test.md-->Code Blocks
```ts:line-numbers{2,3} [config.ts]
export default {
title: "Docs",
description: "Guides",
};
```
::: code-group
```ts [config.ts]
export default { title: "Docs" };
```
```js [config.js]
export default { title: "Docs" };
```
:::Highlight a line with a [!code highlight] comment, or a range with [!code highlight:2] on its first line. Write an install command as one npm code block, as above.
Includes
[[toc]]
<<< @/snippets/example.tscwd resolves the path from the project root, while VitePress's @/ starts at its source root. A Markdown include is <include>./part.md</include>, as above, and a range of lines, like {3,10}, follows the path as in VitePress.
Page Data
{{ $frontmatter.title }} is {{ $params.pkg }}.
<Badge type="tip" text="beta" />
:tada:pkgis a prop of a page with a path param.- Add a
Badge.vuetosrc/components/content/. - A shortcode like
:tada:needs@mdit/plugin-emoji.
Heading IDs
Vuesho and VitePress generate different IDs for some headings:
| Heading | Vuesho | VitePress |
|---|---|---|
## test.each | #testeach | #test-each |
## vi.fn() | #vifn | #vi-fn |
## 2. Setup | #2-setup | #_2-setup |
To keep the existing anchors, add a slug module that copies VitePress's slug function from @mdit-vue/shared:
const control = /[\u0000-\u001f]/g;
const special = /[\s~`!@#$%^&*()\-_+=[\]{}|\\;:"'“”‘’<>,.?/]+/g;
const combining = /[̀-ͯ]/g;
export default (text: string) =>
text
.normalize("NFKD")
.replace(combining, "")
.replace(control, "")
.replace(special, "-")
.replace(/-{2,}/g, "-")
.replace(/^-+|-+$/g, "")
.replace(/^(\d)/, "_$1")
.toLowerCase();export default createSite(docs.toSource()).config({
markdown: { slug: "src/slug.ts" },
});A [#id] on a heading still overrides the slug module.
Server Rendering
Unlike VitePress's dev server, vuesho dev renders each page on the server too. Put code that reads window or document in onMounted().