import React, { useEffect, useMemo, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Button, Badge, Notice, LengthMeter, Segmented } from './ui'; import { IconRefresh, IconExternal, IconShield } from './icons'; import { copyText } from '../copy'; /** * The
of one page, in full. * * Every other SEO plugin writes these tags and then never shows them again — * you find out what shipped by reading view-source. This tab is the whole tag * list with three things view-source cannot give you: why each tag is there, * whether it is within its limit, and (on request) a comparison against the * head the server actually delivered, which is the only way a duplicate * canonical from a theme ever becomes visible. */ const STATUS = { ok: { tone: 'good', label: 'ok' }, missing: { tone: 'serious', label: 'missing' }, empty: { tone: 'neutral', label: __('not set', 'ai-rank-suite') }, long: { tone: 'warning', label: __('too long', 'ai-rank-suite') }, off: { tone: 'neutral', label: __('switched off', 'ai-rank-suite') }, delegated: { tone: 'warning', label: __('other plugin', 'ai-rank-suite') }, }; export default function HeadTab({ postId, initial = null, onLoad, onGoTo }) { const [data, setData] = useState(initial); const [error, setError] = useState(null); const [live, setLive] = useState(null); const [liveBusy, setLiveBusy] = useState(false); const [view, setView] = useState('tags'); const [copied, setCopied] = useState(false); const [open, setOpen] = useState({}); const load = () => { setError(null); api .get(`/content/${postId}/head`) .then((next) => { setData(next); onLoad?.(next); }) .catch((e) => setError(e.message)); }; // The drawer usually has this already — refetch only when it does not, so // switching to this tab is instant rather than a second spinner. useEffect(() => { setLive(null); if (initial) { setData(initial); return; } setData(null); load(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [postId, initial]); const fetchLive = async () => { setLiveBusy(true); try { setLive(await api.get(`/content/${postId}/head/live`)); } catch (e) { setLive({ ok: false, reason: e.message }); } finally { setLiveBusy(false); } }; const byGroup = useMemo(() => { if (!data) return []; return data.groups .map((g) => ({ ...g, tags: data.tags.filter((t) => t.group === g.id) })) .filter((g) => g.tags.length > 0); }, [data]); if (error) return{tag.why}
} {tag.note && ({tag.note}
)} {tag.limit > 0 && tag.value && ({tag.value.slice(0, 4000)}
)}
{tag.key}
written by{' '}
{tag.owner === 'airs'
? 'AI Rank Suite'
: tag.owner === 'wp'
? 'WordPress'
: tag.owner}
{onGoTo && jump(tag.key) && (
)}
{data.source || '(nothing would be written)'}
{__('This is what AI Rank Suite writes. The finished head will also contain whatever your theme and other plugins add — use the live check to see the whole thing.', 'ai-rank-suite')}
{d.planned}
{d.live || absent}
{__('A difference here is almost always a page cache serving an older head. If it survives a cache purge, something else is overwriting the tag.', 'ai-rank-suite')}