From 7440db59bc11c0c45dc833cd8ba9d837bc34c818 Mon Sep 17 00:00:00 2001
From: Etay Zaslavsky <105246259+EtayZaslavsky@users.noreply.github.com>
Date: Sun, 9 Jun 2024 16:18:24 +0300
Subject: [PATCH 1/3] feat: make us SEO compatible (#745)
---
package.json | 2 +-
public/robots.txt | 3 +-
public/sitemap.xml | 91 ++++++++++++++++++++++++++++++++++++++++++++
sitemap.js | 32 ++++++++++++++++
src/routes/index.tsx | 4 +-
5 files changed, 128 insertions(+), 4 deletions(-)
create mode 100644 public/sitemap.xml
create mode 100644 sitemap.js
diff --git a/package.json b/package.json
index 7f6bca9fb..62de6f1de 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,7 @@
},
"scripts": {
"start": "vite",
- "build": "nx exec -- npm run _build -- ",
+ "build": "nx exec -- npm run _build -- && node sitemap.js",
"serve": "vite preview",
"test": "npm run test:unit:ci && npm run test:e2e",
"test:e2e:ui": "cross-env APPLITOOLS_BATCH_ID=`uuidgen` playwright test --ui",
diff --git a/public/robots.txt b/public/robots.txt
index e9e57dc4d..6f73023ee 100644
--- a/public/robots.txt
+++ b/public/robots.txt
@@ -1,3 +1,4 @@
-# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
+
+Sitemap: https://open-bus-map-search.hasadna.org.il/sitemap.xml
\ No newline at end of file
diff --git a/public/sitemap.xml b/public/sitemap.xml
new file mode 100644
index 000000000..51257c3d8
--- /dev/null
+++ b/public/sitemap.xml
@@ -0,0 +1,91 @@
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.629Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/dashboard
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/timeline
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/gaps
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/gaps_patterns
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/map
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/single-line-map
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/about
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/public-appeal
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/report-a-bug
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
+
+ https://open-bus-map-search.hasadna.org.il/data-research
+ weekly
+ 0.8
+ 2024-06-09T12:59:28.630Z
+
+
+
\ No newline at end of file
diff --git a/sitemap.js b/sitemap.js
new file mode 100644
index 000000000..ee79eda92
--- /dev/null
+++ b/sitemap.js
@@ -0,0 +1,32 @@
+const fs = require("fs");
+const path = require("path");
+
+const sitemap = () => {
+ const app = fs.readFileSync(path.join(__dirname, "/src/routes/index.tsx"), "utf8");
+ const routes = app.match(/'\/[a-z_-]*'/g);
+ const urls = routes.map((route) => {
+ const url = route.slice(1, -1);
+ return url;
+ });
+
+ const sitemap = `
+
+ ${urls
+ .map(
+ (url) => `
+
+ https://open-bus-map-search.hasadna.org.il${url}
+ weekly
+ 0.8
+ ${new Date().toISOString()}
+
+ `
+ )
+ .join("\n")}
+ `;
+ fs.writeFileSync(path.join(__dirname, "/public/sitemap.xml"), sitemap);
+};
+
+sitemap();
+
+// credit https://blog.redsols.us/blog/how-to-create-a-dynamic-sitemap-in-react/
\ No newline at end of file
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
index dcabb28be..5808717b7 100644
--- a/src/routes/index.tsx
+++ b/src/routes/index.tsx
@@ -104,7 +104,7 @@ export const PAGES = [
export const HEADER_LINKS = [
{
label: 'report_a_bug_title',
- path: 'report-a-bug',
+ path: '/report-a-bug',
icon: ,
element: ,
},
@@ -125,7 +125,7 @@ const HIDDEN_PAGES = [
},
] as const
-const getRoutesList = () => {
+export const getRoutesList = () => {
const pages = [...PAGES, ...HIDDEN_PAGES, ...HEADER_LINKS]
const RedirectToHomepage = () =>
const routes = pages.filter((r) => r.element)
From b1c58d7d72c89299d917c319f0fce5feeaa8859d Mon Sep 17 00:00:00 2001
From: Etay Zaslavsky <105246259+EtayZaslavsky@users.noreply.github.com>
Date: Sun, 9 Jun 2024 16:40:55 +0300
Subject: [PATCH 2/3] fix: added eslint ignore from sitemap.xml
---
eslint.config.js | 1 +
1 file changed, 1 insertion(+)
diff --git a/eslint.config.js b/eslint.config.js
index a97aa5019..da5a0f295 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -84,6 +84,7 @@ module.exports = [
'eslint.config.js',
'.nx',
'jest.config.ts',
+ 'sitemap.js',
],
},
]
From c68b46e6d3ded02cd195acafbdc07c2663f7dfd2 Mon Sep 17 00:00:00 2001
From: Etay Zaslavsky <105246259+EtayZaslavsky@users.noreply.github.com>
Date: Sun, 23 Jun 2024 08:45:02 +0300
Subject: [PATCH 3/3] fix: removed sitemap.xml from repo, and added it to
gitignore
---
.gitignore | 1 +
public/sitemap.xml | 91 ----------------------------------------------
2 files changed, 1 insertion(+), 91 deletions(-)
delete mode 100644 public/sitemap.xml
diff --git a/.gitignore b/.gitignore
index 2a59ac9a3..f677308e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@
# production
/dist
+sitemap.xml
# misc
.DS_Store
diff --git a/public/sitemap.xml b/public/sitemap.xml
deleted file mode 100644
index 51257c3d8..000000000
--- a/public/sitemap.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/
- weekly
- 0.8
- 2024-06-09T12:59:28.629Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/dashboard
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/timeline
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/gaps
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/gaps_patterns
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/map
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/single-line-map
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/about
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/public-appeal
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/report-a-bug
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
-
- https://open-bus-map-search.hasadna.org.il/data-research
- weekly
- 0.8
- 2024-06-09T12:59:28.630Z
-
-
-
\ No newline at end of file