import React, { useEffect, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import ScreenVerdict from '../components/ScreenVerdict'; import Htaccess from './Htaccess'; import { Card, Button, Switch, Badge, Notice, Tabs, PageState, CodeBlock, MetricGrid, Progress } from '../components/ui'; import { IconExternal } from '../components/icons'; function useSettings(endpoint) { const [data, setData] = useState(null); const [busy, setBusy] = useState(false); const [saved, setSaved] = useState(false); const [error, setError] = useState(null); useEffect(() => { api.get(endpoint).then(setData).catch((e) => setError(e.message)); }, [endpoint]); const update = (patch) => setData((d) => ({ ...d, settings: { ...d.settings, ...patch } })); const save = async () => { setBusy(true); setError(null); try { setData(await api.put(endpoint, data.settings)); setSaved(true); setTimeout(() => setSaved(false), 2200); } catch (e) { setError(e.message); } finally { setBusy(false); } }; return { data, update, save, busy, saved, error }; } function Robots() { const { data, update, save, busy, saved, error } = useSettings('/settings/robots'); if (!data) return ; const s = data.settings; const ARCHIVES = [ { key: 'noindex_author', label: __('Author archives', 'ai-rank-suite'), hint: __('Usually duplicate content on single-author sites', 'ai-rank-suite') }, { key: 'noindex_date', label: __('Date archives', 'ai-rank-suite'), hint: __('Rarely useful as search results', 'ai-rank-suite') }, { key: 'noindex_search', label: __('Internal search results', 'ai-rank-suite'), hint: __('Google explicitly discourages indexing these', 'ai-rank-suite') }, { key: 'noindex_attachment', label: __('Attachment pages', 'ai-rank-suite'), hint: __('Thin pages that only hold one media file', 'ai-rank-suite') }, { key: 'noindex_paginated', label: __('Paginated archive pages', 'ai-rank-suite'), hint: __('Page 2, 3, … of an archive', 'ai-rank-suite') }, ]; const onCount = ARCHIVES.filter((a) => !!s[a.key]).length; const verdict = { tone: onCount === 0 ? 'warning' : 'good', text: onCount === 0 ? __('Every archive type is left indexable — search engines can spend their crawl on author, date and search pages.', 'ai-rank-suite') : s.robots_txt_enabled ? sprintf(__('%1$d of %2$d archive types are set to noindex and custom robots.txt rules are on.', 'ai-rank-suite'), onCount, ARCHIVES.length) : sprintf(__('%1$d of %2$d archive types are set to noindex.', 'ai-rank-suite'), onCount, ARCHIVES.length), why: onCount === 0 ? __('Author, date, search and attachment archives are the pages nobody wants to rank; noindexing them keeps the crawl on the pages that matter.', 'ai-rank-suite') : __('Blocked archives keep the crawl on real content. Anything here changes robots meta on the next request — no cache purge needed beyond the plugin\'s own.', 'ai-rank-suite'), }; return (
{error && {error}} ✓ {__('Saved', 'ai-rank-suite')}} >
{ARCHIVES.map((a) => (
{sprintf(__('Set %s to noindex', 'ai-rank-suite'), a.label)}
{a.hint}
update({ [a.key]: v })} />
))}
update({ max_snippet: Number(e.target.value) })} />
{__('-1 = no limit (recommended)', 'ai-rank-suite')}
update({ robots_txt_enabled: v })} label={__('Enable custom rules', 'ai-rank-suite')} /> } > {data.physical_robots_txt && (
{__('A physical', 'ai-rank-suite')} robots.txt {__('file exists on your server and overrides everything here. Delete it so WordPress can serve robots.txt dynamically.', 'ai-rank-suite')}
)}