import Link from 'next/link' import orderBy from 'lodash.orderby' import { TutorialIcon, GuideIcon, HelpIcon, DocsIcon, RssIcon, ShowcaseIcon, UserIcon, } from 'shared/components/icons.mjs' import { Breadcrumbs } from 'shared/components/breadcrumbs.mjs' export const ns = ['sections'] // List of icons matched to top-level slug const icons = { // FreeSewing.dev guides: (className = '') => , howtos: (className = '') => , reference: (className = '') => , tutorials: (className = '') => , // FreeSewing.org blog: (className = '') => , showcase: (className = '') => , docs: (className = '') => , account: (className = '') => , Account: (className = '') => , } /* helper method to order nav entries */ const order = (obj) => orderBy(obj, ['o', 't'], ['asc', 'asc']) // Component for the collapse toggle // Exported for re-use export const Chevron = ({ w = 8, m = 2 }) => ( ) // Helper method to filter out the real children const currentChildren = (current) => Object.values(order(current)).filter((entry) => typeof entry === 'object') // Shared classes for links // Exported for re-use export const linkClasses = ` py-1 text-base text-base-content sm:text-base-content hover:text-secondary sm:hover:text-secondary ` // Figure out whether a page is on the path to the active page const isActive = (slug, active) => { console.log({ slug, active }) if (!slug) return false if (slug === active) return true let result = true const slugParts = slug.split('/') const activeParts = active.split('/') for (const i in slugParts) { if (slugParts[i] !== activeParts[i]) result = false } return result } // Component that renders a sublevel of navigation const SubLevel = ({ nodes = {}, active = '' }) => (
    {currentChildren(nodes).map((child) => Object.keys(child).length > 4 ? (
  • {child.s === active ? <>• : <>°} {child.t}
  • ) : (
  • {child.s === active ? <>• : <>°} {child.t}
  • ) )}
) export const Icons = ({ app, ulClasses = '', linkClasses = `grow text-lg lg:text-xl py-1 text-base-content sm:text-base-content hover:text-secondary sm:hover:text-secondary hover:cursor-pointer flex flex-col items-center`, linkStyle = {}, }) => { if (!app.state?.nav) return null const output = [] for (const page of order(app.state.nav)) { output.push(
  • {icons[page.s] ? icons[page.s]('w-14 h-14') : } {page.t}
  • ) } return
      {output}
    } export const MainSections = ({ app }) => { if (!app.state.sections) return null // Ensure each page as an `o` key so we can put them in order const sortableSections = app.state.sections.map((s) => ({ ...s, o: s.o ? s.o : s.t })) const output = [] for (const page of orderBy(sortableSections, ['o', 't'])) { const act = isActive(page.s, app.state.slug) const txt = ( <> {icons[page.s] ? ( icons[page.s](`w-6 h-6 ${act ? 'text-secondary-content' : ''}`) ) : ( )} {page.t} ) const item = (
  • {act ? ( {txt} ) : ( {txt} )}
  • ) output.push(item) } return
      {output}
    } export const ActiveSection = ({ app }) => (
    {app.state.crumbs ? (
    ) : null}
    )