From 3e6e763f7e0fdf2e56dbe259f86afd93f803b03b Mon Sep 17 00:00:00 2001 From: Shivam <143623476+myselfshivams@users.noreply.github.com> Date: Sat, 2 Nov 2024 21:54:56 +0530 Subject: [PATCH] added:: Meta Tags, robots.txt, sitemaps for SEO Enhancement --- frontend/generate-sitemap.js | 21 +++++++++++++++++ frontend/package.json | 2 ++ frontend/public/robots.txt | 4 ++++ frontend/public/sitemap.xml | 1 + frontend/src/App.jsx | 2 ++ frontend/src/metadata.jsx | 44 ++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+) 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 00000000..7b73fcd4 --- /dev/null +++ b/frontend/generate-sitemap.js @@ -0,0 +1,21 @@ +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://play-cafe.vercel.app/' }); + 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.json b/frontend/package.json index c0c4b9c0..4dd6d3d5 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -28,12 +28,14 @@ "lucide-react": "^0.454.0", "react": "^18.3.1", "react-dom": "^18.3.1", + "react-helmet": "^6.1.0", "react-icons": "^5.2.1", "react-intersection-observer": "^9.13.0", "react-lazy-load-image-component": "^1.6.2", "react-pageflip": "^2.0.3", "react-responsive": "^10.0.0", "react-router-dom": "^6.24.1", + "sitemap": "^8.0.0", "split-type": "^0.3.4", "tailwind-merge": "^2.5.2", "tailwindcss": "^3.4.4", diff --git a/frontend/public/robots.txt b/frontend/public/robots.txt new file mode 100644 index 00000000..a5502a09 --- /dev/null +++ b/frontend/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Disallow: /private +Allow: / +Sitemap: https://play-cafe.vercel.app/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 00000000..79d07da4 --- /dev/null +++ b/frontend/public/sitemap.xml @@ -0,0 +1 @@ +https://play-cafe.vercel.app/daily1.0 \ No newline at end of file diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 998c1300..defd6b8b 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -5,11 +5,13 @@ import Footer from '../src/components/Shared/Footer'; import { Outlet } from 'react-router-dom'; import BackToTopButton from './components/Shared/BackToTopButton'; import Preloader from './components/Preloader'; +import Metadata from './components/Metadata'; function App() { return ( <> + diff --git a/frontend/src/metadata.jsx b/frontend/src/metadata.jsx new file mode 100644 index 00000000..9c114be2 --- /dev/null +++ b/frontend/src/metadata.jsx @@ -0,0 +1,44 @@ +import React from 'react'; +import { Helmet } from 'react-helmet'; + +const Metadata = () => { + return ( + + Play Cafe - Where Board Games Meet Great Food + + + + + + + + + + {/* Open Graph Tags */} + + + + + + + + {/* Twitter Card Tags */} + + + + + + + + + + + + + + + + ); +}; + +export default Metadata;