# 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](https://github.com/fuma-nama/vuesho/blob/dev/scripts/bench/port-vitest.ts).

## Concepts [#concepts]

| VitePress              | Vuesho                                                              |
| ---------------------- | ------------------------------------------------------------------- |
| `.vitepress/config.ts` | `vuesho.config.ts`, and `vite.config.ts` for Vite's options         |
| `srcDir`               | `content/`, or [`defineDocs({ dir })`](/markdown/collections)       |
| `themeConfig.sidebar`  | Folders and [meta files](#sidebar)                                  |
| `themeConfig.nav`      | [Navbar links](#navbar-and-logo)                                    |
| `themeConfig.logo`     | [`site.logo`](#navbar-and-logo)                                     |
| `.vitepress/theme`     | [`src/theme.ts`](/theme)                                            |
| Default theme slots    | [Layout slots](/theme#slots)                                        |
| `layout: home`         | A [landing page](#home-page)                                        |
| `useData()`            | `usePage()` and the other [composables](/client-api)                |
| Data loaders           | `props` in a [custom page](/custom-pages), or a plugin's data route |
| Dynamic routes         | [Path params](/routing#path-params)                                 |
| `transformPageData`    | A plugin's [`transformPage`](/content-hooks#page-data) hook         |
| Local search           | The built-in [search](/search)                                      |
| `lastUpdated`          | [Git dates](/markdown/collections#last-modified-dates)              |
| `editLink`             | `site.git` in the config                                            |
| `base`                 | Vite's `base`, see [Deploying](/deploying#base-path)                |

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](/ai), so VitePress's `/guide/install.md` becomes `./install.md` or `/guide/install`.
- Dead links fail the build.

## Layout and Navigation [#layout-and-navigation]

### Navbar and Logo [#navbar-and-logo]

```ts tab="VitePress" title=".vitepress/config.ts"
export default defineConfig({
  themeConfig: {
    logo: "/logo.svg",
    nav: [
      { text: "Guide", link: "/guide/" },
      { text: "Config", link: "/config" },
    ],
  },
});
```

```ts tab="Vuesho" title="vuesho.config.ts"
export default createSite(docs.toSource()).config({
  site: { name: "Acme", logo: "/logo.svg" },
  ui: {
    layoutProps: {
      links: [
        { text: "Guide", url: "/guide", active: "nested-url" },
        { text: "Config", url: "/config" },
      ],
    },
  },
});
```

The `notebook` layout puts the links in its header, like VitePress. Set it in `src/theme.ts`:

```ts title="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 [#sidebar]

The folders in `content/` are the sidebar, and a [meta file](/navigation#folders) in a folder names and orders its pages:

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

```ts tab="Vuesho" title="content/guide/meta.ts"
export default {
  title: "Guide",
  pages: ["install", "getting-started"],
};
```

```files
content/guide
├── meta.ts
├── install.md
└── getting-started.md
```

To write the whole sidebar by hand, replace the tree with a [page tree transformer](/content-hooks#page-tree):

```ts title="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 [#home-page]

```md tab="VitePress" title="index.md"
---
layout: home
hero:
  name: Acme Docs
  actions:
    - text: Get Started
      link: /guide/
---
```

```vue tab="Vuesho" title="src/pages/index.vue"
<script setup>
import HomeLayout from "vuesho/layouts/home";
</script>

<template>
  <HomeLayout>
    <!-- A hero, features and a footer, in your own markup -->
    <main>...</main>
  </HomeLayout>
</template>
```

`create-vuesho` generates a landing page with the same parts:

```npm
npm create vuesho@latest my-docs
```

The docs move under `/docs` with `baseSlugs`. See [Landing Page](/layouts#landing-page) for the full example:

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

## Converting Pages [#converting-pages]

[`admonitionsPlugin()`](/markdown/components#containers-and-alerts) renders containers and GitHub alerts as callouts, so they need no conversion:

```ts title="vuesho.config.ts"
import { admonitionsPlugin } from "vuesho/markdown";

createSite(docs.toSource()).plugins(recommendedPreset(), admonitionsPlugin());
```

Code groups and includes have a different syntax:

````md tab="VitePress"
# Installation

::: code-group

```sh [npm]
npm i -D vitest
```

```sh [pnpm]
pnpm add -D vitest
```

:::

## Writing Tests {#writing}

<!--@include: ./parts/first-test.md-->
````

````md tab="Vuesho"
---
title: Installation
---

```npm
npm i -D vitest
```

## Writing Tests [#writing]

<include>./parts/first-test.md</include>
````

### Code Blocks [#code-blocks]

````md tab="VitePress"
```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" };
```

:::
````

````md tab="Vuesho"
```ts title="config.ts" lineNumbers
export default {
  title: "Docs", // [\!code highlight]
  description: "Guides", // [\!code highlight]
};
```

```ts tab="config.ts"
export default { title: "Docs" };
```

```js tab="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](/markdown#code-tabs), as above.

### Includes [#includes]

```md tab="VitePress"
[[toc]]

<<< @/snippets/example.ts
```

```md tab="Vuesho"
<InlineTOC>On this page</InlineTOC>

<include cwd>snippets/example.ts</include>
```

`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 [#page-data]

```md tab="VitePress"
{{ $frontmatter.title }} is {{ $params.pkg }}.

<Badge type="tip" text="beta" />

:tada:
```

```md tab="Vuesho"
{{ page.pageData.title }} is {{ pkg }}.

<Badge text="beta" />

🎉

<script setup lang="ts">
import { usePage } from "vuesho/client";

const page = usePage();
const { pkg } = defineProps<{ pkg: string }>();
</script>
```

- `pkg` is a prop of a page with a [path param](/routing#path-params).
- Add a `Badge.vue` to [`src/components/content/`](/markdown/components#custom-components).
- A shortcode like `:tada:` needs [`@mdit/plugin-emoji`](/markdown#markdown-it-plugins).

## Heading IDs [#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](/config#markdown) that copies VitePress's slug function from `@mdit-vue/shared`:

```ts title="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();
```

```ts title="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 [#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()`.
