Skip to content

Commit

Permalink
feat: make us SEO compatible (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
EtayZaslavsky committed Jun 9, 2024
1 parent 4e58b09 commit 7440db5
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion public/robots.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

Sitemap: https://open-bus-map-search.hasadna.org.il/sitemap.xml
91 changes: 91 additions & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

<url>
<loc>https://open-bus-map-search.hasadna.org.il/</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.629Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/dashboard</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/timeline</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/gaps</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/gaps_patterns</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/map</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/single-line-map</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/about</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/public-appeal</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/report-a-bug</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>


<url>
<loc>https://open-bus-map-search.hasadna.org.il/data-research</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>2024-06-09T12:59:28.630Z</lastmod>
</url>

</urlset>
32 changes: 32 additions & 0 deletions sitemap.js
Original file line number Diff line number Diff line change
@@ -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 = `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${urls
.map(
(url) => `
<url>
<loc>https://open-bus-map-search.hasadna.org.il${url}</loc>
<changefreq>weekly</changefreq>
<priority>0.8</priority>
<lastmod>${new Date().toISOString()}</lastmod>
</url>
`
)
.join("\n")}
</urlset>`;
fs.writeFileSync(path.join(__dirname, "/public/sitemap.xml"), sitemap);
};

sitemap();

// credit https://blog.redsols.us/blog/how-to-create-a-dynamic-sitemap-in-react/
4 changes: 2 additions & 2 deletions src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: <BugOutlined />,
element: <BugReportForm />,
},
Expand All @@ -125,7 +125,7 @@ const HIDDEN_PAGES = [
},
] as const

const getRoutesList = () => {
export const getRoutesList = () => {
const pages = [...PAGES, ...HIDDEN_PAGES, ...HEADER_LINKS]
const RedirectToHomepage = () => <Navigate to={pages[0].path} replace />
const routes = pages.filter((r) => r.element)
Expand Down

0 comments on commit 7440db5

Please sign in to comment.