diff --git a/.gitignore b/.gitignore
index 2a59ac9a..f677308e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@
# production
/dist
+sitemap.xml
# misc
.DS_Store
diff --git a/eslint.config.js b/eslint.config.js
index 6119a8ee..c6f065fc 100644
--- a/eslint.config.js
+++ b/eslint.config.js
@@ -85,6 +85,7 @@ module.exports = [
'eslint.config.js',
'.nx',
'jest.config.ts',
+ 'sitemap.js',
],
},
]
diff --git a/package.json b/package.json
index ce47d2a7..3604b15e 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 e9e57dc4..6f73023e 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/sitemap.js b/sitemap.js
new file mode 100644
index 00000000..ee79eda9
--- /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 f0596ea3..48ccd120 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)