diff --git a/docs/vuepress.config.js b/docs/vuepress.config.js new file mode 100644 index 0000000000..309faee8fd --- /dev/null +++ b/docs/vuepress.config.js @@ -0,0 +1,5 @@ +module.exports = { + data: { + title: 'VuePress' + } +} diff --git a/lib/app/Content.js b/lib/app/Content.js index 001cb6c4a7..eaf33e7cbf 100644 --- a/lib/app/Content.js +++ b/lib/app/Content.js @@ -1,14 +1,14 @@ export default { created () { if (this.$ssrContext) { - this.$ssrContext.title = getMetadata(this, 'title') || 'VuePress' - this.$ssrContext.lang = getMetadata(this, 'lang') || 'en' + this.$ssrContext.title = getTitle(this) + this.$ssrContext.lang = getLang(this) } }, mounted () { const updateMeta = () => { - document.title = getMetadata(this, 'title') || 'VuePress' - document.documentElement.lang = getMetadata(this, 'lang') || 'en' + document.title = getTitle(this) + document.documentElement.lang = getLang(this) } this.$watch('$page', updateMeta) updateMeta() @@ -24,6 +24,21 @@ export default { } } -function getMetadata (vm, key) { - return vm.$page.frontmatter[key] || vm.$page[key] || vm.$site[key] +function getTitle (vm) { + const selfTitle = ( + vm.$page.frontmatter.title || // explicit title + vm.$page.title // inferred title + ) + const siteTitle = vm.$site.title + return siteTitle + ? selfTitle + ? siteTitle + ' | ' + selfTitle + : siteTitle + : selfTitle + ? selfTitle + : 'VuePress' +} + +function getLang (vm) { + return vm.$page.frontmatter.lang } diff --git a/lib/default-theme/Layout.vue b/lib/default-theme/Layout.vue index ecf4585292..50d273d14e 100644 --- a/lib/default-theme/Layout.vue +++ b/lib/default-theme/Layout.vue @@ -34,3 +34,19 @@ export default { + diff --git a/lib/markdown/highlight.js b/lib/markdown/highlight.js new file mode 100644 index 0000000000..e9c35dbe40 --- /dev/null +++ b/lib/markdown/highlight.js @@ -0,0 +1,21 @@ +const prism = require('prismjs') +const loadLanguages = require('prismjs/components/index') + +module.exports = (str, lang) => { + if (lang === 'vue') { + lang = 'html' + } + if (!prism.languages[lang]) { + try { + loadLanguages([lang]) + } catch (e) { + throw new Error(`[vuepress] Syntax highlight for language "${lang}" is not supported.`) + return '' + } + } + if (prism.languages[lang]) { + let res = prism.highlight(str, prism.languages[lang], lang) + return `
${res}
`
+ }
+ return ''
+}
diff --git a/lib/markdown/index.js b/lib/markdown/index.js
new file mode 100644
index 0000000000..be0045c563
--- /dev/null
+++ b/lib/markdown/index.js
@@ -0,0 +1,16 @@
+const highlight = require('./highlight')
+const convertRouterLink = require('./link')
+const container = require('markdown-it-container')
+
+// TODO extract