style: adjust few code orders and such

pull/152/head
Kia King Ishii 5 years ago
parent 8deccbea80
commit bee061782d

@ -44,8 +44,8 @@ function getGuideSidebar() {
text: 'Advanced', text: 'Advanced',
children: [ children: [
{ text: 'Frontmatter', link: '/guide/frontmatter' }, { text: 'Frontmatter', link: '/guide/frontmatter' },
{ text: 'Customization', link: '/guide/customization' }, { text: 'Global Computed', link: '/guide/global-computed' },
{ text: 'Global Computed', link: '/guide/global-computed' } { text: 'Customization', link: '/guide/customization' }
] ]
} }
] ]

@ -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>\$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.
Heres an example of how you could use it in your Markdown file: Heres an example of how you could use it in your Markdown file:

@ -1,57 +1,66 @@
# Global Computed # 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. 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 ## $site
This is the `$site` value of the site youre currently reading: This is the `$site` value of the site you're currently reading:
```json ```js
{ {
"title": "VitePress", base: '/',
"description": "Vite & Vue powered static site generator.", lang: 'en-US',
"lang": "en-US", title: 'VitePress',
"locales": {}, description: 'Vite & Vue powered static site generator.',
"base": "/", head: [],
"head": [], locales: {},
"themeConfig: $themeConfig themeConfig: $themeConfig
}
```
## $themeConfig
Refers to `$site.themeConfig`.
```js
{
locales: {},
repo: 'vuejs/vitepress',
docsDir: 'docs',
editLinks: true,
editLinkText: 'Edit this page on GitHub',
lastUpdated: 'Last Updated',
nav: [...],
sidebar: { ... }
} }
``` ```
## $page ## $page
This is the `$page` value of the page youre currently reading: This is the `$page` value of the page you're currently reading:
```json ```js
{ {
"title": "Global Computed", relativePath: 'guide/global-computed.md',
"relativePath": "guide/global-computed.md", title: 'Global Computed',
"lastUpdated": 1606297645000 headers: [
"headers": [ { level: 2, title: '$site', slug: 'site' },
{ { level: 2, title: '$page', slug: '$page' },
"level": 2,
"title": "$site",
"slug": "site"
},
{
"level": 2,
"title": "$page",
"slug": "$page"
},
... ...
], ],
"frontmatter": $frontmatter, frontmatter: $frontmatter,
lastUpdated: 1606297645000
} }
``` ```
## $frontmatter ## $frontmatter
Reference of [$page](#page).frontmatter. Reference of `$page.frontmatter`.
```json ```js
{ {
"title": "Docs with VitePress", title: 'Docs with VitePress',
"editLink": true editLink: true
} }
``` ```
@ -62,52 +71,3 @@ Value of the `<title>` label used for the current page.
## $description ## $description
The content value of the `<meta name= "description" content= "...">` for the current page. The content value of the `<meta name= "description" content= "...">` for the current page.
## $themeConfig
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": "/"
},
...
]
}
],
...
},
}
```

@ -82,6 +82,11 @@ export function createApp() {
return siteDataByRouteRef.value return siteDataByRouteRef.value
} }
}, },
$themeConfig: {
get() {
return siteDataByRouteRef.value.themeConfig
}
},
$page: { $page: {
get() { get() {
return router.route.data return router.route.data
@ -103,11 +108,6 @@ export function createApp() {
router.route.data.description || siteDataByRouteRef.value.description router.route.data.description || siteDataByRouteRef.value.description
) )
} }
},
$themeConfig: {
get() {
return siteDataByRouteRef.value.themeConfig
}
} }
}) })

@ -14,15 +14,8 @@
</a> </a>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent } from 'vue'
import { withBase } from '../utils' import { withBase } from '../utils'
export default defineComponent({
setup() {
return { withBase }
}
})
</script> </script>
<style scoped> <style scoped>
@ -37,7 +30,7 @@ export default defineComponent({
} }
.logo { .logo {
margin-right: 0.75rem; margin-right: .75rem;
height: 1.3rem; height: 1.3rem;
vertical-align: bottom; vertical-align: bottom;
} }

@ -109,6 +109,10 @@ const inferTitle = (frontmatter: any, content: string) => {
} }
const inferDescription = (frontmatter: Record<string, any>) => { const inferDescription = (frontmatter: Record<string, any>) => {
if (!frontmatter.head) {
return ''
}
return getHeadMetaContent(frontmatter.head, 'description') || '' return getHeadMetaContent(frontmatter.head, 'description') || ''
} }
@ -119,8 +123,10 @@ const getHeadMetaContent = (
if (!head || !head.length) { if (!head || !head.length) {
return undefined return undefined
} }
const meta = head.find(([tag, attrs = {}]) => { const meta = head.find(([tag, attrs = {}]) => {
return tag === 'meta' && attrs.name === name && attrs.content return tag === 'meta' && attrs.name === name && attrs.content
}) })
return meta && meta[1].content return meta && meta[1].content
} }

4
types/shared.d.ts vendored

@ -24,11 +24,11 @@ export type HeadConfig =
| [string, Record<string, string>, string] | [string, Record<string, string>, string]
export interface PageData { export interface PageData {
relativePath: string
title: string title: string
description: string description: string
frontmatter: Record<string, any>
headers: Header[] headers: Header[]
relativePath: string frontmatter: Record<string, any>
lastUpdated: number lastUpdated: number
} }

Loading…
Cancel
Save