1
0
Fork 0

chore(shared): Renamed saa to path

This commit is contained in:
Joost De Cock 2023-03-26 06:56:43 +02:00
parent 244f4524c4
commit 85c0916186
4 changed files with 13 additions and 13 deletions

View file

@ -225,7 +225,7 @@ export const ActiveSection = ({ app }) => (
<div className="mt-4 pt-4 border-t-2"> <div className="mt-4 pt-4 border-t-2">
{app.state.crumbs ? ( {app.state.crumbs ? (
<div className="pl-4"> <div className="pl-4">
<Breadcrumbs crumbs={app.state.crumbs.slice(0, 2)} /> <Breadcrumbs crumbs={app.state.crumbs.slice(0, 1)} />
</div> </div>
) : null} ) : null}
<div className="pr-2"> <div className="pr-2">

View file

@ -2,9 +2,9 @@ import get from 'lodash.get'
import { prebuildNavigation as pbn } from 'site/prebuild/navigation.mjs' import { prebuildNavigation as pbn } from 'site/prebuild/navigation.mjs'
import orderBy from 'lodash.orderby' import orderBy from 'lodash.orderby'
const createCrumbs = (saa) => const createCrumbs = (path) =>
saa.map((crumb, i) => { path.map((crumb, i) => {
const entry = get(pbn.en, saa.slice(0, i + 1)) const entry = get(pbn.en, path.slice(0, i + 1))
const val = { t: entry.t, s: entry.s } const val = { t: entry.t, s: entry.s }
if (entry.o) val.o = entry.o if (entry.o) val.o = entry.o
@ -23,16 +23,16 @@ const createSections = () => {
return orderBy(sections, 'o') return orderBy(sections, 'o')
} }
export const loadNavigation = (saa = []) => { export const loadNavigation = (path = []) => {
// Creat crumbs array // Creat crumbs array
const crumbs = createCrumbs(saa) const crumbs = createCrumbs(path)
return { return {
saa, path,
slug: saa.join('/'), slug: path.join('/'),
crumbs, crumbs,
sections: createSections(), sections: createSections(),
nav: saa.length > 1 ? get(pbn.en, saa[0]) : pbn.en[saa[0]], nav: path.length > 1 ? get(pbn.en, path[0]) : pbn.en[path[0]],
title: crumbs.slice(-1)[0].t, title: crumbs.slice(-1)[0].t,
} }
} }

View file

@ -83,7 +83,7 @@ export async function getStaticProps({ params }) {
toc, toc,
intro: intro.join(' '), intro: intro.join(' '),
page: { page: {
saa: params.mdxslug, // slug as array (saa) path: params.mdxslug, // path to page as array
...mdxMeta[params.mdxslug.join('/')], ...mdxMeta[params.mdxslug.join('/')],
}, },
params, params,

View file

@ -20,7 +20,7 @@ const defaultState = {
*/ */
export function useApp(props = {}) { export function useApp(props = {}) {
const { bugsnag = false, page = {}, loadState = {} } = props const { bugsnag = false, page = {}, loadState = {} } = props
const { saa = [] } = page const { path = [] } = page
const reportError = useBugsnag(props?.bugsnag) const reportError = useBugsnag(props?.bugsnag)
@ -29,8 +29,8 @@ export function useApp(props = {}) {
useEffect(() => { useEffect(() => {
// Force update of navigation info (nav, title, crumbs) on each page change // Force update of navigation info (nav, title, crumbs) on each page change
if (saa.length > 0) setState({ ...state, ...loadNavigation(saa) }) if (path.length > 0) setState({ ...state, ...loadNavigation(path) })
}, [saa, state.slug, state.title]) }, [path, state.slug, state.title])
/* /*
* Helper methods for partial state updates * Helper methods for partial state updates