fix: use page to provide robot txt

This commit is contained in:
KazooTTT
2024-11-23 23:29:58 +08:00
parent 25fb1cc0cb
commit 7292415765
4 changed files with 29 additions and 23 deletions

View File

@ -1,22 +0,0 @@
User-agent: *
Allow: /
HOST: https://blog.kazoottt.top
# Sitemaps
Sitemap: https://blog.kazoottt.top/sitemap-index.xml
# Common crawl optimizations
Disallow: /api/
Disallow: /_astro/
Disallow: /404
Disallow: /500
# Allow crawling of content
Allow: /posts/
Allow: /categories/
Allow: /tags/
Allow: /blog/
Allow: /friends/
Allow: /blog/
Allow: /tools/

26
src/pages/robots.txt.ts Normal file
View File

@ -0,0 +1,26 @@
import type { APIRoute } from 'astro'
import { siteConfig } from '../site.config'
const robotsTxt = `
User-agent: *
Allow: /
HOST: ${siteConfig.site}
# Sitemaps
Sitemap: ${siteConfig.site}/sitemap.xml
# Disallow system and error pages
Disallow: /api/
Disallow: /_astro/
Disallow: /404
Disallow: /500
`
export const GET: APIRoute = () => {
return new Response(robotsTxt.trim(), {
headers: {
'Content-Type': 'text/plain; charset=utf-8',
},
})
}

View File

@ -20,7 +20,8 @@ export const siteConfig: SiteConfig = {
month: 'short', month: 'short',
year: 'numeric' year: 'numeric'
} }
} },
site: 'https://blog.kazoottt.top',
} }
export const menuLinks: Array<{ title: string; path: string }> = [ export const menuLinks: Array<{ title: string; path: string }> = [

View File

@ -8,6 +8,7 @@ export type SiteConfig = {
locale: string | string[] | undefined locale: string | string[] | undefined
options: Intl.DateTimeFormatOptions options: Intl.DateTimeFormatOptions
} }
site: string
} }
export type PaginationLink = { export type PaginationLink = {