diff --git a/.gitignore b/.gitignore index c87c9b39..32921bc5 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,7 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +# next-sitemap +robots.txt +sitemap.xml diff --git a/next-sitemap.config.js b/next-sitemap.config.js new file mode 100644 index 00000000..339f167c --- /dev/null +++ b/next-sitemap.config.js @@ -0,0 +1,36 @@ +/** @type {import('next-sitemap').IConfig} */ +module.exports = { + siteUrl: 'https://www.enji.dev', + priority: 0.6, + generateRobotsTxt: true, + generateIndexSitemap: false, + transform: async (config, path) => { + const defaultValue = (priority) => { + return { + loc: path, + changefreq: config.changefreq, + priority: priority || config.priority, + lastmod: config.autoLastmod ? new Date().toISOString() : undefined, + alternateRefs: config.alternateRefs ?? [], + }; + }; + + if (path === '/') { + return defaultValue(1.0); + } + + if (path === '/blog') { + return defaultValue(0.9); + } + + if (path === '/projects') { + return defaultValue(0.9); + } + + if (path.indexOf('/work') === 0) { + return defaultValue(0.8); + } + + return defaultValue(); + }, +}; diff --git a/package.json b/package.json index 84687ba2..2da8361b 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "lint": "next lint", "lint:types": "tsc --noEmit", "lint:style": "prettier --check .", - "analyze": "cross-env ANALYZE=true yarn build" + "analyze": "cross-env ANALYZE=true yarn build", + "postbuild": "next-sitemap" }, "dependencies": { "@headlessui/react": "^1.7.4", @@ -56,6 +57,7 @@ "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-simple-import-sort": "^8.0.0", "mini-svg-data-uri": "^1.4.4", + "next-sitemap": "^3.1.42", "postcss": "^8.4.18", "prettier": "^2.7.1", "prettier-plugin-tailwindcss": "^0.1.13", diff --git a/public/robots.txt b/public/robots.txt deleted file mode 100644 index f30ce23d..00000000 --- a/public/robots.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Allow all crawlers -User-agent: * -Allow: / diff --git a/yarn.lock b/yarn.lock index df4b2b91..3bbfca8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17,6 +17,11 @@ dependencies: regenerator-runtime "^0.13.10" +"@corex/deepmerge@^4.0.29": + version "4.0.29" + resolved "https://registry.yarnpkg.com/@corex/deepmerge/-/deepmerge-4.0.29.tgz#af9debf07d7f6b0d2a9d04a266abf2c1418ed2f6" + integrity sha512-q/yVUnqckA8Do+EvAfpy7RLdumnBy9ZsducMUtZTvpdbJC7azEf1hGtnYYxm0QfphYxjwggv6XtH64prvS1W+A== + "@emotion/is-prop-valid@^0.8.2": version "0.8.8" resolved "https://registry.yarnpkg.com/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz#db28b1c4368a259b60a97311d6a952d4fd01ac1a" @@ -2542,7 +2547,7 @@ minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: dependencies: brace-expansion "^1.1.7" -minimist@^1.2.0, minimist@^1.2.6: +minimist@^1.2.0, minimist@^1.2.6, minimist@^1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g== @@ -2587,6 +2592,14 @@ natural-compare@^1.4.0: resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" integrity sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw== +next-sitemap@^3.1.42: + version "3.1.42" + resolved "https://registry.yarnpkg.com/next-sitemap/-/next-sitemap-3.1.42.tgz#f5c20f9a2cb66b75710bd7af4249041a47641af5" + integrity sha512-z/m440ZDCTxoE3FWbBWZLK66ZEh9e2R+j/Bm0d1Vo4PFkMi4yhWdIjWqhj//kyFyBvMYk3YWs8QQqVCCe15E6g== + dependencies: + "@corex/deepmerge" "^4.0.29" + minimist "^1.2.7" + next-themes@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/next-themes/-/next-themes-0.2.1.tgz#0c9f128e847979daf6c67f70b38e6b6567856e45"