Skip to content

Commit

Permalink
Fix #392
Browse files Browse the repository at this point in the history
- Chech if page exists and only create link it if it exists
- If subcommand page exists link to page, if not, create anchor
  • Loading branch information
iAdramelk committed Aug 8, 2019
1 parent 765ffc5 commit 1833075
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Documentation/Markdown/utils/remark-linker.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
;`use strict`

import visit from 'unist-util-visit'
import { getItemByPath } from '../../SidebarMenu/helper'

function linker() {
function transformer(tree) {
visit(tree, 'inlineCode', function(node, index, parent) {
if (parent.type !== 'link' && /dvc\s+[a-z-.]+/.test(node.value)) {
let parts = node.value.split(/\s+/)
let url = '/doc/commands-reference/' + parts[1]

let tmpUrl = '/doc/commands-reference/'
let url

if (getItemByPath(tmpUrl + parts[1])) {
url = tmpUrl = tmpUrl + parts[1]
}

if (parts.length > 2) {
url += '#' + parts[2]
if (getItemByPath(tmpUrl + parts[2])) {
url += '/' + parts[2]
} else {
url += '#' + parts[2]
}
}

parent.children[index] = {
type: 'link',
url: url,
children: [node],
position: node.position
if (url) {
parent.children[index] = {
type: 'link',
url: url,
children: [node],
position: node.position
}
}
}
})
Expand Down

0 comments on commit 1833075

Please sign in to comment.