17 lines
931 B
JavaScript
17 lines
931 B
JavaScript
// Signale les pages du site aux moteurs IndexNow (Bing — et donc ChatGPT Search et Copilot —, Yandex, Seznam, Naver).
|
|
// À lancer après chaque déploiement du site : node site-src/indexnow.js
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const { INDEXNOW_KEY, BASE } = require('./seo');
|
|
|
|
const sitemap = fs.readFileSync(path.join(__dirname, '..', 'site', 'sitemap.xml'), 'utf8');
|
|
const urlList = [...sitemap.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]);
|
|
(async () => {
|
|
const res = await fetch('https://api.indexnow.org/indexnow', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
body: JSON.stringify({ host: new URL(BASE).host, key: INDEXNOW_KEY, keyLocation: `${BASE}/${INDEXNOW_KEY}.txt`, urlList }),
|
|
});
|
|
console.log(`IndexNow : ${res.status} ${res.statusText} (${urlList.length} adresses)`);
|
|
if (res.status >= 300) console.log(await res.text());
|
|
})();
|