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] 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 7f6bca9f..62de6f1d 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/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 00000000..51257c3d --- /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 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 dcabb28b..5808717b 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)