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">
{app.state.crumbs ? (
<div className="pl-4">
<Breadcrumbs crumbs={app.state.crumbs.slice(0, 2)} />
<Breadcrumbs crumbs={app.state.crumbs.slice(0, 1)} />
</div>
) : null}
<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 orderBy from 'lodash.orderby'
const createCrumbs = (saa) =>
saa.map((crumb, i) => {
const entry = get(pbn.en, saa.slice(0, i + 1))
const createCrumbs = (path) =>
path.map((crumb, i) => {
const entry = get(pbn.en, path.slice(0, i + 1))
const val = { t: entry.t, s: entry.s }
if (entry.o) val.o = entry.o
@ -23,16 +23,16 @@ const createSections = () => {
return orderBy(sections, 'o')
}
export const loadNavigation = (saa = []) => {
export const loadNavigation = (path = []) => {
// Creat crumbs array
const crumbs = createCrumbs(saa)
const crumbs = createCrumbs(path)
return {
saa,
slug: saa.join('/'),
path,
slug: path.join('/'),
crumbs,
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,
}
}

View file

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

View file

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