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 type { MetadataRoute } from "next"
export const dynamic = "force-dynamic"
export default async function robots(): Promise<MetadataRoute.Robots> {
const slugs = (await getAllUrls()).map(s => `/r/${s.slug}`)
@@ -13,11 +15,15 @@ export default async function robots(): Promise<MetadataRoute.Robots> {
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, {