Skip to content

Commit

Permalink
add example for vitepress ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Sep 29, 2023
1 parent d3432c4 commit 5415f55
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 6 deletions.
36 changes: 36 additions & 0 deletions examples/ssr/vitepress/.vitepress/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { defineConfig } from 'vitepress'
import vueI18n from '@intlify/unplugin-vue-i18n/vite'

// https://vitepress.dev/reference/site-config
export default defineConfig({
vite: {
plugins: [
vueI18n({
ssr: true
})
]
},
title: 'My Awesome Project',
description: 'A VitePress Site',
themeConfig: {
// https://vitepress.dev/reference/default-theme-config
nav: [
{ text: 'Home', link: '/' },
{ text: 'Examples', link: '/markdown-examples' }
],

sidebar: [
{
text: 'Examples',
items: [
{ text: 'Markdown Examples', link: '/markdown-examples' },
{ text: 'Runtime API Examples', link: '/api-examples' }
]
}
],

socialLinks: [
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' }
]
}
})
19 changes: 19 additions & 0 deletions examples/ssr/vitepress/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import DefaultTheme from 'vitepress/theme'
import { createI18n } from 'vue-i18n'

export default {
extends: DefaultTheme,
enhanceApp({ app, router, siteData }) {
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: {
en: {
hello: 'hello world!'
}
}
})
app.use(i18n)
// ...
}
}
15 changes: 15 additions & 0 deletions examples/ssr/vitepress/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 1569

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.0.3. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
55 changes: 55 additions & 0 deletions examples/ssr/vitepress/api-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
outline: deep
---

# Runtime API Examples

This page demonstrates usage of some of the runtime APIs provided by VitePress.

The main `useData()` API can be used to access site, theme, and page data for the current page. It works in both `.md` and `.vue` files:

```md
<script setup>
import { useData } from 'vitepress'

const { theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data

<pre>{{ theme }}</pre>

### Page Data

<pre>{{ page }}</pre>

### Page Frontmatter

<pre>{{ frontmatter }}</pre>
```

<script setup>
import { useData } from 'vitepress'

const { site, theme, page, frontmatter } = useData()
</script>

## Results

### Theme Data

<pre>{{ theme }}</pre>

### Page Data

<pre>{{ page }}</pre>

### Page Frontmatter

<pre>{{ frontmatter }}</pre>

## More

Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).
24 changes: 24 additions & 0 deletions examples/ssr/vitepress/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# https://vitepress.dev/reference/default-theme-home-page
layout: home

hero:
name: 'My Awesome Project'
text: 'A VitePress Site'
tagline: My great project tagline
actions:
- theme: brand
text: Markdown Examples
link: /markdown-examples
- theme: alt
text: API Examples
link: /api-examples

features:
- title: Feature A
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature B
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
- title: Feature C
details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
---
85 changes: 85 additions & 0 deletions examples/ssr/vitepress/markdown-examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Markdown Extension Examples

This page demonstrates some of the built-in markdown extensions provided by VitePress.

## Syntax Highlighting

VitePress provides Syntax Highlighting powered by [Shiki](https://github.com/shikijs/shiki), with additional features like line-highlighting:

**Input**

````
```js{4}
export default {
data () {
return {
msg: 'Highlighted!'
}
}
}
```
````

**Output**

```js{4}
export default {
data () {
return {
msg: 'Highlighted!'
}
}
}
```

## Custom Containers

**Input**

```md
::: info
This is an info box.
:::

::: tip
This is a tip.
:::

::: warning
This is a warning.
:::

::: danger
This is a dangerous warning.
:::

::: details
This is a details block.
:::
```

**Output**

::: info
This is an info box.
:::

::: tip
This is a tip.
:::

::: warning
This is a warning.
:::

::: danger
This is a dangerous warning.
:::

::: details
This is a details block.
:::

## More

Check out the documentation for the [full list of markdown extensions](https://vitepress.dev/guide/markdown).
18 changes: 18 additions & 0 deletions examples/ssr/vitepress/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "vitepress-ssr",
"module": "index.ts",
"type": "module",
"dependencies": {
"vitepress": "^1.0.0-rc.20",
"vue-i18n": "^9.5.0"
},
"devDependencies": {
"@intlify/unplugin-vue-i18n": "^1.4.0",
"typescript": "^5.0.0"
},
"scripts": {
"docs:dev": "vitepress dev",
"docs:build": "vitepress build",
"docs:preview": "vitepress preview"
}
}
19 changes: 19 additions & 0 deletions examples/ssr/vitepress/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"lib": ["ESNext"],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"moduleDetection": "force",
"allowImportingTsExtensions": true,
"noEmit": true,
"composite": true,
"strict": true,
"downlevelIteration": true,
"skipLibCheck": true,
"jsx": "react-jsx",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
}
}
20 changes: 14 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ packages:
- 'packages/*'
- 'examples/**/*'
- '!examples/ssr/vite'
- '!examples/ssr/vitepress'
- '!examples/frameworks/nuxt3'

0 comments on commit 5415f55

Please sign in to comment.