diff --git a/.gitignore b/.gitignore index 466bf71..830f59b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ **/.wrangler/ /.idea/ public/sitemap.xml +public/robots.txt .dev.vars secrets.json wrangler.dev.jsonc \ No newline at end of file diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 31a3662..0000000 --- a/public/robots.txt +++ /dev/null @@ -1,7 +0,0 @@ -User-agent: * -Allow: / -Allow: /connect -Disallow: /api -Disallow: /assets - -Sitemap: https://geoff.seemueller.io/sitemap.xml diff --git a/scripts/generate_robots_txt.js b/scripts/generate_robots_txt.js new file mode 100755 index 0000000..f305fc7 --- /dev/null +++ b/scripts/generate_robots_txt.js @@ -0,0 +1,36 @@ +#!/usr/bin/env bun + +import fs from "fs"; +import {parseArgs} from "util"; + + +const {positionals} = parseArgs({ + args: Bun.argv, + options: {}, + strict: true, + allowPositionals: true, +}); + +const currentDate = new Date().toISOString().split("T")[0]; + +const host = positionals[2]; + +const robotsTxtTemplate = ` +User-agent: * +Allow: / +Allow: /connect +Disallow: /api +Disallow: /assets + +Sitemap: https://${host}/sitemap.xml +`; + +const robotsTxtPath = "./public/robots.txt"; + +fs.writeFile(robotsTxtPath, robotsTxtTemplate, (err) => { + if (err) { + console.error("Error writing robots.txt:", err); + process.exit(1); + } + console.log("robots.txt created successfully:", currentDate); +}); diff --git a/scripts/generate_sitemap.js b/scripts/generate_sitemap.js index 9919f66..e5922ea 100755 --- a/scripts/generate_sitemap.js +++ b/scripts/generate_sitemap.js @@ -1,19 +1,30 @@ #!/usr/bin/env bun import fs from "fs"; +import {parseArgs} from "util"; + + +const {positionals} = parseArgs({ + args: Bun.argv, + options: {}, + strict: true, + allowPositionals: true, +}); const currentDate = new Date().toISOString().split("T")[0]; +const host = positionals[2]; + const sitemapTemplate = ` - https://geoff.seemueller.io/ + https://${host}/ ${currentDate} 1.0 - https://geoff.seemueller.io/connect + https://open-gsio.seemueller.workers.dev/connect ${currentDate} 0.7 diff --git a/vite.config.ts b/vite.config.ts index 04cba76..96ab893 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,14 +3,18 @@ import vike from "vike/plugin"; import { defineConfig } from "vite"; import * as child_process from "node:child_process"; +const APP_FQDN = "open-gsio.seemueller.workers.dev"; + export default defineConfig(({ command }) => { const customPlugins = [ { name: "sitemap-generator", buildStart(options) { if (command === "build") { - child_process.execSync("./scripts/generate_sitemap.js"); + child_process.execSync("./scripts/generate_sitemap.js " + APP_FQDN); console.log("Generated Sitemap -> public/sitemap.xml"); + child_process.execSync("./scripts/generate_robots_txt.js " + APP_FQDN); + console.log("Generated robots.txt -> public/robots.txt"); } }, }, @@ -40,6 +44,7 @@ export default defineConfig(({ command }) => { build: { emitAssets: false, sourcemap: false, + minify: true, target: ["es2020", "edge88", "firefox78", "chrome87", "safari13"], rollupOptions: { output: {