Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
unidocs-unicloud-zh
提交
cbc83acf
U
unidocs-unicloud-zh
项目概览
DCloud
/
unidocs-unicloud-zh
通知
84
Star
2
Fork
20
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
9
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
unidocs-unicloud-zh
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
9
合并请求
9
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
cbc83acf
编写于
4月 11, 2024
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 改进读取 _sidebar 逻辑
上级
91ef2a5e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
88 deletion
+79
-88
docs/.vuepress/config.js
docs/.vuepress/config.js
+2
-2
docs/.vuepress/markdown/createSidebar.js
docs/.vuepress/markdown/createSidebar.js
+76
-63
docs/.vuepress/utils/index.js
docs/.vuepress/utils/index.js
+1
-23
未找到文件。
docs/.vuepress/config.js
浏览文件 @
cbc83acf
...
...
@@ -4,7 +4,7 @@ const highlight = require('@vuepress/markdown/lib/highlight')
const
translatePlugin
=
require
(
'
./markdown/translate
'
)
const
headerPlugin
=
require
(
'
./markdown/header
'
)
const
createSidebar
=
require
(
'
./markdown/createSidebar
'
)
const
{
simplifySlugText
,
tabs
}
=
require
(
'
./utils
'
)
const
{
simplifySlugText
}
=
require
(
'
./utils
'
)
const
copyOptions
=
require
(
'
./config/copy
'
);
const
base
=
'
/uniCloud/
'
...
...
@@ -39,7 +39,7 @@ const config = {
themeConfig
:
{
titleLogo
:
'
https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png
'
,
logo
:
'
https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/logo.png
'
,
sidebar
:
createSidebar
(
tabs
),
sidebar
:
createSidebar
(),
sidebarDepth
:
0
,
nextLinks
:
false
,
prevLinks
:
false
,
...
...
docs/.vuepress/markdown/createSidebar.js
浏览文件 @
cbc83acf
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
MarkdownIt
=
require
(
'
markdown-it
'
);
const
MarkdownIt
=
require
(
'
markdown-it
'
)
const
glob
=
require
(
'
glob
'
)
const
createMarkdownArray
=
require
(
'
./createMarkdownArray
'
)
const
{
isExternal
}
=
require
(
'
../utils
'
)
const
createSiteMap
=
require
(
'
./createSiteMap
'
)
;
const
createSiteMap
=
require
(
'
./createSiteMap
'
)
const
links
=
[]
function
parseBar
(
tab
,
file
,
options
)
{
const
textName
=
options
.
text
||
'
text
'
const
linkName
=
options
.
link
||
'
link
'
const
contents
=
[]
const
textName
=
options
.
text
||
'
text
'
const
linkName
=
options
.
link
||
'
link
'
const
contents
=
[]
new
MarkdownIt
()
.
parse
(
fs
.
readFileSync
(
file
,
{
encoding
:
'
utf-8
'
}).
replace
(
/<!--
([\s\S]
*
?)
-->/g
,
""
))
.
forEach
(
token
=>
{
if
(
token
.
type
===
'
inline
'
)
{
let
text
let
link
let
config
=
{}
token
.
children
.
forEach
(
child
=>
{
switch
(
child
.
type
)
{
case
'
text
'
:
text
=
text
||
child
.
content
break
;
case
'
link_open
'
:
link
=
link
||
new
Map
(
child
.
attrs
).
get
(
'
href
'
)
break
;
case
'
code_inline
'
:
try
{
config
=
JSON
.
parse
(
child
.
content
)
}
catch
(
error
)
{
}
break
;
new
MarkdownIt
().
parse
(
fs
.
readFileSync
(
file
,
{
encoding
:
'
utf-8
'
}).
replace
(
/<!--
([\s\S]
*
?)
-->/g
,
''
)).
forEach
(
token
=>
{
if
(
token
.
type
===
'
inline
'
)
{
let
text
let
link
let
config
=
{}
token
.
children
.
forEach
(
child
=>
{
switch
(
child
.
type
)
{
case
'
text
'
:
text
=
text
||
child
.
content
break
case
'
link_open
'
:
link
=
link
||
new
Map
(
child
.
attrs
).
get
(
'
href
'
)
break
case
'
code_inline
'
:
try
{
config
=
JSON
.
parse
(
child
.
content
)
}
catch
(
error
)
{}
break
default
:
break
;
}
})
default
:
break
}
})
if
(
link
&&
!
isExternal
(
link
))
{
if
(
!
link
.
startsWith
(
'
/
'
))
{
const
linkFirstItem
=
link
.
split
(
'
/
'
)[
0
]
if
(
tab
.
indexOf
(
linkFirstItem
)
===
-
1
)
{
link
=
path
.
join
(
tab
,
link
).
replace
(
/
\\
/g
,
'
/
'
)
}
}
if
(
link
&&
!
isExternal
(
link
))
{
if
(
!
link
.
startsWith
(
'
/
'
))
{
const
linkFirstItem
=
link
.
split
(
'
/
'
)[
0
]
if
(
tab
.
indexOf
(
linkFirstItem
)
===
-
1
)
{
link
=
path
.
join
(
tab
,
link
).
replace
(
/
\\
/g
,
'
/
'
)
}
}
link
=
path
.
join
(
'
/
'
,
link
.
replace
(
/
\.
md
\b
/
,
''
)
.
replace
(
/
\b
README
\b
/
,
''
)
.
replace
(
/
\/
index/
,
'
/
'
)
.
replace
(
/
\?
id=/
,
'
#
'
))
.
replace
(
/
\\
/g
,
'
/
'
)
link
=
path
.
join
(
'
/
'
,
link
.
replace
(
/
\.
md
\b
/
,
''
)
.
replace
(
/
\b
README
\b
/
,
''
)
.
replace
(
/
\/
index/
,
'
/
'
)
.
replace
(
/
\?
id=/
,
'
#
'
)
)
.
replace
(
/
\\
/g
,
'
/
'
)
links
.
push
(
link
)
}
links
.
push
(
link
)
}
contents
.
push
({
level
:
token
.
level
,
[
textName
]:
text
,
[
linkName
]:
link
,
...
config
})
}
})
contents
.
push
({
level
:
token
.
level
,
[
textName
]:
text
,
[
linkName
]:
link
,
...
config
,
})
}
})
return
createMarkdownArray
(
contents
,
options
.
children
)
return
createMarkdownArray
(
contents
,
options
.
children
)
}
module
.
exports
=
function
(
tabs
=
[]
)
{
const
sidebar
=
{}
module
.
exports
=
function
()
{
const
sidebar
=
{}
tabs
.
forEach
(
tab
=>
{
sidebar
[
tab
]
=
parseBar
(
tab
,
path
.
join
(
__dirname
,
'
../../
'
,
tab
,
'
_sidebar.md
'
),
{
text
:
'
title
'
,
link
:
'
path
'
})
})
// 需要反向,vuepress 在匹配路由的时候,会按照数组的顺序匹配,所以需要将最长的路径放在最前面,否则 / 路径会第一个被匹配,导致右侧栏不跟随路由变化
const
tabs
=
glob
.
GlobSync
(
path
.
resolve
(
__dirname
,
'
../../**/_sidebar.md
'
))
.
found
.
map
(
file
=>
{
const
tab
=
file
.
match
(
/
\/
docs
([\s\S]
+
)
_sidebar.md/
)[
1
]
return
tab
})
.
reverse
()
createSiteMap
(
links
,
()
=>
links
.
length
=
0
)
;(
process
.
env
.
DOCS_LITE
?
[]
:
tabs
).
forEach
(
tab
=>
{
sidebar
[
tab
]
=
parseBar
(
tab
,
path
.
join
(
__dirname
,
'
../../
'
,
tab
,
'
_sidebar.md
'
),
{
text
:
'
title
'
,
link
:
'
path
'
,
})
})
return
tabs
.
length
?
sidebar
:
false
}
\ No newline at end of file
createSiteMap
(
links
,
()
=>
(
links
.
length
=
0
))
return
tabs
.
length
?
sidebar
:
false
}
docs/.vuepress/utils/index.js
浏览文件 @
cbc83acf
...
...
@@ -14,29 +14,7 @@ function simplifySlugText(text) {
return
text
;
}
function
getFormattedDate
()
{
const
now
=
new
Date
();
const
year
=
now
.
getFullYear
();
const
month
=
(
now
.
getMonth
()
+
1
).
toString
().
padStart
(
2
,
'
0
'
);
const
day
=
now
.
getDate
().
toString
().
padStart
(
2
,
'
0
'
);
const
hours
=
now
.
getHours
().
toString
().
padStart
(
2
,
'
0
'
);
const
minutes
=
now
.
getMinutes
().
toString
().
padStart
(
2
,
'
0
'
);
const
seconds
=
now
.
getSeconds
().
toString
().
padStart
(
2
,
'
0
'
);
const
formattedDate
=
`
${
year
}
-
${
month
}
-
${
day
}
_
${
hours
}
-
${
minutes
}
-
${
seconds
}
`
;
return
formattedDate
;
}
// 顺序有要求,会影响 for 循环匹配侧边栏
const
tabs
=
[
'
/
'
]
module
.
exports
=
{
isExternal
,
simplifySlugText
,
getFormattedDate
,
tabs
:
process
.
env
.
DOCS_LITE
?
[]
:
tabs
simplifySlugText
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录