import React from 'react'
import Link from './Link'
import {rootPage} from './utils'

export default function NodeLink(props) {
  const {href, children: content} = props
  if (content) {
    return <Link {...props} />
  }
  const node = rootPage.first(node => node.path === href)
  const children = (node ? node.meta.title : null) || href
  return <Link {...props}>{children}</Link>
}

@@ -79,16 +79,563 @@
 utils'%0A%0A
+/**%0A * The NodeLink component takes an %60href%60 and optional %60children%60.%0A * If no %60children%60 are provided, we look up the %22node%22 of the corresponding%0A * page in the tree (the one whose %60path%60 matches the given %60href%60) and use%0A * that node's %60meta.title%60 if it's set. In other words, given the following%0A * page:%0A *%0A * %60%60%60md%0A * ---%0A * title: Foo Bar%0A * ---%0A * %3C!-- foo/bar.md --%3E%0A * %60%60%60%0A *%0A * The following instance of NodeLink should render a link to %22/foo/bar%22 with%0A * %22Foo Bar%22 as its text:%0A *%0A * %60%60%60jsx%0A * %3CNodeLink href=%22/foo/bar%22 /%3E%0A * %60%60%60%0A */%0A
 export d

add doc comment for NodeLink