Skip to content

Commit

Permalink
feat: add robots.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
yongsk0066 committed Nov 9, 2024
1 parent e942ee8 commit 289fdd1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
User-agent: *
Allow: /

Sitemap: https://yongseok.me/sitemap-index.xml
2 changes: 2 additions & 0 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const { title, description, image = "/blog-placeholder-1.jpg" } = Astro.props;
---

<link rel="sitemap" href="/sitemap-index.xml" />

<meta
name="naver-site-verification"
content="a46530fae7250188dbcc74f5334891f7ce851180"
Expand Down
2 changes: 2 additions & 0 deletions src/components/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const { title, description, image = "/nano.png" } = Astro.props;
content="a46530fae7250188dbcc74f5334891f7ce851180"
/>

<link rel="sitemap" href="/sitemap-index.xml" />

<!-- Global Metadata -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
Expand Down
13 changes: 13 additions & 0 deletions src/pages/robots.txt.ts
Original file line number Diff line number Diff line change
@@ -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));
};

0 comments on commit 289fdd1

Please sign in to comment.