Skip to content

Commit

Permalink
Merge pull request #8 from mqycn/dev
Browse files Browse the repository at this point in the history
计算面包屑 ,父级目录 增加 index.html 的支持
  • Loading branch information
mqycn authored Sep 19, 2020
2 parents 7f350e8 + c8da290 commit 4ad5489
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/markdown/breadcrumb/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// 计算面包屑

const indexFiles = [
'README.md',
'index.html'
]

module.exports = async ({ fileNode }, next) => {
const breadcrumb = fileNode.breadcrumb = {
nodes: [fileNode], //父子关系,
Expand Down Expand Up @@ -29,7 +34,7 @@ function toHtml(formatNode, separator) {
treeNode, // 其他节点 为 treeNode 节点
treeNode.isFileNode ?
treeNode : // 如果节点是 fileNode,直接传入
treeNode.children.length > 0 && treeNode.getFileName(treeNode.children[0]) == 'README.md' ?
treeNode.children.length > 0 && indexFiles.indexOf(treeNode.getFileName(treeNode.children[0])) != -1 ?
treeNode.children[0] : // 如果 当前 treeNode 节点存在子节点,并且第一个为 README.md,传入
null
)
Expand All @@ -41,7 +46,11 @@ function formatDefault(treeNode, indexFileNode) {
let itemHtml = ''
if (indexFileNode) {
// treeNode存在 首页( README.md),显示链接
itemHtml = `<a href="/${indexFileNode.path.replace('README.md', '')}">${indexFileNode.title || indexFileNode.path}</a>`
let path = indexFileNode.path
indexFiles.forEach(item=>{
path = path.replace(item, '')
})
itemHtml = `<a href="/${path}">${indexFileNode.title || indexFileNode.path}</a>`
} else {
// treeNode 无首页,只显示 路径文本
itemHtml = treeNode.path
Expand Down

0 comments on commit 4ad5489

Please sign in to comment.