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.

prop type default required description
content string - Yes (in content mode) Raw robots directive string rendered directly as the meta content value.
prop type default required description
noindex boolean - No Prevents the page from being indexed.
nofollow boolean - No Prevents crawlers from following links on the page.
noarchive boolean - No Prevents search engines from caching the page.
nosnippet boolean - No Prevents a snippet from being generated in search results.
indexifembedded boolean - No Allows indexing when the page is embedded in an iframe.
max-snippet number - No Maximum character length for the text snippet in search results.
max-image-preview "none" | "standard" | "large" - No Maximum size of image preview in search results.
max-video-preview number - No Maximum number of seconds for a video snippet in search results.
notranslate boolean - No Prevents the page from being translated in search results.
noimageindex boolean - No Prevents images on the page from being indexed.
unavailable_after string - No Date 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} />}