QR-master/scripts/submit-indexnow.ts

82 lines
2.4 KiB
TypeScript

import { blogPostList } from '../src/lib/blog-data';
import fs from 'fs';
import path from 'path';
const HOST = 'www.qrmaster.net';
const KEY = 'bb6dfaacf1ed41a880281c426c54ed7c';
const KEY_LOCATION = `https://${HOST}/${KEY}.txt`;
const INDEXNOW_ENDPOINT = 'https://api.indexnow.org/indexnow';
async function submitIndexNow() {
console.log('🚀 Starting IndexNow submission...');
// 1. Gather all URLs
const baseUrl = `https://${HOST}`;
const staticPages = [
'',
'/pricing',
'/faq',
'/blog',
'/signup',
'/login',
'/privacy',
'/qr-code-erstellen',
'/qr-code-tracking',
'/dynamic-qr-code-generator',
'/bulk-qr-code-generator',
'/reprint-calculator',
'/newsletter',
];
// Dynamically get tool slugs from directory
const toolsDir = path.join(process.cwd(), 'src/app/(marketing)/tools');
let freeTools: string[] = [];
try {
freeTools = fs.readdirSync(toolsDir).filter(file => {
return fs.statSync(path.join(toolsDir, file)).isDirectory();
});
} catch (e) {
console.warn('⚠️ Could not read tools directory:', e);
}
const toolTypeUrls = freeTools.map(slug => `/tools/${slug}`);
const blogUrls = blogPostList.map(post => `/blog/${post.slug}`);
const allPaths = [...staticPages, ...toolTypeUrls, ...blogUrls];
const urlList = allPaths.map(path => `${baseUrl}${path}`);
console.log(`📝 Found ${urlList.length} URLs to submit.`);
// 2. Prepare payload
const payload = {
host: HOST,
key: KEY,
keyLocation: KEY_LOCATION,
urlList: urlList,
};
try {
// 3. Send Request
const response = await fetch(INDEXNOW_ENDPOINT, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(payload),
});
if (response.status === 200 || response.status === 202) {
console.log('✅ IndexNow submission successful!');
} else {
console.error(`❌ IndexNow submission failed. Status: ${response.status}`);
console.error(await response.text());
}
} catch (error) {
console.error('❌ Error submitting to IndexNow:', error);
}
}
submitIndexNow();