2021-12-16 19:01:37 +01:00
|
|
|
import get from 'lodash.get'
|
2021-12-11 14:04:05 +01:00
|
|
|
import Icon from 'shared/components/icon/index.js'
|
2021-12-12 18:00:08 +01:00
|
|
|
import nav from 'site/prebuild/navigation.js'
|
2021-12-12 18:58:24 +01:00
|
|
|
import Link from 'next/link'
|
2021-12-16 19:01:37 +01:00
|
|
|
import orderBy from 'lodash.orderby'
|
2021-12-11 14:04:05 +01:00
|
|
|
|
2021-12-12 18:58:24 +01:00
|
|
|
const keepClosed = ['blog', 'showcase', ]
|
|
|
|
|
2021-12-16 19:01:37 +01:00
|
|
|
const linkClasses = {className: 'hover:text-underline color-primary'}
|
|
|
|
|
|
|
|
|
2021-12-12 18:58:24 +01:00
|
|
|
const TopLevel = ({ icon, title, nav, current }) => (
|
|
|
|
<details className='p-2' open={((keepClosed.indexOf(current._slug) === -1) ? 1 : 0)}>
|
|
|
|
<summary className={`
|
|
|
|
flex flex-row uppercase gap-4 font-bold text-lg
|
|
|
|
hover:cursor-row-resize
|
|
|
|
hover:bg-base-200
|
|
|
|
p-2
|
2021-12-16 19:01:37 +01:00
|
|
|
text-primary
|
2021-12-12 18:58:24 +01:00
|
|
|
`}>
|
2021-12-16 19:01:37 +01:00
|
|
|
{icon}
|
|
|
|
<Link
|
|
|
|
href={`/${current._slug}/`}
|
|
|
|
className='hover:cursor-pointer'
|
|
|
|
>
|
|
|
|
{title}
|
|
|
|
</Link>
|
2021-12-11 18:19:20 +01:00
|
|
|
</summary>
|
|
|
|
<div className='pl-4'>
|
|
|
|
<ul>
|
2021-12-16 19:01:37 +01:00
|
|
|
{orderBy(Object.values(current._children), ['order', 'title'], ['asc', 'asc']).map(item => {
|
|
|
|
console.log(item)
|
|
|
|
const target = item._slug ? get(nav, item._slug.split('/')) : '/'
|
|
|
|
return (
|
|
|
|
<li key={item._slug}>
|
|
|
|
{ item?._linktitle || item._title }
|
|
|
|
</li>
|
|
|
|
)
|
|
|
|
})}
|
2021-12-11 18:19:20 +01:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</details>
|
|
|
|
)
|
|
|
|
|
2021-12-12 18:58:24 +01:00
|
|
|
// TODO: Get rid of this when markdown has been restructured
|
|
|
|
const remove = ['contributors', 'developers', 'editors', 'translators']
|
|
|
|
const Navigation = ({ nav, app }) => {
|
|
|
|
const output = []
|
|
|
|
for (const key of Object.keys(nav[app.language]).sort()) {
|
|
|
|
if (
|
|
|
|
key.slice(0,1) !== '_' &&
|
|
|
|
remove.indexOf(key) === -1
|
|
|
|
) output.push(<TopLevel
|
|
|
|
icon={<Icon icon={key}/>}
|
|
|
|
title={key}
|
|
|
|
key={key}
|
2021-12-16 19:01:37 +01:00
|
|
|
nav={nav[app.language]}
|
2021-12-12 18:58:24 +01:00
|
|
|
current={nav[app.language][key]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return output
|
|
|
|
}
|
|
|
|
|
2021-12-11 14:04:05 +01:00
|
|
|
const PrimaryMenu = props => {
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav className={`
|
|
|
|
sm:max-w-sm
|
2021-12-11 18:19:20 +01:00
|
|
|
grow
|
2021-12-11 14:04:05 +01:00
|
|
|
`}>
|
2021-12-12 18:58:24 +01:00
|
|
|
<Navigation nav={nav} app={props.app}/>
|
2021-12-11 14:04:05 +01:00
|
|
|
</nav>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PrimaryMenu
|