Skip to content

Commit

Permalink
Add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
andreilgeorgescu authored Oct 25, 2024
1 parent 3e8e766 commit 4e2aaba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@astrojs/mdx": "^3.1.6",
"@astrojs/react": "^3.6.2",
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"@astrojs/sitemap": "^3.2.1",
"@astrojs/tailwind": "^5.1.0",
"@headlessui/react": "^2.1.8",
"@heroicons/react": "^2.1.5",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions public/robots.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/components/Head.astro
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const orgStructuredData = {
title={site.name}
href={new URL("feed.xml", Astro.site)}
/>
<link rel="sitemap" href="/sitemap-index.xml" />
<title>
{title} | {site.name}
</title>
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 4e2aaba

Please sign in to comment.