/** * Which section of a settings page shows an option, by its form path * ("general.breadcrumbs_separator") or key: the pages use it to open the * section an error or a reset is in, the settings search to send a match * from another page to the right place. */ /** Which General settings section shows an option. */ export const generalSection = (path: string): string => { const [group, key = ''] = path.split('.'); if (group === 'titles') { return 'webmaster'; } if (group === 'llms') { return 'llms'; } if (key.startsWith('breadcrumbs_')) { return 'breadcrumbs'; } if (key.startsWith('wc_')) { return 'woocommerce'; } if (key.startsWith('redirects_')) { return 'redirects'; } if (key.startsWith('monitor_404_')) { return 'monitor404'; } if (key.startsWith('image_')) { return 'images'; } if (key === 'frontend_css') { return 'frontend'; } if (key === 'conflict_mode') { return 'plugins'; } if ( key === 'remove_generator' || key === 'disable_xmlrpc' || key.startsWith('rss_') ) { return 'others'; } return 'links'; }; /** Which Titles & meta section shows an option; the per-type ones by their slug. */ export const titlesSection = ( path: string, postTypes: string[], taxonomies: string[] ): string => { const [group, key = ''] = path.split('.'); if (group === 'general') { return 'misc'; } const longestFirst = (a: string, b: string): number => b.length - a.length; const postType = [...postTypes] .sort(longestFirst) .find(slug => key.startsWith(`pt_${slug}_`)); if (postType) { return `post-type-${postType}`; } const taxonomy = [...taxonomies] .sort(longestFirst) .find(slug => key.startsWith(`tax_${slug}_`)); if (taxonomy) { return `taxonomy-${taxonomy}`; } if ( [ 'separator', 'capitalize_titles', 'noindex_empty_archives', 'robots_max_snippet', 'robots_max_video_preview', 'robots_max_image_preview', 'og_default_image', 'twitter_card_type', ].includes(key) ) { return 'global'; } if ( ['knowledge_graph', 'website_', 'organization_'].some(prefix => key.startsWith(prefix) ) ) { return 'local'; } if (key === 'facebook_app_id' || key.startsWith('social_')) { return 'social'; } if (key.startsWith('home_')) { return 'homepage'; } if (key.startsWith('author_')) { return 'authors'; } return 'misc'; }; /** Which of the fixed sections shows a field, so an error or a reset lands on it. */ export const sitemapSection = (key: string): string => key === 'include_authors' ? 'authors' : key === 'ping_indexnow' ? 'indexnow' : key.startsWith('news_') || key === 'include_videos' ? 'media' : key.startsWith('html_') ? 'html' : 'general'; /** The contact fields of Local SEO, which the Contact section shows. */ export const CONTACT_KEYS = [ 'phone', 'email', 'price_range', 'latitude', 'longitude', ] as const; /** Which Local SEO section shows an option. */ export const localSection = (path: string): string => { const key = path.split('.').pop() ?? ''; if ( (CONTACT_KEYS as readonly string[]).includes(key) || key === 'opening_hours' || key === 'map_provider' || key === 'google_maps_key' ) { return 'contact'; } if (key === 'about_page' || key === 'contact_page' || key === 'show_map') { return 'pages'; } if (key === 'multiple_locations') { return 'locations'; } return 'business'; };