seo(evenements): 301 de la copie aep…/evenements/* vers event., une seule source SEO (B28, B29)
B28 — redirection(host, path, search) : hors event. et hors local, /evenements/<reste> part en 301 vers https://event.trans-former.fr/<reste>, requête gardée. Le middleware lit l'hôte par getRequestHost(event, { xForwardedHost: true }). En local (localhost, 127.0.0.1, ::1, *.localhost : estHoteLocal), la copie reste servie avec son noindex ; la branche robots() est gardée pour ce cas et pour un hôte imprévu. URL mortes : inchangées (relatives). B29 — utils/seo.ts exporte sousPrefixe(path, prefixe) et cheminEvent ; utils/evenements.ts les importe (cheminPublic et le sousPrefixe à un argument retirés, aucune page ne les importait), estHoteEvenement devient un alias de estHoteEvent, canoniqueEvenement appelle canonique(). CHEMINS_AEP et estCheminEvent retirés : sur event., tout chemin est un chemin d'événement. useEvenement ne pose plus canonique ni robots (le plugin B23 le fait) ; le plugin lit useRequestURL().hostname comme le reste du code Nuxt. Tests : test-seo.mjs 88 purs + 21 HTTP, test-y.mjs 58 purs + 41 HTTP (build), npm run test vert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CWNQoixG8Fp46XKgbTm5u8
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d37448490e
commit
83e642f7a8
+68
-5
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* Test de l'indexation (B23) : canonique, robots, redirections, robots.txt, sitemap.
|
||||
* B28 : 301 de la copie aep.…/evenements/* vers event. ; B29 : utils/evenements.ts lit utils/seo.ts.
|
||||
* Charge le VRAI fichier utils/seo.ts via jiti (même patron que test-echelles-nav.mjs).
|
||||
* Usage : node scripts/test-seo.mjs
|
||||
* node scripts/test-seo.mjs http://localhost:3000 (+ contrôles HTTP sur un serveur lancé)
|
||||
@@ -13,9 +14,10 @@ import { dirname, join } from 'node:path'
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const jiti = createJiti(import.meta.url)
|
||||
|
||||
const { canonique, robots, redirection, robotsTxt, cheminsSitemap, sitemapXml, dateSitemap, entreesFichesSitemap } = await jiti.import(
|
||||
join(__dirname, '..', 'utils', 'seo.ts'),
|
||||
)
|
||||
const seo = await jiti.import(join(__dirname, '..', 'utils', 'seo.ts'))
|
||||
const { canonique, robots, redirection, robotsTxt, cheminsSitemap, sitemapXml, dateSitemap, entreesFichesSitemap,
|
||||
estHoteLocal, sousPrefixe, cheminEvent } = seo
|
||||
const evt = await jiti.import(join(__dirname, '..', 'utils', 'evenements.ts'))
|
||||
|
||||
let echecs = 0
|
||||
function egal(nom, obtenu, attendu) {
|
||||
@@ -46,7 +48,9 @@ const canoniques = [
|
||||
[EVT, '/ruetz', { utm: 'deck' }, `${E}/ruetz`],
|
||||
[EVT, '/', {}, `${E}/`],
|
||||
[EVT, '/evenements/ruetz', {}, `${E}/ruetz`],
|
||||
[EVT, '/agences', {}, `${A}/agences`],
|
||||
// B29 : sur event., tout chemin est un chemin d'événement (app/router.options.ts) ; /agences y répond 404,
|
||||
// la canonique d'une 404 n'est lue par personne : on vérifie seulement qu'elle reste sur event.
|
||||
[EVT, '/agences', {}, `${E}/agences`],
|
||||
['localhost:3000', '/media', { tab: 'projets' }, `${A}/media?tab=projets`],
|
||||
]
|
||||
for (const [h, p, q, att] of canoniques) egal(`canonique ${h}${p} ${JSON.stringify(q)}`, canonique(h, p, q), att)
|
||||
@@ -62,13 +66,42 @@ const robotsCas = [
|
||||
]
|
||||
for (const [h, p, att] of robotsCas) egal(`robots ${h}${p}`, robots(h, p), att)
|
||||
|
||||
// ── Hôte local (B28) ────────────────────────────────────────────
|
||||
const locaux = [
|
||||
['localhost', true], ['localhost:3000', true], ['127.0.0.1', true], ['127.0.0.1:3128', true],
|
||||
['::1', true], ['[::1]', true], ['[::1]:3000', true], ['event.localhost:3000', true], ['LOCALHOST:3000', true],
|
||||
[AEP, false], [EVT, false], ['localhost.trans-former.fr', false], ['monlocalhost', false], ['', false], [undefined, false],
|
||||
]
|
||||
for (const [h, att] of locaux) egal(`hôte local ${JSON.stringify(h)}`, estHoteLocal(h), att)
|
||||
|
||||
// ── Redirections ────────────────────────────────────────────────
|
||||
// B28 : la copie des pages d'événement part vers event., hors event. et hors local
|
||||
const redirsEvt = [
|
||||
[AEP, '/evenements/ruetz/foret', `${E}/ruetz/foret`],
|
||||
[AEP, '/evenements', `${E}/`],
|
||||
[AEP, '/evenements/', `${E}/`],
|
||||
[AEP, '/evenements/ruetz/', `${E}/ruetz`],
|
||||
[EVT, '/ruetz/foret', null],
|
||||
[EVT, '/evenements/ruetz', null], // sur event., ce chemin n'est pas une route : 404 naturel, pas de 301
|
||||
['localhost:3000', '/evenements/ruetz', null],
|
||||
['127.0.0.1:3128', '/evenements/ruetz', null],
|
||||
['event.localhost:3000', '/ruetz', null],
|
||||
[AEP, '/evenementsX', null], // frontière de préfixe
|
||||
['203.0.113.7:3333', '/evenements/ruetz', `${E}/ruetz`], // hôte inconnu (IP nue) : 301 aussi
|
||||
]
|
||||
for (const [h, p, att] of redirsEvt) egal(`301 ${h}${p}`, redirection(h, p), att)
|
||||
egal('301 garde la requête', redirection(AEP, '/evenements/ruetz/foret', '?a=1&utm_source=mail'), `${E}/ruetz/foret?a=1&utm_source=mail`)
|
||||
egal('301 requête sans « ? » : un seul « ? »', redirection(AEP, '/evenements/ruetz', 'a=1'), `${E}/ruetz?a=1`)
|
||||
egal('301 requête vide : pas de « ? »', [redirection(AEP, '/evenements/ruetz', ''), redirection(AEP, '/evenements/ruetz', '?')], [`${E}/ruetz`, `${E}/ruetz`])
|
||||
|
||||
// URL mortes (B23), hôte AEP : relatives, requête retirée comme avant
|
||||
const redirs = [
|
||||
['/pratiques-regeneratives', '/agences'], ['/pratiques-regeneratives/', '/agences'],
|
||||
['/proposer-pratique', '/proposer'], ['/pratique/42', '/agences'],
|
||||
['/proposer', null], ['/chatbot-v2', null], ['/agences', null],
|
||||
]
|
||||
for (const [p, att] of redirs) egal(`301 ${p}`, redirection(p), att)
|
||||
for (const [p, att] of redirs) egal(`301 ${AEP}${p}`, redirection(AEP, p), att)
|
||||
egal('301 URL morte : requête non recopiée', redirection(AEP, '/pratique/42', '?x=1'), '/agences')
|
||||
|
||||
// ── robots.txt ──────────────────────────────────────────────────
|
||||
const txt = robotsTxt(AEP)
|
||||
@@ -97,6 +130,15 @@ egal('fiches sitemap : nocodb → les fiches avec Id', entreesFichesSitemap({ so
|
||||
[{ loc: `${A}/fiche/108`, lastmod: '2026-10-01' }, { loc: `${A}/fiche/7`, lastmod: undefined }])
|
||||
egal('fiches sitemap : réponse absente → aucune', [entreesFichesSitemap(null), entreesFichesSitemap({ source: 'nocodb' })], [[], []])
|
||||
|
||||
// ── B29 : une seule source (utils/evenements.ts lit utils/seo.ts) ───
|
||||
for (const c of ['/', '/ruetz', '/ruetz/codev', '/ruetz/foret']) {
|
||||
egal(`canoniqueEvenement(${c}) = canonique(event., ${c})`, evt.canoniqueEvenement(c), canonique(EVT, c))
|
||||
}
|
||||
egal('estHoteEvenement est estHoteEvent (alias, pas une copie)', evt.estHoteEvenement === seo.estHoteEvent, true)
|
||||
egal('plus de cheminPublic ni de sousPrefixe dans utils/evenements.ts', ['cheminPublic', 'sousPrefixe'].filter(n => n in evt), [])
|
||||
egal('sousPrefixe(path, prefixe)', [sousPrefixe('/evenements', '/evenements'), sousPrefixe('/evenements/r', '/evenements'), sousPrefixe('/evenementsX', '/evenements')], [true, true, false])
|
||||
egal('cheminEvent', [cheminEvent('/evenements/ruetz'), cheminEvent('/evenements'), cheminEvent('/ruetz')], ['/ruetz', '/', '/ruetz'])
|
||||
|
||||
// ── HTTP (optionnel, serveur lancé) ─────────────────────────────
|
||||
const base = process.argv[2]
|
||||
if (base) {
|
||||
@@ -108,6 +150,7 @@ if (base) {
|
||||
egal('HTTP sitemap 200 xml', [r2.status, r2.headers.get('content-type')?.startsWith('application/xml')], [200, true])
|
||||
const locs = [...corps.matchAll(/<loc>([^<]+)<\/loc>/g)].map(m => m[1])
|
||||
egal('HTTP sitemap : ni /rag, ni /signaler, ni /contribuer', locs.filter(l => /\/(rag|signaler|contribuer)$/.test(l)), [])
|
||||
egal('HTTP sitemap aep : aucune URL /evenements', locs.filter(l => l.includes('/evenements')), [])
|
||||
console.log(` (${locs.length} URL, dont ${locs.filter(l => l.includes('/fiche/')).length} fiches)`)
|
||||
for (const [p, cible] of [['/pratiques-regeneratives', '/agences'], ['/proposer-pratique', '/proposer'], ['/pratique/3', '/agences']]) {
|
||||
const r = await get(p)
|
||||
@@ -123,6 +166,26 @@ if (base) {
|
||||
for (const p of ['/signaler', '/ajouter', '/proposer', '/codev']) egal(`HTTP ${p} noindex`, rob(await page(p)), NI)
|
||||
const rApi = await get('/api/stats')
|
||||
egal('HTTP /api/stats X-Robots-Tag', rApi.headers.get('x-robots-tag'), 'noindex')
|
||||
|
||||
// B28 : la copie part en 301 vers event. node:http plutôt que fetch : fetch ignore l'en-tête Host.
|
||||
const { request } = await import('node:http')
|
||||
const brut = (path, headers = {}) => new Promise((resolve, reject) => {
|
||||
const u = new URL(base + path)
|
||||
const req = request({ hostname: u.hostname, port: u.port, path: u.pathname + u.search, headers }, (res) => {
|
||||
res.resume()
|
||||
res.on('end', () => resolve({ status: res.statusCode, location: res.headers.location ?? null }))
|
||||
})
|
||||
req.on('error', reject)
|
||||
req.end()
|
||||
})
|
||||
const hAep = { Host: AEP }
|
||||
egal('HTTP Host aep /evenements/ruetz/foret → 301 event.', await brut('/evenements/ruetz/foret', hAep), { status: 301, location: `${E}/ruetz/foret` })
|
||||
egal('HTTP Host aep, ?a=1 suit la 301', await brut('/evenements/ruetz/foret?a=1', hAep), { status: 301, location: `${E}/ruetz/foret?a=1` })
|
||||
egal('HTTP Host aep /evenements → 301 racine event.', await brut('/evenements', hAep), { status: 301, location: `${E}/` })
|
||||
egal('HTTP X-Forwarded-Host aep (Caddy) → 301 event.', (await get('/evenements/ruetz', { headers: { 'x-forwarded-host': AEP } })).headers.get('location'), `${E}/ruetz`)
|
||||
egal('HTTP sans Host (local) : la copie reste servie', (await brut('/evenements/ruetz/foret')).status, 200)
|
||||
egal('HTTP Host event. /ruetz/foret : 200, pas de 301', await brut('/ruetz/foret', { Host: 'event.localhost:3000' }), { status: 200, location: null })
|
||||
egal('HTTP Host aep : URL morte toujours relative', await brut('/pratique/3', hAep), { status: 301, location: '/agences' })
|
||||
}
|
||||
|
||||
console.log(echecs ? `\n${echecs} échec(s)` : '\nTout est vert.')
|
||||
|
||||
+5
-1
@@ -146,7 +146,7 @@ if (base) {
|
||||
let html = ''
|
||||
res.setEncoding('utf8')
|
||||
res.on('data', (c) => { html += c })
|
||||
res.on('end', () => resolve({ status: res.statusCode, html }))
|
||||
res.on('end', () => resolve({ status: res.statusCode, html, location: res.headers.location ?? null }))
|
||||
})
|
||||
req.on('error', reject)
|
||||
req.end()
|
||||
@@ -157,9 +157,13 @@ if (base) {
|
||||
egal(`HTTP event${chemin} : 200, sans barre, titre`, [r.status, r.html.includes('class="app-header'), r.html.includes(h1)], [200, false, true])
|
||||
egal(`HTTP event${chemin} : canonique, pas de noindex`,
|
||||
[r.html.includes(`<link rel="canonical" href="https://event.trans-former.fr${chemin}">`), r.html.includes('noindex')], [true, false])
|
||||
// En local (hôte localhost), la copie reste servie ; sur l'hôte aep., elle part en 301 vers event. (B28).
|
||||
const a = await get('/evenements' + chemin)
|
||||
egal(`HTTP aep/evenements${chemin} : 200, barre, noindex`,
|
||||
[a.status, a.html.includes('class="app-header'), a.html.includes('content="noindex, follow"')], [200, true, true])
|
||||
const r301 = await get('/evenements' + chemin, 'aep.trans-former.fr')
|
||||
egal(`HTTP Host aep.trans-former.fr /evenements${chemin} : 301 vers event.`,
|
||||
[r301.status, r301.location], [301, `https://event.trans-former.fr${chemin}`])
|
||||
}
|
||||
// B25 : la forêt ne mène ni au codev ni au carrefour ; le lieu mène à Maps ; la frise mène à la forêt.
|
||||
const fo = (await get('/ruetz/foret', EVT)).html
|
||||
|
||||
Reference in New Issue
Block a user