Files
ipal-kit/docs/agent/skills/ipal-nav/resources/nav-code.md
T
Radosław SmolińskiandClaude Opus 5.5 b61b753ec2 Merge main (security-perf + SEO) into docs; finish English docs and agent guide
- Resolve conflicts in analytics, consent, content, i18n, mcp and stats,
  keeping the docs fixes and the new code behaviour, verified against src
- Translate the remaining 14 module pages, ipal-seo-check skill and script
- Integrate the security-perf and SEO agent-guide text: getRobots,
  isPathVisible, Search & AI (DNS verification first, meta fields optional),
  sitemap index/cache/503, consentMode basic/advanced, policyVersion,
  globalOverrides, revalidatePath / buildGlobalRevalidateHook, authAccess,
  firstUserAdmin, allowCollectionMismatch, unknown-IP rate limit; stale
  claims fixed across AGENT.md, skills, frontend, developer guide, vibe
- docsConsistency: pending list removed (all docs English); relative links
  now also check #anchors

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-22 17:59:52 +02:00

6.3 KiB

Navigation code — Header, Footer, mobile menu

Resources of the ipal-nav skill. Rules: node_modules/@intecion/ipal-kit/docs/agent/AGENT.md §6.8. Requires the UI primitives from ../ipal-block/resources/section-code.md (CMSLink, Media).

Navigation, footer and company data are project globals (the model depends on the client and the country), built from the same shared fields as sections. Logo and name live in Site Settings — do not duplicate them in Header.

// src/globals/Header.ts
import type { GlobalConfig } from 'payload'
import { buildLinkField, buildLinksField, rowLabel } from '@intecion/ipal-kit'

export const Header: GlobalConfig = {
  slug: 'header',
  access: { read: () => true },
  fields: [
    {
      name: 'navItems',
      type: 'array',
      labels: { singular: 'Menu item', plural: 'Menu items' },
      maxRows: 8,
      admin: { initCollapsed: true, components: rowLabel('link.label', 'Menu item') },
      fields: [
        buildLinkField({ appearances: false }),
        {
          name: 'subItems',          // one submenu level — we do not build deeper
          type: 'array',
          labels: { singular: 'Submenu item', plural: 'Submenu' },
          maxRows: 10,
          admin: { initCollapsed: true, components: rowLabel('link.label', 'Submenu item') },
          fields: [buildLinkField({ appearances: false })],
        },
      ],
    },
    buildLinksField({ maxRows: 1 }),     // CTA button in the header
    {
      name: 'menuLabel',
      type: 'text',
      localized: true,
      admin: { description: 'Accessible label of the mobile menu button, e.g. "Menu".' },
    },
  ],
}
// src/globals/Footer.ts
import type { GlobalConfig } from 'payload'
import { buildLinkField, rowLabel } from '@intecion/ipal-kit'

export const Footer: GlobalConfig = {
  slug: 'footer',
  access: { read: () => true },
  fields: [
    {
      name: 'columns',
      type: 'array',
      labels: { singular: 'Column', plural: 'Columns' },
      maxRows: 4,
      admin: { initCollapsed: true, components: rowLabel('heading', 'Column') },
      fields: [
        { name: 'heading', type: 'text', localized: true },
        {
          name: 'items',
          type: 'array',
          labels: { singular: 'Link', plural: 'Links' },
          admin: { initCollapsed: true, components: rowLabel('link.label', 'Link') },
          fields: [buildLinkField({ appearances: false })],
        },
      ],
    },
    { name: 'note', type: 'textarea', localized: true },   // e.g. "All rights reserved"
  ],
}
  • Legal links in the footer (privacy policy, cookies, terms): await getSystemLinks(locale) from lib/content — href and label (page title) from System Pages; do not add them by hand to columns, do not write labels in code.
  • Highlighted menu item / button in a different colour = a style in the admin panel: buildLinkField({ appearances: ['default', { label: 'Highlighted', value: 'highlight' }] }) → a class in the project.
  • Company data (name, address, NIP/ABN, phone) — the project's company global; the footer and JSON-LD read from it. Compute the copyright year in code (new Date().getFullYear()), take the name from the global.
  • Refreshing: a global changes on every page → buildGlobalRevalidateHook in afterChange (hooks.md; it calls revalidatePath('/', 'layout'), skips seeds/migrations and context.disableRevalidate; buildRevalidateHook is for collections):
// src/globals/Header.ts (and Footer, Company)
import { buildGlobalRevalidateHook } from '@intecion/ipal-kit'
import { revalidatePath } from 'next/cache'

hooks: {
  afterChange: [buildGlobalRevalidateHook({ revalidatePath })],
},

The plugin resolves the menu from the global: await resolveNav(header.navItems, locale) from lib/content → { href, label, internal, newTab, targetProps, children }[] (dead links skipped, any depth). This is plain data — it goes straight to the client MobileNav. Do not create lib/navigation.ts.

// src/components/layout/Header.tsx — server
import Link from 'next/link'
import type { Header as HeaderData } from '@/payload-types'
import { resolveNav } from '@/lib/content'
import { CMSLink } from '@/components/ui/CMSLink'
import { MobileNav } from './MobileNav'

export async function Header({ header, locale }: { header: HeaderData; locale: string }) {
  const items = await resolveNav(header.navItems, locale)
  return (
    <header className="border-b">
      <nav className="container flex items-center justify-between py-4">
        {/* logo: Site Settings → <Media> */}
        <ul className="hidden gap-6 md:flex">
          {items.map((item) => (
            <li key={item.href}>
              <Link href={item.href} {...item.targetProps}>{item.label}</Link>
            </li>
          ))}
        </ul>
        {header.links?.map(({ id, link }) => <CMSLink key={id} link={link} locale={locale} />)}
        <MobileNav items={items} menuLabel={header.menuLabel ?? ''} />
      </nav>
    </header>
  )
}
// src/components/layout/MobileNav.tsx — client, open state only
'use client'
import { useState } from 'react'
import Link from 'next/link'
import type { NavItem } from '@intecion/ipal-kit'   // TYPE import — does not pull in server code

export function MobileNav({ items, menuLabel }: { items: NavItem[]; menuLabel: string }) {
  const [open, setOpen] = useState(false)
  return (
    <div className="md:hidden">
      <button type="button" aria-expanded={open} aria-label={menuLabel} onClick={() => setOpen(!open)}>
        <span aria-hidden>☰</span>
      </button>
      {open && (
        <ul>
          {items.map((item) => (
            <li key={item.href}>
              <Link href={item.href} onClick={() => setOpen(false)}>{item.label}</Link>
            </li>
          ))}
        </ul>
      )}
    </div>
  )
}

Fetch Header/Footer in [locale]/layout.tsx (through a cached getter in lib/) and pass them as props — the layout is the only place that assembles them.

Footer component — content inside NoSnippet (otherwise Google shows the footer address as the description of every subpage; seo.md → "Descriptions in Google"):

import { NoSnippet } from '@intecion/ipal-kit/rsc'

<footer className="…">
  <NoSnippet className="…">{/* company data, links, legal links */}</NoSnippet>
</footer>