From 1fc851541fb021facb7907aec053f461570eedda Mon Sep 17 00:00:00 2001 From: Cosimo Matteini Date: Sun, 29 Dec 2024 16:46:42 +0100 Subject: [PATCH] add astro sitemap integration --- astro.config.mjs | 3 ++- package-lock.json | 52 ++++++++++++++++++++++++++++++++++++++ package.json | 5 ++-- public/robots.txt | 3 +++ src/layouts/Document.astro | 1 + 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 45f79a1..a9f6a4b 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -8,6 +8,7 @@ import rehypeSlug from "rehype-slug" import { prettyCodePlugins } from "./config/pretty-code" import { isAnalyticsEnabled } from "./config/analytics" import vercel from "@astrojs/vercel" +import sitemap from "@astrojs/sitemap" // https://astro.build/config export default defineConfig({ @@ -20,7 +21,7 @@ export default defineConfig({ prettyCodePlugins, ], }, - integrations: [tailwind(), icon(), mdx()], + integrations: [tailwind(), icon(), mdx(), sitemap()], output: "static", adapter: vercel({ webAnalytics: { diff --git a/package-lock.json b/package-lock.json index 52ca432..2c618b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,7 @@ "version": "2.0.0", "dependencies": { "@astrojs/mdx": "4.0.3", + "@astrojs/sitemap": "3.2.1", "@astrojs/tailwind": "5.1.4", "@astrojs/vercel": "8.0.1", "@fontsource-variable/inter": "5.1.0", @@ -244,6 +245,16 @@ "node": "^18.17.1 || ^20.3.0 || >=22.0.0" } }, + "node_modules/@astrojs/sitemap": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@astrojs/sitemap/-/sitemap-3.2.1.tgz", + "integrity": "sha512-uxMfO8f7pALq0ADL6Lk68UV6dNYjJ2xGUzyjjVj60JLBs5a6smtlkBYv3tQ0DzoqwS7c9n4FUx5lgv0yPo/fgA==", + "dependencies": { + "sitemap": "^8.0.0", + "stream-replace-string": "^2.0.0", + "zod": "^3.23.8" + } + }, "node_modules/@astrojs/tailwind": { "version": "5.1.4", "resolved": "https://registry.npmjs.org/@astrojs/tailwind/-/tailwind-5.1.4.tgz", @@ -2508,6 +2519,14 @@ "undici-types": "~5.26.4" } }, + "node_modules/@types/sax": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz", + "integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/tar": { "version": "6.1.13", "resolved": "https://registry.npmjs.org/@types/tar/-/tar-6.1.13.tgz", @@ -10322,6 +10341,11 @@ "suf-log": "^2.5.3" } }, + "node_modules/sax": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" + }, "node_modules/semver": { "version": "7.6.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", @@ -10438,6 +10462,29 @@ "version": "1.0.5", "license": "MIT" }, + "node_modules/sitemap": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-8.0.0.tgz", + "integrity": "sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==", + "dependencies": { + "@types/node": "^17.0.5", + "@types/sax": "^1.2.1", + "arg": "^5.0.0", + "sax": "^1.2.4" + }, + "bin": { + "sitemap": "dist/cli.js" + }, + "engines": { + "node": ">=14.0.0", + "npm": ">=6.0.0" + } + }, + "node_modules/sitemap/node_modules/@types/node": { + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -10491,6 +10538,11 @@ "node": ">= 0.6" } }, + "node_modules/stream-replace-string": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/stream-replace-string/-/stream-replace-string-2.0.0.tgz", + "integrity": "sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==" + }, "node_modules/stream-to-array": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/stream-to-array/-/stream-to-array-2.3.0.tgz", diff --git a/package.json b/package.json index ab9294e..ee6bdaa 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "dependencies": { "@astrojs/mdx": "4.0.3", + "@astrojs/sitemap": "3.2.1", "@astrojs/tailwind": "5.1.4", "@astrojs/vercel": "8.0.1", "@fontsource-variable/inter": "5.1.0", @@ -35,16 +36,16 @@ }, "devDependencies": { "@astrojs/check": "0.9.4", - "eslint": "9.17.0", "@eslint/js": "9.17.0", "@types/eslint__js": "8.42.3", - "typescript-eslint": "8.18.2", + "eslint": "9.17.0", "eslint-config-prettier": "9.1.0", "eslint-plugin-astro": "1.3.1", "prettier": "3.4.2", "prettier-plugin-astro": "0.14.1", "tailwindcss": "3.4.17", "typescript": "5.7.2", + "typescript-eslint": "8.18.2", "vercel": "39.2.2" } } diff --git a/public/robots.txt b/public/robots.txt index 7d329b1..7cd709a 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1 +1,4 @@ User-agent: * +Allow: / + +Sitemap: https://cosimomatteini.com/sitemap-index.xml diff --git a/src/layouts/Document.astro b/src/layouts/Document.astro index 293fe7e..9c0683e 100644 --- a/src/layouts/Document.astro +++ b/src/layouts/Document.astro @@ -47,6 +47,7 @@ const keywords = Array.from(metadata.keywords).join(",") +