Skip to content

Commit 3397dc2

Browse files
committed
Merge branch 'master' into dropdown
2 parents 96c30c5 + 42f63a8 commit 3397dc2

21 files changed

+111
-51
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ VuePress is still a work in progress. There are a few things that it currently d
3434

3535
Contributions are welcome!
3636

37+
## Development
38+
39+
``` bash
40+
npm install
41+
npm run dev # serves VuePress' own docs with itself
42+
```
43+
3744
## License
3845

3946
MIT

bin/vuepress.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ program
1111
.usage('<command> [options]')
1212

1313
program
14-
.command('dev <targetDir>')
14+
.command('dev [targetDir]')
1515
.description('start development server')
1616
.option('-p, --port <port>', 'use specified port (default: 8080)')
17-
.action((dir, { port }) => {
17+
.action((dir = '.', { port }) => {
1818
wrapCommand(dev)(path.resolve(dir), { port })
1919
})
2020

2121
program
22-
.command('build <targetDir>')
22+
.command('build [targetDir]')
2323
.description('build dir as static site')
2424
.option('-d, --dest <outDir>', 'specify build output dir (default: .vuepress/dist)')
2525
.option('--debug', 'build in development mode for debugging')
26-
.action((dir, { debug, outDir }) => {
26+
.action((dir = '.', { debug, outDir }) => {
2727
wrapCommand(build)(path.resolve(dir), { debug, outDir })
2828
})
2929

docs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ footer: MIT Licensed | Copyright © 2018-present Evan You
2020
npm install -g vuepress
2121

2222
# create a markdown file
23-
echo "# Hello VuePress!" > README.md
23+
echo "# Hello VuePress" > README.md
2424

2525
# start writing
26-
vuepress dev .
26+
vuepress dev
2727

2828
# build to static files
29-
vuepress build .
29+
vuepress build
3030
```

docs/guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Each markdown file is compiled into HTML with [markdown-it](https://github.com/m
1616

1717
- [Built-in markdown extensions](./markdown.md) optimized for technical documentation
1818
- [Ability to leverage Vue inside markdown files](./using-vue.md)
19-
- [Vue-powered custom theme system](./custom-themes)
19+
- [Vue-powered custom theme system](./custom-themes.md)
2020
- PWA Support
2121
- Google Analytics Integration
2222
- A default theme with:

docs/guide/assets.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,30 @@
55
All markdown files are compiled into Vue components and processed by webpack, therefore you can and **should prefer** referencing any asset using relative URLs:
66

77
``` md
8-
![An image][./image.png]
8+
![An image](./image.png)
99
```
1010

1111
This would work the same way as in `*.vue` file templates. The image will be processed with `url-loader` and `file-loader`, and copied to appropriate locations in the generated static build.
1212

1313
In addition, you can use the `~` prefix to explicitly indicate this is a webpack module request, allowing you to reference files with webpack aliases or from npm dependencies:
1414

1515
``` md
16-
![Image from alias][~@assets/image.png]
17-
![Image from dependency][~some-dependency/image.png]
16+
![Image from alias](~@alias/image.png)
17+
![Image from dependency](~some-dependency/image.png)
18+
```
19+
20+
webpack aliases can be configured via [configureWebpack](/config/#configurewebpack) in `.vuepress/config.js`. Example:
21+
22+
``` js
23+
module.exports = {
24+
configurewebpack: {
25+
resolve: {
26+
alias: {
27+
'@alias': 'path/to/some/dir'
28+
}
29+
}
30+
}
31+
}
1832
```
1933

2034
## Public Files

docs/guide/getting-started.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ If you just want to play around with VuePress, you can install it globally:
99
npm install -g vuepress
1010

1111
# create a markdown file
12-
echo "# Hello VuePress!" > index.md
12+
echo "# Hello VuePress" > README.md
1313

1414
# start writing
15-
vuepress dev .
15+
vuepress dev
1616

1717
# build
18-
vuepress build .
18+
vuepress build
1919
```
2020

2121
## Inside an Existing Project

docs/guide/markdown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export default {
167167

168168
## Advanced Configuration
169169

170-
VuePress uses [markdown-it]() as the markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vuepress/config.js`:
170+
VuePress uses [markdown-it](https://github.com/markdown-it/markdown-it) as the markdown renderer. A lot of the extensions above are implemented via custom plugins. You can further customize the `markdown-it` instance using the `markdown` option in `.vuepress/config.js`:
171171

172172
``` js
173173
module.exports = {

docs/guide/using-vue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Make sure a custom component's names either contains a hyphen or is in PascalCas
123123

124124
## Script & Style Hoisting
125125

126-
Sometimes you may need to apply some JavaScript or CSS only to the current page. In those case you can directly write root-level `<script>` or `<style>` blocks in the markdown file, and they will be hoisted out of the compiled HTML and used as the `<script>` and `<style>` blocks for the resulting Vue single-file component.
126+
Sometimes you may need to apply some JavaScript or CSS only to the current page. In those cases you can directly write root-level `<script>` or `<style>` blocks in the markdown file, and they will be hoisted out of the compiled HTML and used as the `<script>` and `<style>` blocks for the resulting Vue single-file component.
127127

128128
<p class="demo" :class="$style.example"></p>
129129

lib/build.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
55
const path = require('path')
66
const chalk = require('chalk')
77
const webpack = require('webpack')
8+
const readline = require('readline')
89
const { promisify } = require('util')
10+
const escape = require('escape-html')
911
const rimraf = promisify(require('rimraf'))
1012
const mkdirp = promisify(require('mkdirp'))
1113
const readFile = promisify(fs.readFile)
@@ -17,6 +19,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
1719
const { createBundleRenderer } = require('vue-server-renderer')
1820
const { normalizeHeadTag, applyUserWebpackConfig } = require('./util')
1921

22+
process.stdout.write('Extracting site metadata...')
2023
const options = await prepare(sourceDir)
2124
if (cliOptions.outDir) {
2225
options.outDir = cliOptions.outDir
@@ -28,6 +31,9 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
2831
let clientConfig = createClientConfig(options, cliOptions).toConfig()
2932
let serverConfig = createServerConfig(options, cliOptions).toConfig()
3033

34+
// disable uglify for server
35+
serverConfig.optimization = { minimizer: [] }
36+
3137
// apply user config...
3238
const userConfig = options.siteConfig.configureWebpack
3339
if (userConfig) {
@@ -53,7 +59,6 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
5359
const renderer = createBundleRenderer(serverBundle, {
5460
clientManifest,
5561
runInNewContext: false,
56-
// shouldPrefetch: () => false,
5762
inject: false,
5863
template: fs.readFileSync(path.resolve(__dirname, 'app/index.ssr.html'), 'utf-8')
5964
})
@@ -64,14 +69,21 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
6469
.join('\n ')
6570

6671
// render pages
67-
await Promise.all(options.siteData.pages.map(renderPage))
72+
console.log('Rendering static HTML...')
73+
for (const page of options.siteData.pages) {
74+
await renderPage(page)
75+
}
6876

6977
// if the user does not have a custom 404.md, generate the theme's default
7078
if (!options.siteData.pages.some(p => p.path === '/404.html')) {
7179
await renderPage({ path: '/404.html' })
7280
}
7381

82+
readline.clearLine(process.stdout, 0)
83+
readline.cursorTo(process.stdout, 0)
84+
7485
if (options.siteConfig.serviceWorker) {
86+
console.log('Generating service worker...')
7587
const wbb = require('workbox-build')
7688
wbb.generateSW({
7789
swDest: path.resolve(outDir, 'service-worker.js'),
@@ -112,16 +124,19 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
112124
function renderAttrs (attrs = {}) {
113125
const keys = Object.keys(attrs)
114126
if (keys.length) {
115-
return ' ' + keys.map(name => `${name}="${attrs[name]}"`).join(' ')
127+
return ' ' + keys.map(name => `${name}="${escape(attrs[name])}"`).join(' ')
116128
} else {
117129
return ''
118130
}
119131
}
120132

121133
async function renderPage (page) {
122134
const pagePath = page.path
123-
const pageMeta = renderPageMeta(page.frontmatter && page.frontmatter.meta)
135+
readline.clearLine(process.stdout, 0)
136+
readline.cursorTo(process.stdout, 0)
137+
process.stdout.write(`Rendering page: ${pagePath}`)
124138

139+
const pageMeta = renderPageMeta(page.frontmatter && page.frontmatter.meta)
125140
const context = {
126141
url: pagePath,
127142
userHeadTags,
@@ -135,8 +150,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
135150
html = await renderer.renderToString(context)
136151
} catch (e) {
137152
console.error(chalk.red(`Error rendering ${pagePath}:`))
138-
console.error(e.stack)
139-
return
153+
throw e
140154
}
141155
const filename = pagePath.replace(/\/$/, '/index.html').replace(/^\//, '')
142156
const filePath = path.resolve(outDir, filename)
@@ -149,7 +163,7 @@ module.exports = async function build (sourceDir, cliOptions = {}) {
149163
return meta.map(m => {
150164
let res = `<meta`
151165
Object.keys(m).forEach(key => {
152-
res += ` ${key}="${m[key]}"`
166+
res += ` ${key}="${escape(m[key])}"`
153167
})
154168
return res + `>`
155169
}).join('')

lib/default-theme/NavLinks.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
class="github-link"
3535
target="_blank"
3636
rel="noopener">
37-
Github
37+
GitHub
3838
<OutboundLink/>
3939
</a>
4040
</nav>

lib/default-theme/SidebarLink.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ export default {
1414
? selfActive || item.children.some(c => isActive($route, item.basePath + '#' + c.slug))
1515
: selfActive
1616
const link = renderLink(h, item.path, item.title || item.path, active)
17-
const configDepth = $page.frontmatter.sidebarDepth || $site.themeConfig.sidebarDepth
17+
const configDepth = $page.frontmatter.sidebarDepth != null
18+
? $page.frontmatter.sidebarDepth
19+
: $site.themeConfig.sidebarDepth
1820
const maxDepth = configDepth == null ? 1 : configDepth
1921
if (item.type === 'auto') {
2022
return [link, renderChildren(h, item.children, item.basePath, $route, maxDepth)]
@@ -47,7 +49,7 @@ function renderChildren (h, children, path, route, maxDepth, depth = 1) {
4749
const active = isActive(route, path + '#' + c.slug)
4850
return h('li', { class: 'sidebar-sub-header' }, [
4951
renderLink(h, '#' + c.slug, c.title, active),
50-
...renderChildren(h, c.children, path, route, maxDepth, depth + 1)
52+
renderChildren(h, c.children, path, route, maxDepth, depth + 1)
5153
])
5254
}))
5355
}

lib/default-theme/styles/code.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
.highlighted-line
3535
background-color rgba(0, 0, 0, 66%)
3636
display block
37-
margin 0.1rem -1.8rem 0
37+
margin 0.1rem -1.5rem 0
3838
padding 0.1rem 1.8rem
3939

4040
pre[class="language-js"], pre[class="language-javascript"]

lib/default-theme/styles/mobile.styl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ $mobileSidebarWidth = $sidebarWidth * 0.82
2929
@media (max-width: $MQMobileNarrow)
3030
h1
3131
font-size 1.9rem
32-
pre, pre[class*="language-"]
33-
margin 0.85rem -1.5rem
34-
border-radius 0
3532
.content:not(.custom)
3633
padding 1.5rem
34+
.content
35+
pre, pre[class*="language-"]
36+
margin 0.85rem -1.5rem
37+
border-radius 0

lib/default-theme/styles/theme.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ table
132132

133133
tr
134134
border-top 1px solid #dfe2e5
135-
&:nth-child(2)
135+
&:nth-child(2n)
136136
background-color #f6f8fa
137137

138138
th, td

lib/dev.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = async function dev (sourceDir, cliOptions = {}) {
1717
const { applyUserWebpackConfig } = require('./util')
1818
const { frontmatterEmitter } = require('./webpack/markdownLoader')
1919

20+
process.stdout.write('Extracting site metadata...')
2021
const options = await prepare(sourceDir)
2122

2223
// setup watchers to update options and dynamically generated files

lib/markdown/highlight.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
const chalk = require('chalk')
22
const prism = require('prismjs')
33
const loadLanguages = require('prismjs/components/index')
4+
const escapeHtml = require('escape-html')
45

56
// required to make embedded highlighting work...
67
loadLanguages(['markup', 'css', 'javascript'])
78

89
function wrap (code, lang) {
10+
if (lang === 'text') {
11+
code = escapeHtml(code)
12+
}
913
return `<pre v-pre class="language-${lang}"><code>${code}</code></pre>`
1014
}
1115

0 commit comments

Comments
 (0)