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: make us SEO compatible (#745) #790

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# production
/dist
sitemap.xml

# misc
.DS_Store
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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
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',
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