2022-05-11 17:41:24 +02:00
|
|
|
import React from 'react'
|
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import Link from 'next/link'
|
|
|
|
// Shared components
|
|
|
|
import Logo from 'shared/components/logos/freesewing.js'
|
|
|
|
import Aside from 'shared/components/navigation/aside'
|
|
|
|
import get from 'lodash.get'
|
|
|
|
|
|
|
|
const PageTitle = ({ app, slug, title }) => {
|
|
|
|
if (title) return <h1>{title}</h1>
|
|
|
|
if (slug) return <h1>{get(app.navigation, slug.split('/')).__title}</h1>
|
|
|
|
|
|
|
|
return <h1>FIXME: This page has no title</h1>
|
|
|
|
}
|
|
|
|
|
|
|
|
const Breadcrumbs = ({ app, slug=false, title }) => {
|
|
|
|
if (!slug) return null
|
|
|
|
const crumbs = []
|
|
|
|
const chunks = slug.split('/')
|
|
|
|
for (const i in chunks) {
|
|
|
|
const j = parseInt(i)+parseInt(1)
|
|
|
|
const page = get(app.navigation, chunks.slice(0,j))
|
|
|
|
if (page) crumbs.push([page.__linktitle, '/'+chunks.slice(0,j).join('/'), (j < chunks.length)])
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ul className="flex flex-row flex-wrap gap-2 font-bold">
|
|
|
|
<li>
|
|
|
|
<Link href="/">
|
|
|
|
<a title="To the homepage" className="text-base-content">
|
|
|
|
<Logo size={24} fill="currentColor" stroke={false}/>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</li>
|
|
|
|
{crumbs.map(crumb => (
|
|
|
|
<React.Fragment key={crumb[1]}>
|
|
|
|
<li className="text-base-content">»</li>
|
|
|
|
<li>
|
|
|
|
{crumb[2]
|
|
|
|
? (
|
|
|
|
<Link href={crumb[1]}>
|
|
|
|
<a title={crumb[0]} className="text-secondary hover:text-secondary-focus">
|
|
|
|
{crumb[0]}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
: <span className="text-base-content">{crumb[0]}</span>
|
|
|
|
}
|
|
|
|
</li>
|
|
|
|
</React.Fragment>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const DefaultLayout = ({ app, title=false, children=[] }) => {
|
|
|
|
const router = useRouter()
|
|
|
|
const slug = router.asPath.slice(1)
|
|
|
|
|
2022-05-12 19:59:33 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Aside app={app} slug={slug} mobileOnly />
|
|
|
|
{children}
|
|
|
|
</>
|
|
|
|
)
|
2022-05-11 17:41:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default DefaultLayout
|