From efa4fdcb9529eb41e52efc651e802772db73e247 Mon Sep 17 00:00:00 2001 From: Taken Date: Wed, 6 Aug 2025 23:50:38 +0200 Subject: [PATCH] Have return no rules when no slugs --- src/app/robots.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/app/robots.ts b/src/app/robots.ts index b6f28d0..539491a 100644 --- a/src/app/robots.ts +++ b/src/app/robots.ts @@ -1,6 +1,8 @@ import { getAllUrls } from "@/lib/db/urls" import type { MetadataRoute } from "next" +export const dynamic = "force-dynamic" + export default async function robots(): Promise { const slugs = (await getAllUrls()).map(s => `/r/${s.slug}`) @@ -13,11 +15,15 @@ export default async function robots(): Promise { crawlDelay: 60 }] - const dynamicRules: MetadataRoute.Robots["rules"] = [{ - userAgent: allowedBots, - allow: slugs, - crawlDelay: 1 - }] + console.log(slugs.length) + + const dynamicRules: MetadataRoute.Robots["rules"] = slugs.length > 0 ? + [{ + userAgent: allowedBots, + allow: slugs, + crawlDelay: 1 + }] : + [] return { rules: [...mainRules, ...dynamicRules, {