Have return no rules when no slugs

This commit is contained in:
2025-08-06 23:50:38 +02:00
parent 0e18f19c1c
commit efa4fdcb95

View File

@@ -1,6 +1,8 @@
import { getAllUrls } from "@/lib/db/urls" import { getAllUrls } from "@/lib/db/urls"
import type { MetadataRoute } from "next" import type { MetadataRoute } from "next"
export const dynamic = "force-dynamic"
export default async function robots(): Promise<MetadataRoute.Robots> { export default async function robots(): Promise<MetadataRoute.Robots> {
const slugs = (await getAllUrls()).map(s => `/r/${s.slug}`) const slugs = (await getAllUrls()).map(s => `/r/${s.slug}`)
@@ -13,11 +15,15 @@ export default async function robots(): Promise<MetadataRoute.Robots> {
crawlDelay: 60 crawlDelay: 60
}] }]
const dynamicRules: MetadataRoute.Robots["rules"] = [{ console.log(slugs.length)
const dynamicRules: MetadataRoute.Robots["rules"] = slugs.length > 0 ?
[{
userAgent: allowedBots, userAgent: allowedBots,
allow: slugs, allow: slugs,
crawlDelay: 1 crawlDelay: 1
}] }] :
[]
return { return {
rules: [...mainRules, ...dynamicRules, { rules: [...mainRules, ...dynamicRules, {