提交 404a0a1c 编写于 作者: E Evan You

wip mobile

上级 b4ca0e4c
...@@ -15,6 +15,7 @@ module.exports = { ...@@ -15,6 +15,7 @@ module.exports = {
'/assets', '/assets',
'/using-vue', '/using-vue',
'/config', '/config',
'/default-theme',
'/theming', '/theming',
'/deploy' '/deploy'
] ]
......
...@@ -8,15 +8,15 @@ navTitle: Getting Started ...@@ -8,15 +8,15 @@ navTitle: Getting Started
## Why ## Why
- Writing first: minimal setup, all you need is a markdown file. - **Writing First**: minimal setup, all you need is a markdown file.
- Vue-powered: the layout system is a Vue app. It's also pre-rendered into static HTML. And you can register and use Vue components inside markdown content. - **Vue-powered**: Use custom Vue components inside markdown, and develop custom themes using Vue single file components.
- Flexible: develop with full power of webpack (hot-reload, pre-processors support), generate SEO-friendly static HTML, and works as an SPA after initial page load. - **Great Dev Experience**: enjoy the same enjoyable development experience of a Vue app. Leverage the full power of webpack (hot-reload, pre-processors), generate SEO-friendly static HTML, and works as an SPA after initial page load.
- Optimized for docs: many built-in markdown extensions and default theme features for writing great documentation. - **Optimized for Docs**: many [built-in markdown extensions](./markdown.md) and default theme features for writing great documentation.
- GitHub friendly: pages can link to each other using relative links that ends in `.md`, auto-generates GitHub link and page edit links if a repo is provided. - **GitHub Friendly**: source markdown files can link to each other using relative links that ends in `.md` so they are also readable on GitHub, auto-generates page edit links if a repo is provided.
## Quickstart ## Quickstart
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
### themeConfig ### themeConfig
Also see [config options for the default theme](./default-theme.md).
## Markdown ## Markdown
### markdown.anchor ### markdown.anchor
......
# Default Theme Configuration
# Theming # Custom Themes
VuePress uses Vue single file components for custom themes. To use a custom layout, create a `.vuepress/theme` directory in your docs root, and then create a `Layout.vue` file: VuePress uses Vue single file components for custom themes. To use a custom layout, create a `.vuepress/theme` directory in your docs root, and then create a `Layout.vue` file:
......
...@@ -42,18 +42,32 @@ The compiled component does not have any private data but do have access to the ...@@ -42,18 +42,32 @@ The compiled component does not have any private data but do have access to the
**Output** **Output**
<pre><code>{{ $page }}</code></pre> ``` json
{
"path": "/using-vue.html",
"title": "Using Vue in Markdown",
"frontmatter": {}
}
```
## Escaping ## Escaping
By default, fenced code blocks are automatically wrapped with `v-pre`. If you want to display raw mustaches or Vue-specific syntax inside inline code snippets or plain text, you need to wrap a paragraph with the `v-pre` custom container: By default, fenced code blocks are automatically wrapped with `v-pre`. If you want to display raw mustaches or Vue-specific syntax inside inline code snippets or plain text, you need to wrap a paragraph with the `v-pre` custom container:
**Input**
``` markdown ``` markdown
::: v-pre ::: v-pre
`{{ This will be displayed as-is }}` `{{ This will be displayed as-is }}`
::: :::
``` ```
**Output**
::: v-pre
`{{ This will be displayed as-is }}`
:::
## Using Components ## Using Components
Any `*.vue` file found in `.vuepress/components` are automatically registered as global async components. For example: Any `*.vue` file found in `.vuepress/components` are automatically registered as global async components. For example:
...@@ -77,7 +91,7 @@ Inside any markdown file you can then directly use the components (names are inf ...@@ -77,7 +91,7 @@ Inside any markdown file you can then directly use the components (names are inf
<OtherComponent/> <OtherComponent/>
::: warning ::: warning IMPORTANT
Make sure a custom component's names either contains a hyphen or is in PascalCase. Otherwise it will be treated as an inline element and wrapped inside a `<p>` tag, which will lead to hydration mismatch because `<p>` does not allow block elements to be placed inside it. Make sure a custom component's names either contains a hyphen or is in PascalCase. Otherwise it will be treated as an inline element and wrapped inside a `<p>` tag, which will lead to hydration mismatch because `<p>` does not allow block elements to be placed inside it.
::: :::
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title></title> <title></title>
</head> </head>
<body> <body>
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html lang="{{ lang }}"> <html lang="{{ lang }}">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>{{ title }}</title> <title>{{ title }}</title>
{{{ userHeadTags }}} {{{ userHeadTags }}}
{{{ pageMeta }}} {{{ pageMeta }}}
......
<template> <template>
<div class="theme-container"> <div class="theme-container">
<ul class="sidebar"> <div class="sidebar">
<li v-for="page in sortedPages"> <ul>
<router-link :to="page.path"> <li v-for="page in sortedPages">
{{ page.frontmatter.navTitle || page.title || page.path }} <router-link :to="page.path">
</router-link> {{ page.frontmatter.navTitle || page.title || page.path }}
</li> </router-link>
</ul> </li>
</ul>
</div>
<Index v-if="$page.path === '/index'" /> <Index v-if="$page.path === '/index'" />
<Page v-else /> <Page v-else />
</div> </div>
......
.theme-container body
font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif font-family -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif
-webkit-font-smoothing antialiased -webkit-font-smoothing antialiased
-moz-osx-font-smoothing grayscale -moz-osx-font-smoothing grayscale
padding 0 30px
font-size 16px font-size 16px
color #2c3e50 color #2c3e50
.markdown .page
max-width 800px padding-left 300px
margin-left 300px
margin-bottom 30px
.sidebar .sidebar
width 300px
position fixed position fixed
margin 0 margin 0
top 30px top 0
left 0
bottom 0
padding 2em 0
box-sizing border-box
border-right 1px solid #eaecef
overflow-y scroll
ul
padding 0
margin 0
list-style-type none
a
display inline-block
color #2c3e50
border-left 4px solid transparent
padding 0.25em
padding-left 1.25em
&:hover
color darken(#41b883, 5%)
&.router-link-exact-active
font-weight 600
color darken(#41b883, 5%)
border-left-color darken(#41b883, 5%)
.markdown
max-width 720px
margin 2em auto
padding 0 2em
blockquote blockquote
font-size 1.25em font-size 1.25em
...@@ -64,7 +89,7 @@ code ...@@ -64,7 +89,7 @@ code
font-family source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace font-family source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace
p, ul, ol p, ul, ol
line-height 1.5 line-height 1.7
p, h1, h2, h3, h4, h5, h6 p, h1, h2, h3, h4, h5, h6
code code
...@@ -81,19 +106,19 @@ pre, pre[class*="language-"] ...@@ -81,19 +106,19 @@ pre, pre[class*="language-"]
background-color #2d2d2d background-color #2d2d2d
color white color white
line-height 1.4 line-height 1.4
border-radius 5px border-radius 6px
padding 1.3rem 1.575rem padding 1.4em 1.6em
white-space pre-wrap white-space pre-wrap
word-break break-word word-break break-word
overflow auto overflow auto
code code
font-size .88em font-size 0.85em
.highlighted-line .highlighted-line
background-color #14161a background-color #14161a
display block display block
margin 0 -1.575rem margin 0 -1.6em
padding 0.2rem 1.575rem 0 padding 0.2em 1.6em 0
.custom-block .custom-block
.custom-block-title .custom-block-title
...@@ -105,7 +130,7 @@ pre, pre[class*="language-"] ...@@ -105,7 +130,7 @@ pre, pre[class*="language-"]
border-left-style solid border-left-style solid
margin 1em 0 margin 1em 0
&.tip &.tip
background-color #f1f3f5 background-color #f3f5f7
border-color #42b983 border-color #42b983
&.warning &.warning
background-color rgba(255,229,100,.3) background-color rgba(255,229,100,.3)
...@@ -125,3 +150,27 @@ p ...@@ -125,3 +150,27 @@ p
padding 1rem padding 1rem
border 1px solid #ddd border 1px solid #ddd
border-radius 4px border-radius 4px
@media (max-width: 879px)
body
font-size 15px
.sidebar
font-size 14px
width 250px
.page
padding-left 250px
.markdown
margin 1.5em 0
padding 0 1.5em
@media (max-width: 639px)
body
font-size 15px
.sidebar
width 275px
display none
.page
padding-left 0
.markdown
margin 1em 0
padding 0 1em
...@@ -4,6 +4,7 @@ const globby = require('globby') ...@@ -4,6 +4,7 @@ const globby = require('globby')
const mkdirp = require('mkdirp') const mkdirp = require('mkdirp')
const yaml = require('yaml-front-matter') const yaml = require('yaml-front-matter')
const tempPath = path.resolve(__dirname, 'app/.temp') const tempPath = path.resolve(__dirname, 'app/.temp')
const { inferTitle } = require('./util')
mkdirp(tempPath) mkdirp(tempPath)
...@@ -114,9 +115,9 @@ async function resolveOptions (sourceDir) { ...@@ -114,9 +115,9 @@ async function resolveOptions (sourceDir) {
// extract yaml frontmatter // extract yaml frontmatter
const frontmatter = yaml.loadFront(content) const frontmatter = yaml.loadFront(content)
// infer title // infer title
const titleMatch = frontmatter.__content.trim().match(/^#+\s+(.*)/) const title = inferTitle(frontmatter)
if (titleMatch) { if (title) {
data.title = titleMatch[1] data.title = title
} }
delete frontmatter.__content delete frontmatter.__content
if (Object.keys(frontmatter).length) { if (Object.keys(frontmatter).length) {
......
...@@ -24,3 +24,13 @@ exports.applyUserWebpackConfig = function (userConfig, config, isServer) { ...@@ -24,3 +24,13 @@ exports.applyUserWebpackConfig = function (userConfig, config, isServer) {
} }
return config return config
} }
exports.inferTitle = function (frontmatter) {
if (frontmatter.title) {
return frontmatter.title
}
const match = frontmatter.__content.trim().match(/^#+\s+(.*)/)
if (match) {
return match[1]
}
}
const { EventEmitter } = require('events') const { EventEmitter } = require('events')
const { getOptions } = require('loader-utils') const { getOptions } = require('loader-utils')
const frontmatter = require('yaml-front-matter') const yaml = require('yaml-front-matter')
const { inferTitle } = require('../util')
const frontmatterCache = new Map() const cache = new Map()
module.exports = function (src) { module.exports = function (src) {
const { markdown } = getOptions(this) const { markdown } = getOptions(this)
const parsed = frontmatter.loadFront(src)
const content = parsed.__content
delete parsed.__content
// diff frontmatter, since it's not going to be part of the returned const frontmatter = yaml.loadFront(src)
// component, changes in frontmatter do not trigger hot updates const inferredTitle = inferTitle(frontmatter)
const serializedData = JSON.stringify(parsed) const content = frontmatter.__content
const cachedData = frontmatterCache.get(this.resourcePath) delete frontmatter.__content
if (cachedData != null && cachedData !== serializedData) {
// diff frontmatter and title, since they are not going to be part of the
// returned component, changes in frontmatter do not trigger proper updates
const cachedData = cache.get(this.resourcePath)
if (cachedData && (
cachedData.inferredTitle !== inferredTitle ||
JSON.stringify(cachedData.frontmatter) !== JSON.stringify(frontmatter)
)) {
// frontmatter changed... need to do a full reload // frontmatter changed... need to do a full reload
module.exports.frontmatterEmitter.emit('update') module.exports.frontmatterEmitter.emit('update')
} }
frontmatterCache.set(this.resourcePath, serializedData)
cache.set(this.resourcePath, {
frontmatter,
inferredTitle
})
const { html, hoistedTags } = markdown.renderWithHoisting(content) const { html, hoistedTags } = markdown.renderWithHoisting(content)
return ( return (
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册