feat(shared): Added DocsTitle MDX component
This commit is contained in:
parent
ea8d540305
commit
c3dc282717
2 changed files with 21 additions and 0 deletions
19
sites/shared/components/mdx/docs-title.mjs
Normal file
19
sites/shared/components/mdx/docs-title.mjs
Normal file
|
@ -0,0 +1,19 @@
|
|||
import get from 'lodash.get'
|
||||
import { useNavigation } from 'site/hooks/use-navigation.mjs'
|
||||
|
||||
const getPage = {
|
||||
dev: (slug, nav) => get(nav, slug.split('/')),
|
||||
org: (root, nav) => {
|
||||
// Fixme: make this work for org
|
||||
if (!root) return nav
|
||||
if (root.indexOf('/') === -1) return nav[root]
|
||||
return get(nav, root.split('/'))
|
||||
},
|
||||
}
|
||||
|
||||
export const DocsTitle = ({ slug, className = '', site = 'org' }) => {
|
||||
const { siteNav } = useNavigation()
|
||||
const page = getPage[site](slug, siteNav)
|
||||
|
||||
return page ? <span className={className}>{page.t}</span> : null
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue