Review a robots metadata policy

src/robots-policy.tsTypeScript
@@ -0,0 +1,29 @@
1+export type RobotsDirective =
2+ | "index, follow"
3+ | "noindex, follow"
4+ | "noindex, nofollow";
5+
6+export interface PageRequest {
7+ pathname: string;
8+ searchParams: URLSearchParams;
9+ authenticated: boolean;
10+}
11+
12+export function selectRobotsDirective({
13+ pathname,
14+ searchParams,
15+}: PageRequest): RobotsDirective {
16+ if (searchParams.get("preview") === "true") {
17+ return "noindex, nofollow";
18+ }
19+
20+ if (pathname.startsWith("/account") || pathname.startsWith("/admin")) {
21+ return "noindex, follow";
22+ }
23+
24+ return "index, follow";
25+}
26+
27+export function renderRobotsMeta(request: PageRequest): string {
28+ return `<meta name="robots" content="${selectRobotsDirective(request)}">`;
29+}