Skip to Content
Vuesho

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

VitePressVuesho
.vitepress/config.tsvuesho.config.ts, and vite.config.ts for Vite's options
srcDircontent/, or defineDocs({ dir })
themeConfig.sidebarFolders and meta files
themeConfig.navNavbar links
themeConfig.logosite.logo
.vitepress/themesrc/theme.ts
Default theme slotsLayout slots
layout: homeA landing page
useData()usePage() and the other composables
Data loadersprops in a custom page, or a plugin's data route
Dynamic routesPath params
transformPageDataA plugin's transformPage hook
Local searchThe built-in search
lastUpdatedGit dates
editLinksite.git in the config
baseVite's base, see Deploying

By default:

  • URLs have no .html.
  • A relative link to a .md file, like ./install.md, resolves to its page. A link from the root is a URL of the site, and a URL ending in .md is a page's Markdown version, so VitePress's /guide/install.md becomes ./install.md or /guide/install.
  • Dead links fail the build.

Layout and Navigation

.vitepress/config.ts
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:

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 },
});

The folders in content/ are the sidebar, and a meta file in a folder names and orders its pages:

.vitepress/config.ts
export default defineConfig({
  themeConfig: {
    sidebar: [
      {
        text: "Guide",
        items: [
          { text: "Install", link: "/guide/install" },
          { text: "Getting Started", link: "/guide/getting-started" },
        ],
      },
    ],
  },
});
meta.ts
install.md
getting-started.md

To write the whole sidebar by hand, replace the tree with a page tree transformer:

vuesho.config.ts
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

index.md
---
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-docs

The docs move under /docs with baseSlugs. See Landing Page for the full example:

vuesho.config.ts
export default createSite(docs.toSource(), { baseSlugs: ["docs"] });

Converting Pages

admonitionsPlugin() renders containers and GitHub alerts as callouts, so they need no conversion:

vuesho.config.ts
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.ts

cwd 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:

Heading IDs

Vuesho and VitePress generate different IDs for some headings:

HeadingVueshoVitePress
## 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:

src/slug.ts
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();
vuesho.config.ts
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().