From 9ba89a8649d4553472917104ad22e9cbe8552400 Mon Sep 17 00:00:00 2001
From: Rishaan Desai <77017806+Blackhole1123@users.noreply.github.com>
Date: Mon, 26 Sep 2022 12:23:44 -0700
Subject: [PATCH] Added Sitemap Generator"
---
package.json | 11 +++++++--
public/sitemap.xml | 2 ++
scripts/generate-sitemap.mjs | 47 ++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 2 deletions(-)
create mode 100644 public/sitemap.xml
create mode 100644 scripts/generate-sitemap.mjs
diff --git a/package.json b/package.json
index 27b47bd..a72d013 100644
--- a/package.json
+++ b/package.json
@@ -4,12 +4,19 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
- "lint": "next lint"
+ "lint": "next lint",
+ "postbuild": "NODE_OPTIONS='--experimental-json-modules' node ./scripts/generate-sitemap.mjs"
},
"dependencies": {
"next": "12.1.0",
+ "prop-types": "^15.8.1",
"react": "17.0.2",
- "react-dom": "17.0.2"
+ "react-dom": "17.0.2",
+ "react-feather": "^2.0.10",
+ "react-parallax": "^3.5.1",
+ "styled-components": "^5.3.5",
+ "prettier": "^2.5.1",
+ "globby": "13.1.2"
},
"devDependencies": {
"eslint": "8.9.0",
diff --git a/public/sitemap.xml b/public/sitemap.xml
new file mode 100644
index 0000000..74f553f
--- /dev/null
+++ b/public/sitemap.xml
@@ -0,0 +1,2 @@
+
+
diff --git a/scripts/generate-sitemap.mjs b/scripts/generate-sitemap.mjs
new file mode 100644
index 0000000..c253042
--- /dev/null
+++ b/scripts/generate-sitemap.mjs
@@ -0,0 +1,47 @@
+import { writeFileSync } from 'fs'
+
+import { globby } from 'globby'
+import prettier from 'prettier'
+
+async function generate() {
+ const prettierConfig = await prettier.resolveConfig('./.prettierrc.js')
+ const pages = await globby([
+ 'pages/*.tsx',
+ 'data/**/*.mdx',
+ '!data/*.mdx',
+ '!pages/_*.tsx',
+ '!pages/api',
+ '!pages/404.tsx',
+ ])
+
+ const sitemap = `
+
+
+ ${pages
+ .map(page => {
+ const path = page
+ .replace('pages', '')
+ .replace('data', '')
+ .replace('.tsx', '')
+ .replace('.mdx', '')
+ const route = path === '/index' ? '' : path
+ return `
+
+ ${`https://cretu.dev${route}`}
+
+ `
+ })
+ .join('')}
+
+ `
+
+ const formatted = prettier.format(sitemap, {
+ ...prettierConfig,
+ parser: 'html',
+ })
+
+ // eslint-disable-next-line no-sync
+ writeFileSync('public/sitemap.xml', formatted)
+}
+
+generate()