Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: frontmatter global and computed global docs #152

Merged
merged 7 commits into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function getGuideSidebar() {
text: 'Advanced',
children: [
{ text: 'Frontmatter', link: '/guide/frontmatter' },
{ text: 'Customization', link: '/guide/customization' }
{ text: 'Customization', link: '/guide/customization' },
{ text: 'Global Computed', link: '/guide/global-computed' }
]
}
]
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ editLink: true
---
```

Between the triple-dashed lines, you can set [predefined variables](#predefined-variables), or even create custom ones of your own. These variables can be used via the <code>\$page.frontmatter</code> variable.
Between the triple-dashed lines, you can set [predefined variables](#predefined-variables), or even create custom ones of your own. These variables can be used via the <code>\$frontmatter</code> variable.
kiaking marked this conversation as resolved.
Show resolved Hide resolved

Here’s an example of how you could use it in your Markdown file:

Expand Down
105 changes: 105 additions & 0 deletions docs/guide/global-computed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Global Computed

In VitePress, some core [computed properties](https://v3.vuejs.org/guide/computed.html#computed-properties) can be used by the default theme or custom themes. Or directly in Markdown pages using vue, for example using `{{ $frontmatter.title }}` to access the title defined in the frontmatter section of the page.

## \$site

This is the `$site` value of the site you’re currently reading:

```json
{
"title": "VitePress",
"description": "Vite & Vue powered static site generator.",
"lang": "en-US",
"locales": {},
"base": "/",
"head": [],
"themeConfig: $theme
}
```

## \$page

This is the `$page` value of the page you’re currently reading:

```json
{
"title": "Global Computed",
"relativePath": "guide/global-computed.md",
"lastUpdated": 1606297645000
"headers": [
{
"level": 2,
"title": "$site",
"slug": "site"
},
{
"level": 2,
"title": "$page",
"slug": "$page"
},
...
],
"frontmatter": $frontmatter,
}
```

## \$frontmatter

Reference of [\$page](#page).frontmatter.

```json
{
"title": "Docs with VitePress",
"editLink": true
}
```

## \$theme
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this $themeConfig to align with VuePress.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you want to change it, I was going to add a comment about this particular rename because I do not think we gain anything by breaking compat with vuepress with it. I agree that we should align the naming in the two projects if possible.


Refers to `$site.themeConfig`.

```json
{
"repo": "vuejs/vitepress",
"docsDir": "docs",
"locales": {},
"editLinks": true,
"editLinkText": "Edit this page on GitHub",
"lastUpdated": "Last Updated",
"nav": [
{
"text": "Guide",
"link": "/"
},
...
],
"sidebar": {
"/": [
{
"text": "Introduction",
"children": [
{
"text": "What is VitePress?",
"link": "/"
},
...
]
}
],
"/guide/": [
{
"text": "Introduction",
"children": [
{
"text": "What is VitePress?",
"link": "/"
},
...
]
}
],
...
},
}
```
5 changes: 5 additions & 0 deletions src/client/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ export function createApp() {
return router.route.data
}
},
$frontmatter: {
get() {
return router.route.data.frontmatter
}
},
$theme: {
get() {
return siteDataByRouteRef.value.themeConfig
Expand Down