2021-12-24 18:17:02 +01:00
|
|
|
import get from 'lodash.get'
|
|
|
|
import orderBy from 'lodash.orderby'
|
|
|
|
import Link from 'next/link'
|
|
|
|
|
|
|
|
// Helper method to filter out the real children
|
2022-12-04 15:04:56 +01:00
|
|
|
const order = (obj) => orderBy(obj, ['__order', '__title'], ['asc', 'asc'])
|
|
|
|
const currentChildren = (current) =>
|
|
|
|
Object.values(order(current)).filter((entry) => typeof entry === 'object')
|
2021-12-24 18:17:02 +01:00
|
|
|
|
2023-01-29 16:44:02 +01:00
|
|
|
export const ReadMore = (props) => {
|
2022-05-30 15:36:39 +02:00
|
|
|
// Don't bother if we don't have the navigation tree in app
|
|
|
|
if (!props.app) return null
|
2021-12-24 18:17:02 +01:00
|
|
|
|
2022-01-16 12:21:36 +01:00
|
|
|
const root = get(props.app.navigation, props.slug.split('/'))
|
2021-12-24 18:17:02 +01:00
|
|
|
const list = []
|
|
|
|
for (const page of currentChildren(root)) {
|
2022-12-04 15:04:56 +01:00
|
|
|
list.push(
|
|
|
|
<li key={page.__slug} className={props.recurse ? 'ont-bold' : ''}>
|
|
|
|
<Link
|
|
|
|
href={`/${page.__slug}`}
|
|
|
|
className={props.recurse ? 'inline-block font-bold pt-3 pb-1' : ''}
|
|
|
|
>
|
|
|
|
{page.__title}
|
|
|
|
</Link>
|
|
|
|
{props.recurse && <ReadMore app={props.app} slug={page.__slug} />}
|
|
|
|
</li>
|
|
|
|
)
|
2021-12-24 18:17:02 +01:00
|
|
|
}
|
|
|
|
return <ul>{list}</ul>
|
|
|
|
}
|