From ec53d057b9b1af443194e2acd94615079160115c Mon Sep 17 00:00:00 2001 From: Shivam <143623476+myselfshivams@users.noreply.github.com> Date: Sat, 2 Nov 2024 23:32:56 +0530 Subject: [PATCH] added:: Meta Tags, robots.txt, sitemaps for SEO Enhancement --- frontend/generate-sitemap.js | 22 ++++++++++++ frontend/package-lock.json | 66 +++++++++++++++++++++++++++++++++++- frontend/package.json | 2 ++ frontend/public/robots.txt | 4 +++ frontend/public/sitemap.xml | 1 + frontend/src/App.jsx | 2 ++ frontend/src/metadata.jsx | 45 ++++++++++++++++++++++++ 7 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 frontend/generate-sitemap.js create mode 100644 frontend/public/robots.txt create mode 100644 frontend/public/sitemap.xml create mode 100644 frontend/src/metadata.jsx diff --git a/frontend/generate-sitemap.js b/frontend/generate-sitemap.js new file mode 100644 index 0000000..4d40ad2 --- /dev/null +++ b/frontend/generate-sitemap.js @@ -0,0 +1,22 @@ +import { SitemapStream } from 'sitemap'; +import { createWriteStream } from 'fs'; +import path from 'path'; +import { fileURLToPath } from 'url'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const pages = [ + { url: '/', changefreq: 'daily', priority: 1.0 }, + + ]; +async function generateSitemap() { + const writeStream = createWriteStream(path.resolve(__dirname, 'public', 'sitemap.xml')); + const sitemap = new SitemapStream({ hostname: 'https://stationguide.onrender.com/' }); + sitemap.pipe(writeStream).on('finish', () => { + console.log('Sitemap generated successfully'); + }); + pages.forEach(page => sitemap.write(page)); + sitemap.end(); +} +generateSitemap().catch(error => { + console.error('Error generating sitemap:', error); +}); \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3e66b78..2598ea0 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -21,11 +21,13 @@ "react": "^18.3.1", "react-datepicker": "^7.4.0", "react-dom": "^18.3.1", + "react-helmet": "^6.1.0", "react-icons": "^5.3.0", "react-leaflet": "^4.2.1", "react-responsive": "^10.0.0", "react-router-dom": "^6.26.2", "shadcn-ui": "^0.2.3", + "sitemap": "^8.0.0", "socket.io-client": "^4.8.0", "station-saarthi": "file:", "styled-components": "^6.1.13", @@ -2510,6 +2512,14 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/sax": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/@types/sax/-/sax-1.2.7.tgz", + "integrity": "sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/stylis": { "version": "4.2.5", "resolved": "https://registry.npmjs.org/@types/stylis/-/stylis-4.2.5.tgz", @@ -2653,7 +2663,6 @@ "version": "5.0.2", "resolved": "https://registry.npmjs.org/arg/-/arg-5.0.2.tgz", "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", - "dev": true, "license": "MIT" }, "node_modules/argparse": { @@ -6724,6 +6733,25 @@ "react": "^18.3.1" } }, + "node_modules/react-fast-compare": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/react-fast-compare/-/react-fast-compare-3.2.2.tgz", + "integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==" + }, + "node_modules/react-helmet": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/react-helmet/-/react-helmet-6.1.0.tgz", + "integrity": "sha512-4uMzEY9nlDlgxr61NL3XbKRy1hEkXmKNXhjbAIOVw5vcFrsdYbH2FEwcNyWvWinl103nXgzYNlns9ca+8kFiWw==", + "dependencies": { + "object-assign": "^4.1.1", + "prop-types": "^15.7.2", + "react-fast-compare": "^3.1.1", + "react-side-effect": "^2.1.0" + }, + "peerDependencies": { + "react": ">=16.3.0" + } + }, "node_modules/react-icons": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-5.3.0.tgz", @@ -6813,6 +6841,14 @@ "react-dom": ">=16.8" } }, + "node_modules/react-side-effect": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/react-side-effect/-/react-side-effect-2.1.2.tgz", + "integrity": "sha512-PVjOcvVOyIILrYoyGEpDN3vmYNLdy1CajSFNt4TDsVQC5KpTijDvWVoR+/7Rz2xT978D8/ZtFceXxzsPwZEDvw==", + "peerDependencies": { + "react": "^16.3.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -7188,6 +7224,11 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/sax": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" + }, "node_modules/scheduler": { "version": "0.23.2", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", @@ -7342,6 +7383,29 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", "license": "MIT" }, + "node_modules/sitemap": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/sitemap/-/sitemap-8.0.0.tgz", + "integrity": "sha512-+AbdxhM9kJsHtruUF39bwS/B0Fytw6Fr1o4ZAIAEqA6cke2xcoO2GleBw9Zw7nRzILVEgz7zBM5GiTJjie1G9A==", + "dependencies": { + "@types/node": "^17.0.5", + "@types/sax": "^1.2.1", + "arg": "^5.0.0", + "sax": "^1.2.4" + }, + "bin": { + "sitemap": "dist/cli.js" + }, + "engines": { + "node": ">=14.0.0", + "npm": ">=6.0.0" + } + }, + "node_modules/sitemap/node_modules/@types/node": { + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==" + }, "node_modules/socket.io-client": { "version": "4.8.1", "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.8.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 9855490..e61c06d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -24,11 +24,13 @@ "react": "^18.3.1", "react-datepicker": "^7.4.0", "react-dom": "^18.3.1", + "react-helmet": "^6.1.0", "react-icons": "^5.3.0", "react-leaflet": "^4.2.1", "react-responsive": "^10.0.0", "react-router-dom": "^6.26.2", "shadcn-ui": "^0.2.3", + "sitemap": "^8.0.0", "socket.io-client": "^4.8.0", "station-saarthi": "file:", "styled-components": "^6.1.13", diff --git a/frontend/public/robots.txt b/frontend/public/robots.txt new file mode 100644 index 0000000..4521522 --- /dev/null +++ b/frontend/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Disallow: /private +Allow: / +Sitemap: https://stationguide.onrender.com/sitemap.xml \ No newline at end of file diff --git a/frontend/public/sitemap.xml b/frontend/public/sitemap.xml new file mode 100644 index 0000000..bfde5ce --- /dev/null +++ b/frontend/public/sitemap.xml @@ -0,0 +1 @@ +https://stationguide.onrender.com/daily1.0 \ No newline at end of file diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 2593463..b5e4901 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -27,11 +27,13 @@ import Error from "./Pages/Error"; import PrivacyPolicy from "./Pages/PrivacyPolicy"; // Added back from one version import User from "./Pages/User"; // Added from the other version import ComplainBox from "./Pages/ComplainBox"; +import Metadata from "./metadata"; function App() { return ( <> + } /> } /> diff --git a/frontend/src/metadata.jsx b/frontend/src/metadata.jsx new file mode 100644 index 0000000..4d1766c --- /dev/null +++ b/frontend/src/metadata.jsx @@ -0,0 +1,45 @@ +import React from "react"; + +const Metadata = () => { + return ( + <> + + Station Guide - Your Platform Guide + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; + +export default Metadata;