import { LOCAL_SECTIONS, SECTIONS, postTypeSection, sitemapPostTypeSection, sitemapTaxonomySection, taxonomySection, } from '../../pages/seo/settings.copy'; export interface SeoNavSection { key: string; label: string; description: string; /** A caption the row sits under ("Post types"), for the per-type sections. */ group?: string; } export interface SeoTypes { post_types: Record; taxonomies: Record; } export interface SeoNavSections { defaultKey: string; sections: SeoNavSection[]; } const pick = ( copy: Record, keys: Record ): SeoNavSection[] => Object.entries(keys).map(([key, copyKey]) => ({ key, label: copy[copyKey].title, description: copy[copyKey].description, })); /** * The sections the sidebar lists under each settings page; the page's own * rail adds the per-type ones Titles & meta and Sitemap build at runtime. */ export const SEO_NAV_SECTIONS: Record = { '/seo/general': { defaultKey: 'links', sections: pick(SECTIONS, { links: 'links', breadcrumbs: 'breadcrumbs', redirects: 'redirects', monitor404: 'monitor404', images: 'images', frontend: 'frontend', webmaster: 'webmaster', plugins: 'plugins', llms: 'llms', robots: 'robots', htaccess: 'htaccess', others: 'others', woocommerce: 'woocommerce', }), }, '/seo/titles': { defaultKey: 'global', sections: pick(SECTIONS, { global: 'global', local: 'local', social: 'social', homepage: 'homepage', authors: 'authors', misc: 'misc', }), }, '/seo/sitemap': { defaultKey: 'general', sections: pick(SECTIONS, { general: 'sitemapGeneral', media: 'sitemapMedia', html: 'sitemapHtml', indexnow: 'sitemapIndexnow', authors: 'sitemapAuthors', }), }, '/seo/local': { defaultKey: 'business', sections: pick(LOCAL_SECTIONS, { business: 'business', contact: 'contact', pages: 'pages', locations: 'locations', }), }, }; /** * The per-type sections Titles & meta and Sitemap add after their fixed * ones, from the types the plugin reports; the keys match what the pages * read from `?section=`. */ export function typeSections(page: string, types: SeoTypes): SeoNavSection[] { const titles = page === '/seo/titles'; if (!titles && page !== '/seo/sitemap') return []; const postType = titles ? postTypeSection : sitemapPostTypeSection; const taxonomy = titles ? taxonomySection : sitemapTaxonomySection; return [ ...Object.entries(types.post_types).map(([slug, label]) => ({ key: `post-type-${slug}`, label, description: postType(label).description, group: 'Post types', })), ...Object.entries(types.taxonomies).map(([slug, label]) => ({ key: `taxonomy-${slug}`, label, description: taxonomy(label).description, group: 'Taxonomies', })), ]; } export function currentSection(page: string, search: string): string | null { const known = SEO_NAV_SECTIONS[page]; if (!known) return null; return new URLSearchParams(search).get('section') ?? known.defaultKey; }