#!/usr/bin/env bash
# Contrôle SEO (MG-070 à MG-072) : title, meta description, canonical, JSON-LD.
B="http://localhost:8080"

for u in / /qui-suis-je /approche /cabinet /visio /ateliers /faq /contact \
         /mentions-legales /politique-confidentialite; do
    page=$(mktemp)
    curl -s "$B$u" > "$page"

    title=$(grep -oE '<title>[^<]*' "$page" | head -1 | sed 's|<title>||')
    desc=$(grep -oE 'name="description" content="[^"]*' "$page" | head -1 | sed 's|.*content="||')
    canon=$(grep -c 'rel="canonical"' "$page")
    ld=$(grep -c 'application/ld+json' "$page")

    printf '%-28s\n' "$u"
    printf '   title (%3d) : %s\n' "${#title}" "$title"
    printf '   desc  (%3d) : %s\n' "${#desc}" "${desc:0:90}"
    printf '   canonical=%s  json-ld=%s\n' "$canon" "$ld"
    rm -f "$page"
done

echo
echo "── robots.txt ──"
curl -s "$B/robots.txt"
echo "── sitemap : nombre d'URL ──"
curl -s "$B/sitemap.xml" | grep -o '<loc>' | wc -l
