From d94cc52bcd989a3ae600f4b88bb680b7663c6a4b Mon Sep 17 00:00:00 2001 From: xEsiah Date: Wed, 25 Mar 2026 20:58:12 +0100 Subject: [PATCH] Improving SEO --- public/robots.txt | 4 +++ public/sitemap.xml | 23 +++++++++++++ src/components/SEO.tsx | 74 ++++++++++++++++++++++++++++++++++++++++++ src/pages/About.tsx | 6 ++++ src/pages/Events.tsx | 6 ++++ src/pages/Historic.tsx | 6 ++++ src/pages/Home.tsx | 6 ++++ 7 files changed, 125 insertions(+) create mode 100644 public/robots.txt create mode 100644 public/sitemap.xml create mode 100644 src/components/SEO.tsx diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..07ba841 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,4 @@ +User-agent: * +Allow: / + +Sitemap: https://coeur-ua-pam.fr/sitemap.xml \ No newline at end of file diff --git a/public/sitemap.xml b/public/sitemap.xml new file mode 100644 index 0000000..3d8bc26 --- /dev/null +++ b/public/sitemap.xml @@ -0,0 +1,23 @@ + + + + https://coeur-ua-pam.fr/ + 2025-03-25 + 1.0 + + + https://coeur-ua-pam.fr/a-propos + 2025-03-25 + 0.8 + + + https://coeur-ua-pam.fr/notre-histoire + 2025-03-25 + 0.8 + + + https://coeur-ua-pam.fr/evenements + 2025-03-25 + 0.8 + + \ No newline at end of file diff --git a/src/components/SEO.tsx b/src/components/SEO.tsx new file mode 100644 index 0000000..bce5f08 --- /dev/null +++ b/src/components/SEO.tsx @@ -0,0 +1,74 @@ +import { useEffect } from "react"; + +interface SEOProps { + title: string; + description: string; + type?: string; + image?: string; + url?: string; +} + +export default function SEO({ + title, + description, + type = "website", + image = "/logo.png", + url, +}: SEOProps) { + useEffect(() => { + const siteName = "Cœur UA PAM"; + const fullTitle = `${title} | ${siteName}`; + + // Mise à jour du titre de l'onglet + document.title = fullTitle; + + // Utilitaire pour mettre à jour ou créer des balises meta + const setMeta = (name: string, content: string, isProperty = false) => { + const selector = isProperty + ? `meta[property="${name}"]` + : `meta[name="${name}"]`; + let element = document.querySelector(selector); + if (!element) { + element = document.createElement("meta"); + if (isProperty) element.setAttribute("property", name); + else element.setAttribute("name", name); + document.head.appendChild(element); + } + element.setAttribute("content", content); + }; + + const origin = window.location.origin; + const absoluteImage = image.startsWith("http") + ? image + : `${origin}${image}`; + const absoluteUrl = url ? `${origin}${url}` : window.location.href; + + // Balises standards + setMeta("description", description); + + // Open Graph (Facebook, LinkedIn, etc.) + setMeta("og:title", fullTitle, true); + setMeta("og:description", description, true); + setMeta("og:type", type, true); + setMeta("og:url", absoluteUrl, true); + setMeta("og:image", absoluteImage, true); + setMeta("og:site_name", siteName, true); + + // Twitter + setMeta("twitter:card", "summary_large_image"); + setMeta("twitter:title", fullTitle); + setMeta("twitter:description", description); + setMeta("twitter:image", absoluteImage); + + // Lien canonique + let canonical = document.querySelector('link[rel="canonical"]'); + if (!canonical) { + canonical = document.createElement("link"); + canonical.setAttribute("rel", "canonical"); + document.head.appendChild(canonical); + } + canonical.setAttribute("href", absoluteUrl); + }, [title, description, type, image, url]); + + return null; +} diff --git a/src/pages/About.tsx b/src/pages/About.tsx index b82e947..d539659 100644 --- a/src/pages/About.tsx +++ b/src/pages/About.tsx @@ -1,8 +1,14 @@ import AnimatedContent from "../components/AnimatedContent"; +import SEO from "../components/SEO"; const About = () => { return (
+
+
{ return (
+
{ return (
+