// scripts/ci/ping-indexnow.mjs // 사이트 배포 뒤 IndexNow(Bing·네이버·Yandex 등 공유)에 바뀐 주소를 알린다. 계정이 필요 없고, // 소유 확인은 사이트 루트의 키 파일(site/public/.txt)로 한다. 주소 목록은 prerender 가 만든 // site/dist/indexnow-urls.json(sitemap 과 같은 목록)이다. import { readdirSync, readFileSync } from 'node:fs' import { join } from 'node:path' const HOST = 'd3ro.chanpaca.net' const publicDir = join(process.cwd(), 'site', 'public') const keyFile = readdirSync(publicDir).find((name) => /^[0-9a-f]{32}\.txt$/.test(name)) if (!keyFile) throw new Error('indexnow: site/public/<32 hex>.txt 키 파일이 없다') const key = readFileSync(join(publicDir, keyFile), 'utf8').trim() const urlList = JSON.parse(readFileSync(join(process.cwd(), 'site', 'dist', 'indexnow-urls.json'), 'utf8')) const response = await fetch('https://api.indexnow.org/indexnow', { method: 'POST', headers: { 'content-type': 'application/json; charset=utf-8' }, body: JSON.stringify({ host: HOST, key, keyLocation: `https://${HOST}/${keyFile}`, urlList }), }) // 200/202 = 접수. 429 등은 배포 실패로 보지 않고 경고만 남긴다. console.log(`[indexnow] ${response.status} ${response.statusText} (${urlList.length} urls)`) if (response.status >= 400 && response.status !== 429) process.exitCode = 1