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

29 lines
955 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
2021-12-25 13:43:41 +01:00
const order = obj => orderBy(obj, ['__order', '__title'], ['asc', 'asc'])
const currentChildren = current => Object.values(order(current))
2021-12-24 18:17:02 +01:00
.filter(entry => (typeof entry === 'object'))
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' : ''}>
2021-12-24 18:17:02 +01:00
<Link href={`/${page.__slug}`}>
<a className={props.recurse ? 'inline-block font-bold pt-3 pb-1' : ''}>{page.__title}</a>
2021-12-24 18:17:02 +01:00
</Link>
{props.recurse && <ReadMore app={props.app} slug={page.__slug} />}
2021-12-24 18:17:02 +01:00
</li>)
}
return <ul>{list}</ul>
}
2021-12-19 19:08:54 +01:00
export default ReadMore