Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
f4cf3b40
V
Vuepress
项目概览
计算机应用开发
/
前端
/
Vuepress
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vuepress
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f4cf3b40
编写于
4月 10, 2018
作者:
E
Evan You
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: avoid loading bar if page has been loaded
上级
33624f31
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
58 addition
and
42 deletion
+58
-42
lib/app/Content.js
lib/app/Content.js
+17
-34
lib/app/metadataMixin.js
lib/app/metadataMixin.js
+2
-7
lib/app/util.js
lib/app/util.js
+36
-0
lib/default-theme/Layout.vue
lib/default-theme/Layout.vue
+3
-1
未找到文件。
lib/app/Content.js
浏览文件 @
f4cf3b40
import
{
pathToComponentName
,
getTitle
,
getLang
}
from
'
./util
'
export
default
{
created
()
{
if
(
this
.
$ssrContext
)
{
this
.
$ssrContext
.
title
=
getTitle
(
this
)
this
.
$ssrContext
.
lang
=
getLang
(
this
)
this
.
$ssrContext
.
title
=
getTitle
(
this
.
$page
)
this
.
$ssrContext
.
lang
=
getLang
(
this
.
$page
)
}
},
mounted
()
{
let
currentMetaTags
beforeMount
()
{
this
.
currentMetaTags
=
[]
const
updateMeta
=
()
=>
{
document
.
title
=
getTitle
(
this
)
document
.
documentElement
.
lang
=
getLang
(
this
)
currentMetaTags
=
updateMetaTags
(
this
,
currentMetaTags
)
document
.
title
=
getTitle
(
this
.
$page
)
document
.
documentElement
.
lang
=
getLang
(
this
.
$page
)
this
.
currentMetaTags
=
updateMetaTags
(
this
.
$page
,
this
.
currentMetaTags
)
}
this
.
$watch
(
'
$page
'
,
updateMeta
)
updateMeta
()
},
beforeDestroy
()
{
updateMetaTags
(
null
,
this
.
currentMetaTags
)
},
render
(
h
)
{
return
h
(
pathToComponentName
(
this
.
$page
.
path
))
}
}
function
pathToComponentName
(
path
)
{
if
(
path
.
charAt
(
path
.
length
-
1
)
===
'
/
'
)
{
return
`page
${
path
.
replace
(
/
\/
/g
,
'
-
'
)
+
'
index
'
}
`
}
else
{
return
`page
${
path
.
replace
(
/
\/
/g
,
'
-
'
).
replace
(
/
\.
html$/
,
''
)}
`
}
}
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
||
'
VuePress
'
}
function
getLang
(
vm
)
{
return
vm
.
$page
.
frontmatter
.
lang
||
'
en
'
}
function
updateMetaTags
(
vm
,
current
)
{
function
updateMetaTags
(
page
,
current
)
{
if
(
current
)
{
current
.
forEach
(
c
=>
{
document
.
head
.
removeChild
(
c
)
})
}
const
data
=
vm
.
$
page
.
frontmatter
.
meta
const
data
=
page
&&
page
.
frontmatter
.
meta
if
(
data
)
{
return
data
.
map
(
m
=>
{
const
tag
=
document
.
createElement
(
'
meta
'
)
...
...
lib/app/metadataMixin.js
浏览文件 @
f4cf3b40
import
{
siteData
}
from
'
./.temp/siteData
'
import
{
findPageForPath
}
from
'
./util
'
siteData
.
pages
.
forEach
(
page
=>
{
if
(
!
page
.
frontmatter
)
{
...
...
@@ -12,13 +13,7 @@ export default {
return
siteData
},
$page
()
{
const
pages
=
siteData
.
pages
for
(
let
i
=
0
;
i
<
pages
.
length
;
i
++
)
{
const
page
=
pages
[
i
]
if
(
page
.
path
===
this
.
$route
.
path
)
{
return
page
}
}
return
findPageForPath
(
this
.
$route
.
path
)
}
}
}
lib/app/util.js
0 → 100644
浏览文件 @
f4cf3b40
import
{
siteData
}
from
'
./.temp/siteData
'
export
function
pathToComponentName
(
path
)
{
if
(
path
.
charAt
(
path
.
length
-
1
)
===
'
/
'
)
{
return
`page
${
path
.
replace
(
/
\/
/g
,
'
-
'
)
+
'
index
'
}
`
}
else
{
return
`page
${
path
.
replace
(
/
\/
/g
,
'
-
'
).
replace
(
/
\.
html$/
,
''
)}
`
}
}
export
function
findPageForPath
(
path
)
{
const
pages
=
siteData
.
pages
for
(
let
i
=
0
;
i
<
pages
.
length
;
i
++
)
{
const
page
=
pages
[
i
]
if
(
page
.
path
===
path
)
{
return
page
}
}
}
export
function
getTitle
(
page
)
{
const
selfTitle
=
(
page
.
frontmatter
.
title
||
// explicit title
page
.
title
// inferred title
)
const
siteTitle
=
siteData
.
title
return
siteTitle
?
selfTitle
?
(
siteTitle
+
'
|
'
+
selfTitle
)
:
siteTitle
:
selfTitle
||
'
VuePress
'
}
export
function
getLang
(
page
)
{
return
page
.
frontmatter
.
lang
||
'
en
'
}
lib/default-theme/Layout.vue
浏览文件 @
f4cf3b40
...
...
@@ -7,10 +7,12 @@
</
template
>
<
script
>
import
Vue
from
'
vue
'
import
nprogress
from
'
nprogress
'
import
Navbar
from
'
./Navbar.vue
'
import
Page
from
'
./Page.vue
'
import
Sidebar
from
'
./Sidebar.vue
'
import
{
pathToComponentName
}
from
'
../app/util
'
export
default
{
components
:
{
Page
,
Sidebar
,
Navbar
},
...
...
@@ -18,7 +20,7 @@ export default {
nprogress
.
configure
({
showSpinner
:
false
})
this
.
$router
.
beforeEach
((
to
,
from
,
next
)
=>
{
if
(
to
.
path
!==
from
.
path
)
{
if
(
to
.
path
!==
from
.
path
&&
!
Vue
.
component
(
pathToComponentName
(
to
.
path
))
)
{
nprogress
.
start
()
}
next
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录