Skip to content

Robots

Robots renders a <meta name="robots"> tag in your document head to control crawler behavior. It is scoped to resolving and serializing the directive content only and does not affect robots.txt generation.

The component accepts two mutually exclusive modes. Pass either content or any combination of directive props, but not both.

proptypedefaultrequireddescription
contentstring-Yes (in content mode)Raw robots directive string rendered directly as the meta content value.
proptypedefaultrequireddescription
noindexboolean-NoPrevents the page from being indexed.
nofollowboolean-NoPrevents crawlers from following links on the page.
noarchiveboolean-NoPrevents search engines from caching the page.
nosnippetboolean-NoPrevents a snippet from being generated in search results.
indexifembeddedboolean-NoAllows indexing when the page is embedded in an iframe.
max-snippetnumber-NoMaximum character length for the text snippet in search results.
max-image-preview"none" | "standard" | "large"-NoMaximum size of image preview in search results.
max-video-previewnumber-NoMaximum number of seconds for a video snippet in search results.
notranslateboolean-NoPrevents the page from being translated in search results.
noimageindexboolean-NoPrevents images on the page from being indexed.
unavailable_afterstring-NoDate and time after which the page should no longer be shown in search results.

Input:

<Robots content="noindex, nofollow" />

Output:

<meta name="robots" content="noindex, nofollow" />

Uses the integration headTags.robots value when no props are provided.

Input:

// in astro.config.mjs integration config
eminence({
headTags: {
robots: { noindex: true },
},
});
<Robots />

Output:

<meta name="robots" content="noindex" />

Input:

<Robots
noindex
nofollow
max-snippet={50}
unavailable_after="25 Jun 2026 15:00:00 PST"
/>

Output:

<meta
name="robots"
content="noindex, nofollow, max-snippet:50, unavailable_after:25 Jun 2026 15:00:00 PST"
/>

The component accepts either a raw content string or directive props, but not both. The raw string mode is useful for ad-hoc values, while directive mode is type-safe and composable.

---
import config from "virtual:eminence-astro-suite/head-tags";
import { hasAnyProp } from "../utils";
interface DirectiveProps {
noindex?: boolean;
nofollow?: boolean;
noarchive?: boolean;
nosnippet?: boolean;
indexifembedded?: boolean;
"max-snippet"?: number;
"max-image-preview"?: "none" | "standard" | "large";
"max-video-preview"?: number;
notranslate?: boolean;
noimageindex?: boolean;
unavailable_after?: string;
}
type Props =
| ({
content: string;
} & {
[K in keyof DirectiveProps]?: never;
})
| (DirectiveProps & {
content?: never;
});
const directivesToContent = (directives: DirectiveProps): string => {
return Object.entries(directives)
.flatMap(([directive, value]) => {
if (value === undefined || value === false) return [];
if (value === true) return [directive];
return [`${directive}:${value}`];
})
.join(", ");
};
const { content, ...directiveProps } = hasAnyProp(Astro.props)
? Astro.props
: (config.robots ?? {});
const robotsContent =
content ?? directivesToContent(directiveProps as DirectiveProps);
---
{robotsContent && <meta name="robots" content={robotsContent} />}