Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate sitemap #790

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ module.exports = [
'eslint.config.js',
'.nx',
'jest.config.ts',
'sitemap.js',
],
},
]
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's ignore this file on git, it's autogenerated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's also delete this file

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
NoamGaash marked this conversation as resolved.
Show resolved Hide resolved
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',
NoamGaash marked this conversation as resolved.
Show resolved Hide resolved
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
Loading