Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
计算机应用开发
前端
Vuepress
提交
b50ff521
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,发现更多精彩内容 >>
提交
b50ff521
编写于
4月 09, 2018
作者:
E
Evan You
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix nested README
上级
aef30e54
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
128 addition
and
75 deletion
+128
-75
docs/.vuepress/config.js
docs/.vuepress/config.js
+7
-6
docs/test/README.md
docs/test/README.md
+3
-0
lib/app/Content.js
lib/app/Content.js
+9
-7
lib/default-theme/SideBar.vue
lib/default-theme/SideBar.vue
+10
-45
lib/default-theme/SidebarGroup.vue
lib/default-theme/SidebarGroup.vue
+4
-3
lib/default-theme/SidebarLink.vue
lib/default-theme/SidebarLink.vue
+67
-0
lib/prepare.js
lib/prepare.js
+28
-14
未找到文件。
docs/.vuepress/config.js
浏览文件 @
b50ff521
...
...
@@ -14,20 +14,21 @@ module.exports = {
{
title
:
'
Guide
'
,
children
:
[
[
'
/
'
,
'
Home
'
],
'
/getting-started
'
,
'
/markdown
'
,
'
/assets
'
,
'
/using-vue
'
,
'
/config
'
,
'
/default-theme
'
'
/default-theme
'
,
'
/theming
'
,
'
/deploy
'
]
},
{
title
:
'
API
Reference
'
,
title
:
'
Config
Reference
'
,
children
:
[
[
'
/markdown#emoji
'
,
'
MMMMM
'
],
'
/theming
'
,
'
/deploy
'
'
/config
'
,
'
/test/
'
]
}
],
...
...
docs/test/README.md
0 → 100644
浏览文件 @
b50ff521
# Test Page
hello dude
lib/app/Content.js
浏览文件 @
b50ff521
...
...
@@ -16,13 +16,15 @@ export default {
updateMeta
()
},
render
(
h
)
{
const
componentName
=
this
.
$page
.
path
===
'
/
'
?
'
index
'
:
this
.
$page
.
path
.
replace
(
/^
\/
/
,
''
)
.
replace
(
/
\.
html$/
,
''
)
.
replace
(
/
\/
/g
,
'
-
'
)
return
h
(
'
page-
'
+
componentName
)
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$/
,
''
)}
`
}
}
...
...
lib/default-theme/SideBar.vue
浏览文件 @
b50ff521
...
...
@@ -2,9 +2,7 @@
<div
class=
"sidebar"
>
<ul>
<li
v-for=
"(item, i) in sidebarItems"
>
<router-link
v-if=
"item.type === 'page'"
:to=
"item.path"
>
{{
item
.
title
||
item
.
path
}}
</router-link>
<SidebarLink
v-if=
"item.type === 'page'"
:item=
"item"
/>
<SidebarGroup
v-else-if=
"item.type === 'group'"
:item=
"item"
:first=
"i === 0"
...
...
@@ -17,9 +15,10 @@
<
script
>
import
SidebarGroup
from
'
./SidebarGroup.vue
'
import
SidebarLink
,
{
isActive
,
normalize
,
ensureExt
}
from
'
./SidebarLink.vue
'
export
default
{
components
:
{
SidebarGroup
},
components
:
{
SidebarGroup
,
SidebarLink
},
data
()
{
return
{
openGroupIndex
:
0
...
...
@@ -42,6 +41,9 @@ export default {
methods
:
{
toggleGroup
(
index
)
{
this
.
openGroupIndex
=
index
===
this
.
openGroupIndex
?
-
1
:
index
},
isActive
(
page
)
{
return
isActive
(
this
.
$route
,
page
)
}
}
}
...
...
@@ -49,18 +51,12 @@ export default {
function
resolveOpenGroupIndex
(
route
,
items
)
{
for
(
let
i
=
0
;
i
<
items
.
length
;
i
++
)
{
const
item
=
items
[
i
]
if
(
item
.
type
===
'
group
'
&&
item
.
children
.
some
(
c
=>
isActive
(
route
,
c
.
path
)))
{
if
(
item
.
type
===
'
group
'
&&
item
.
children
.
some
(
c
=>
isActive
(
route
,
c
)))
{
return
i
}
}
}
function
isActive
(
route
,
path
)
{
// TODO refine
const
routePath
=
route
.
path
return
routePath
.
indexOf
(
path
)
===
0
}
function
resolveSidebar
(
route
,
site
)
{
const
{
pages
,
themeConfig
}
=
site
const
sidebarConfig
=
themeConfig
.
sidebar
...
...
@@ -98,7 +94,7 @@ function resolveItem (item, pages, isNested) {
})
}
else
{
if
(
isNested
)
{
throw
new
E
rror
(
console
.
e
rror
(
'
[vuepress] Nested sidebar groups are not supported.
'
+
'
Consider using navbar + categories instead.
'
)
...
...
@@ -123,46 +119,15 @@ function resolvePage (pages, rawPath) {
})
}
}
}
const
hashRE
=
/#.*$/
const
extRE
=
/
\.(
md|html
)
$/
const
slashRE
=
/
\/
$/
function
normalize
(
path
)
{
return
path
.
replace
(
hashRE
,
''
)
.
replace
(
extRE
,
''
)
}
function
ensureExt
(
path
)
{
if
(
slashRE
.
test
(
path
))
{
return
path
}
const
hashMatch
=
path
.
match
(
hashRE
)
const
hash
=
hashMatch
?
hashMatch
[
0
]
:
''
return
normalize
(
path
)
+
'
.html
'
+
hash
console
.
error
(
`[vuepress] No matching page found for sidebar item "
${
rawPath
}
"`
)
return
{}
}
</
script
>
<
style
lang=
"stylus"
>
@import './styles/config.stylus'
.sidebar
ul
padding 0
margin 0
list-style-type none
a
display inline-block
color $textColor
border-left 0.25rem solid transparent
padding 0.25rem
padding-left 1.25rem
&:hover
color $accentColor
&.router-link-active
font-weight 600
color $accentColor
border-left-color $accentColor
</
style
>
lib/default-theme/SidebarGroup.vue
浏览文件 @
b50ff521
...
...
@@ -7,9 +7,7 @@
<transition
name=
"sidebar-group"
@
enter=
"setHeight"
>
<ul
class=
"sidebar-group-items"
ref=
"items"
v-if=
"open"
>
<li
v-for=
"child in item.children"
>
<router-link
v-if=
"child.type === 'page'"
:to=
"child.path"
>
{{
child
.
title
||
child
.
path
}}
</router-link>
<SidebarLink
v-if=
"child.type === 'page'"
:item=
"child"
/>
</li>
</ul>
</transition>
...
...
@@ -17,9 +15,12 @@
</
template
>
<
script
>
import
SidebarLink
from
'
./SidebarLink.vue
'
export
default
{
name
:
'
SidebarGroup
'
,
props
:
[
'
item
'
,
'
first
'
,
'
open
'
],
components
:
{
SidebarLink
},
mounted
()
{
const
{
items
}
=
this
.
$refs
if
(
items
)
this
.
setHeight
(
items
)
...
...
lib/default-theme/SidebarLink.vue
0 → 100644
浏览文件 @
b50ff521
<
script
>
export
default
{
functional
:
true
,
props
:
[
'
item
'
],
render
(
h
,
{
parent
:
{
$route
},
props
:
{
item
}})
{
return
h
(
'
router-link
'
,
{
props
:
{
to
:
item
.
path
,
activeClass
:
''
,
exactActiveClass
:
''
},
class
:
{
'
sidebar-link
'
:
true
,
// use custom active class matching logic
// due to edge case of paths ending with / + hash
active
:
isActive
(
$route
,
item
)
}
},
[
item
.
title
||
item
.
path
])
}
}
const
hashRE
=
/#.*$/
const
extRE
=
/
\.(
md|html
)
$/
const
slashRE
=
/
\/
$/
export
function
isActive
(
route
,
page
)
{
const
routePath
=
normalize
(
route
.
path
)
const
pagePath
=
normalize
(
page
.
path
)
if
(
routePath
===
'
/
'
||
pagePath
===
'
/
'
)
{
return
routePath
===
pagePath
}
else
{
return
routePath
.
indexOf
(
pagePath
)
===
0
}
}
export
function
normalize
(
path
)
{
return
path
.
replace
(
hashRE
,
''
)
.
replace
(
extRE
,
''
)
}
export
function
ensureExt
(
path
)
{
if
(
slashRE
.
test
(
path
))
{
return
path
}
const
hashMatch
=
path
.
match
(
hashRE
)
const
hash
=
hashMatch
?
hashMatch
[
0
]
:
''
return
normalize
(
path
)
+
'
.html
'
+
hash
}
</
script
>
<
style
lang=
"stylus"
>
@import './styles/config.stylus'
a.sidebar-link
display inline-block
color $textColor
border-left 0.25rem solid transparent
padding 0.25rem
padding-left 1.25rem
&:hover
color $accentColor
&.active
font-weight 600
color $accentColor
border-left-color $accentColor
</
style
>
lib/prepare.js
浏览文件 @
b50ff521
...
...
@@ -104,15 +104,12 @@ async function resolveOptions (sourceDir) {
// resolve pages
const
pagesData
=
options
.
pageFiles
.
map
(
file
=>
{
const
urlPath
=
isIndexFile
(
file
)
?
'
/
'
:
`/
${
file
.
replace
(
/
\.
md$/
,
''
).
replace
(
/
\\
/g
,
'
/
'
)}
.html`
const
content
=
fs
.
readFileSync
(
path
.
resolve
(
sourceDir
,
file
),
'
utf-8
'
)
const
data
=
{
path
:
urlPath
path
:
fileToPath
(
file
)
}
// extract yaml frontmatter
const
content
=
fs
.
readFileSync
(
path
.
resolve
(
sourceDir
,
file
),
'
utf-8
'
)
const
frontmatter
=
yaml
.
loadFront
(
content
)
// infer title
const
title
=
inferTitle
(
frontmatter
)
...
...
@@ -140,7 +137,7 @@ async function resolveOptions (sourceDir) {
async
function
genComponentRegistrationFile
({
sourceDir
,
pageFiles
})
{
function
genImport
(
file
)
{
const
name
=
t
oComponentName
(
file
)
const
name
=
fileT
oComponentName
(
file
)
const
baseDir
=
/
\.
md$/
.
test
(
file
)
?
sourceDir
:
path
.
resolve
(
sourceDir
,
'
.vuepress/components
'
)
...
...
@@ -154,17 +151,34 @@ async function genComponentRegistrationFile ({ sourceDir, pageFiles }) {
return
`import Vue from 'vue'\n`
+
all
.
map
(
genImport
).
join
(
'
\n
'
)
}
function
toComponentName
(
file
)
{
const
isPage
=
/
\.
md$/
.
test
(
file
)
const
isIndex
=
isIndexFile
(
file
)
const
normalizedName
=
isIndex
?
'
index
'
:
file
.
replace
(
/
\.(
vue|md
)
$/
,
''
).
replace
(
/
\/
|
\\
/g
,
'
-
'
)
return
isPage
?
`page-
${
normalizedName
}
`
:
normalizedName
const
indexRE
=
/
\b
readme
\.
md$/i
const
extRE
=
/
\.(
vue|md
)
$/
function
fileToPath
(
file
)
{
if
(
isIndexFile
(
file
))
{
// README.md -> /
// foo/README.md -> /foo/
return
'
/
'
+
file
.
replace
(
indexRE
,
''
)
}
else
{
// foo.md -> /foo.html
// foo/bar.md -> /foo/bar.html
return
`/
${
file
.
replace
(
extRE
,
''
).
replace
(
/
\\
/g
,
'
/
'
)}
.html`
}
}
function
fileToComponentName
(
file
)
{
let
normalizedName
=
file
.
replace
(
/
\/
|
\\
/g
,
'
-
'
)
.
replace
(
extRE
,
''
)
if
(
isIndexFile
(
file
))
{
normalizedName
=
normalizedName
.
replace
(
/readme$/i
,
'
index
'
)
}
const
pagePrefix
=
/
\.
md$/
.
test
(
file
)
?
`page-`
:
``
return
`
${
pagePrefix
}${
normalizedName
}
`
}
function
isIndexFile
(
file
)
{
return
/^
(
index|readme
)\.
md$/i
.
test
(
file
)
return
indexRE
.
test
(
file
)
}
async
function
resolveComponents
(
sourceDir
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录