From a6a47d28820671f33ea5684e9cc8842a57bbfcbd Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Thu, 21 Oct 2021 10:48:51 -0400 Subject: [PATCH 1/4] generate a sitemap on build --- .gitignore | 5 +++-- next-sitemap.js | 5 +++++ package.json | 2 ++ yarn.lock | 21 +++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 next-sitemap.js diff --git a/.gitignore b/.gitignore index b8737f59..da52ba33 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -# added by mike - don't save public/rss.xml, which is generated only in production -# and will be made dynamically on server at build time +# added by mike - don't save rss.xml or sitemap.xml in the public folder. +# they are generated only in production, and will be made dynamically on server at build time public/rss.xml +public/sitemap.xml .next diff --git a/next-sitemap.js b/next-sitemap.js new file mode 100644 index 00000000..f11fdb3f --- /dev/null +++ b/next-sitemap.js @@ -0,0 +1,5 @@ +module.exports = { + siteUrl: process.env.SITE_URL || 'https://mikebifulco.com', + generateRobotsTxt: process.env.NODE_ENV === 'production', + // ...other options +}; diff --git a/package.json b/package.json index 64762e24..1e43fd11 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "license": "MIT", "scripts": { "build": "next build", + "postbuild": "next-sitemap", "dev": "NODE_OPTIONS='--inspect' next dev", "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"", "start": "next start", @@ -54,6 +55,7 @@ "husky": ">=6", "lint-staged": "^11.2.3", "netlify-plugin-cache-nextjs": "^1.6.1", + "next-sitemap": "^1.6.192", "prettier": "^2.4.1" }, "repository": { diff --git a/yarn.lock b/yarn.lock index 48ff9e5c..f49f068d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -867,6 +867,11 @@ dependencies: "@chakra-ui/utils" "1.8.3" +"@corex/deepmerge@^2.6.34": + version "2.6.34" + resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-2.6.34.tgz#8dd084f2bcc9cf54f6b1210a1aebd25206de2a84" + integrity sha512-5l3bQRGOoCJ1nYTxEaOW/MRuwNDq32KYatWO5rwOlOzxY4beVCrxDBaDBX5wpDn0PYm0QAul/vAC9GDHShEbTw== + "@ctrl/tinycolor@^3.4.0": version "3.4.0" resolved "https://registry.yarnpkg.com/@ctrl/tinycolor/-/tinycolor-3.4.0.tgz#c3c5ae543c897caa9c2a68630bed355be5f9990f" @@ -5188,6 +5193,13 @@ markdown-escapes@^1.0.0: resolved "https://registry.yarnpkg.com/markdown-escapes/-/markdown-escapes-1.0.4.tgz#c95415ef451499d7602b91095f3c8e8975f78535" integrity sha512-8z4efJYk43E0upd0NbVXwgSTQs6cT3T06etieCMEg7dRbzCbxUCK/GHlX8mhHRDcp+OLlHkPKsvqQTCvsRl2cg== +matcher@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/matcher/-/matcher-4.0.0.tgz#a42a05a09aaed92e2d241eb91fddac689461ea51" + integrity sha512-S6x5wmcDmsDRRU/c2dkccDwQPXoFczc5+HpQ2lON8pnvHlnvHAHj5WlLVvw6n6vNyHuVugYrFohYxbS+pvFpKQ== + dependencies: + escape-string-regexp "^4.0.0" + md5.js@^1.3.4: version "1.3.5" resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f" @@ -5687,6 +5699,15 @@ next-mdx-remote@^3.0.6: esbuild "^0.13.4" pkg-dir "^5.0.0" +next-sitemap@^1.6.192: + version "1.6.192" + resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-1.6.192.tgz#2f5c4e4b8ac12e2edcf8d2caffdd3b320b2b47a8" + integrity sha512-Pvxi5ttn/pedojrCvhGrvXsXg0bSV/scWCLrivO1xeBd+OVGiFyn60WHfx7I0HfW7nFQmbvwGfYffkUMOj/ptg== + dependencies: + "@corex/deepmerge" "^2.6.34" + matcher "^4.0.0" + minimist "^1.2.5" + next@^11.1.2: version "11.1.2" resolved "https://registry.yarnpkg.com/next/-/next-11.1.2.tgz#527475787a9a362f1bc916962b0c0655cc05bc91" From 4ae1b14d42e07344ff77cc229eb5a6327361b8ff Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Thu, 21 Oct 2021 11:00:46 -0400 Subject: [PATCH 2/4] hacky postbuild hook? --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1e43fd11..0684299e 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Mike Bifulco ", "license": "MIT", "scripts": { - "build": "next build", + "build": "next build && next-sitemap", "postbuild": "next-sitemap", "dev": "NODE_OPTIONS='--inspect' next dev", "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\"", From 906d94750dd49bed65f77305ad80cae6baa81f31 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Thu, 21 Oct 2021 11:10:20 -0400 Subject: [PATCH 3/4] robots.txt true, netlify always sets build env to prod --- next-sitemap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/next-sitemap.js b/next-sitemap.js index f11fdb3f..a303d61f 100644 --- a/next-sitemap.js +++ b/next-sitemap.js @@ -1,5 +1,5 @@ module.exports = { siteUrl: process.env.SITE_URL || 'https://mikebifulco.com', - generateRobotsTxt: process.env.NODE_ENV === 'production', + generateRobotsTxt: true, // ...other options }; From 9ad1ff01494d06eeeb9050c77162bff3d18bab15 Mon Sep 17 00:00:00 2001 From: Mike Bifulco Date: Sat, 23 Oct 2021 13:38:49 -0400 Subject: [PATCH 4/4] robots.txt generated by next-sitemap --- public/robots.txt | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 public/robots.txt diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index 76f64218..00000000 --- a/public/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Allow all crawlers -User-agent: * -Allow: / \ No newline at end of file