/
opt
/
canhelp
/
scripts
/
/opt/canhelp/scripts
mkdir
upload
Name
Size
Mode
Actions
backup.sh
3132
0755
edit
dl
rm
deploy-no-install.sh
4130
0755
edit
dl
rm
deploy.sh
4948
0755
edit
dl
rm
health-check.sh
2805
0755
edit
dl
rm
install.sh
2650
0755
edit
dl
rm
restart.sh
1478
0755
edit
dl
rm
submit-sitemap.mjs
1854
0644
edit
dl
rm
Edit:
/opt/canhelp/scripts/submit-sitemap.mjs
(1854B)
#!/usr/bin/env node const sitemapUrl = process.env.SITEMAP_URL || 'https://canhelp.gr/sitemap.xml' const gscSite = process.env.GSC_SITE || '' const gscToken = process.env.GSC_ACCESS_TOKEN || '' const pingBing = (process.env.PING_BING || '1') !== '0' async function ping(url, options = {}) { const res = await fetch(url, options) const text = await res.text().catch(() => '') return { ok: res.ok, status: res.status, text } } async function submitToGoogleSearchConsole() { if (!gscSite || !gscToken) { console.log('[sitemap] Google Search Console submit skipped: set GSC_SITE and GSC_ACCESS_TOKEN') return { skipped: true } } const endpoint = `https://www.googleapis.com/webmasters/v3/sites/${encodeURIComponent(gscSite)}/sitemaps/${encodeURIComponent(sitemapUrl)}` const result = await ping(endpoint, { method: 'PUT', headers: { Authorization: `Bearer ${gscToken}`, }, }) if (!result.ok) { throw new Error(`Google Search Console submit failed (${result.status}): ${result.text.slice(0, 500)}`) } console.log('[sitemap] Google Search Console submit: OK') return { skipped: false } } async function pingBingSitemap() { if (!pingBing) { console.log('[sitemap] Bing ping skipped (PING_BING=0)') return } const endpoint = `https://www.bing.com/ping?sitemap=${encodeURIComponent(sitemapUrl)}` const result = await ping(endpoint) if (!result.ok) { console.warn( `[sitemap] Bing ping skipped (${result.status}). Endpoint may be deprecated.`, ) return } console.log('[sitemap] Bing ping: OK') } async function main() { console.log(`[sitemap] URL: ${sitemapUrl}`) await pingBingSitemap() await submitToGoogleSearchConsole() console.log('[sitemap] Done') } main().catch((err) => { console.error('[sitemap] Error:', err.message) process.exit(1) })
Save
cmd:
run