1
0
Fork 0
freesewing/sites/shared/components/mdx/read-more.js

33 lines
1,002 B
JavaScript
Raw Normal View History

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
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
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
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)) {
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>
}
2021-12-19 19:08:54 +01:00
export default ReadMore