feat: auto-generate robots.txt
This commit is contained in:
parent
773fb7b73e
commit
05daa7025e
2 changed files with 14 additions and 0 deletions
|
@ -23,6 +23,7 @@ const { title, description, image = '/static/twitter-card.png' } = Astro.props
|
||||||
<meta name="generator" content={Astro.generator} />
|
<meta name="generator" content={Astro.generator} />
|
||||||
|
|
||||||
<link rel="canonical" href={canonicalURL} />
|
<link rel="canonical" href={canonicalURL} />
|
||||||
|
<link rel="sitemap" href="/sitemap-index.xml" />
|
||||||
|
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
<meta name="title" content={title} />
|
<meta name="title" content={title} />
|
||||||
|
|
13
src/pages/robots.txt.ts
Normal file
13
src/pages/robots.txt.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import type { APIRoute } from 'astro'
|
||||||
|
|
||||||
|
const getRobotsTxt = (sitemapURL: URL) => `
|
||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: ${sitemapURL.href}
|
||||||
|
`
|
||||||
|
|
||||||
|
export const GET: APIRoute = ({ site }) => {
|
||||||
|
const sitemapURL = new URL('sitemap-index.xml', site)
|
||||||
|
return new Response(getRobotsTxt(sitemapURL))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue