Claude Code से XML साइटमैप अपने आप बनाएं
Astro और Node में साइटमैप बनाएं: hreflang, lastmod, robots.txt और Search Console जांच सहित।
साइटमैप सार्वजनिक URL की सूची है, इंडेक्सिंग की गारंटी नहीं
जब Claude Code से कई लेख, दस्तावेज़ या उत्पाद पेज बनाए जाते हैं, तो असली समस्या हमेशा पेज टेम्पलेट नहीं होती। अक्सर समस्या यह होती है कि खोज इंजन सही URL खोज पा रहे हैं या नहीं। XML साइटमैप बताता है कि कौन से URL मानक हैं, किस पेज में सच में महत्वपूर्ण बदलाव हुआ है, और अनुवादित पेज आपस में कैसे जुड़े हैं।
यह बात साफ रखनी चाहिए कि साइटमैप कोई जादुई इंडेक्सिंग गारंटी नहीं है। Google की मौजूदा गाइड के अनुसार priority और changefreq को Google इस्तेमाल नहीं करता। lastmod तभी उपयोगी है जब वह लंबे समय तक असली बदलाव से मेल खाता हो। पुराना साइटमैप ping endpoint भी बंद हो चुका है, इसलिए अब https://www.google.com/ping?sitemap=... वाली स्क्रिप्ट की जगह robots.txt, Google Search Console और प्रकाशन के बाद की जांच का उपयोग करें।
इस लेख में दो व्यावहारिक तरीके हैं: Astro की आधिकारिक साइटमैप integration और Node.js से बना ऐसा जनरेटर जो किसी बाहरी पैकेज पर निर्भर नहीं है। पूरी SEO प्रक्रिया सुधारनी हो तो Claude Code SEO सुधार और Claude Code CI/CD सेटअप भी देखें।
पहले आधिकारिक नियम तय करें
| विषय | व्यवहारिक निर्णय |
|---|---|
| URL | https://example.com/blog/post/ जैसे पूरे URL लिखें |
| सीमा | एक फाइल में 50,000 URL या 50 MB बिना संपीड़न तक रखें |
| एन्कोडिंग | UTF-8 इस्तेमाल करें और XML मानों को escape करें |
lastmod | केवल असली महत्वपूर्ण बदलाव की तारीख लिखें |
priority / changefreq | Google के लिए इन्हें छोड़ सकते हैं |
| बहुभाषी पेज | हर URL अपने आप को और सभी भाषा विकल्पों को सूचीबद्ध करे |
| जमा करना | robots.txt और Search Console इस्तेमाल करें, ping स्क्रिप्ट नहीं |
मुख्य संदर्भ हैं Google साइटमैप गाइड, Google ping बंद होने की सूचना, स्थानीय संस्करण गाइड, और sitemaps.org protocol।
उपयोग उदाहरण 1: Astro पेज और ब्लॉग मार्ग
यदि साइट Astro पर स्थिर build होती है, तो पहले @astrojs/sitemap आज़माएं। यह astro build के दौरान साइटमैप बनाता है और मार्ग संरचना साफ हो तो भाषा संबंध भी जोड़ सकता है।
npx astro add sitemap
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://claudecodelab.com',
integrations: [
sitemap({
filter: (page) => !page.includes('/draft/') && !page.includes('/preview/'),
i18n: {
defaultLocale: 'ja',
locales: {
ja: 'ja',
en: 'en',
zh: 'zh-CN',
ko: 'ko',
es: 'es',
fr: 'fr',
de: 'de',
pt: 'pt-BR',
hi: 'hi',
id: 'id',
},
},
}),
],
});
यहां सबसे सामान्य गलती site को गलत छोड़ना है। localhost, पूर्वावलोकन domain, या http और https का मिश्रण साइटमैप में नहीं होना चाहिए। Google साइटमैप में लिखे URL को उसी तरह crawl करने की कोशिश करता है, इसलिए वे आपके मानक URL से मेल खाने चाहिए।
उपयोग उदाहरण 2: Node.js से बहुभाषी MDX साइटमैप
जब सामग्री blog, blog-en, blog-zh जैसी collections में हो, या updatedDate को सही lastmod बनाना हो, तो अपना जनरेटर बेहतर रहता है। नीचे वाली स्क्रिप्ट केवल Node.js के अंतर्निहित module इस्तेमाल करती है और public/sitemap.xml लिखती है।
// scripts/generate-sitemap.mjs
import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
import path from 'node:path';
const SITE_URL = (process.env.SITE_URL ?? 'https://example.com').replace(/\/$/, '');
const OUT_DIR = 'public';
const OUT_FILE = path.join(OUT_DIR, 'sitemap.xml');
const collections = [
{ dir: 'site/src/content/blog', prefix: '/blog', hreflang: 'ja' },
{ dir: 'site/src/content/blog-en', prefix: '/en/blog', hreflang: 'en' },
{ dir: 'site/src/content/blog-zh', prefix: '/zh/blog', hreflang: 'zh-CN' },
{ dir: 'site/src/content/blog-ko', prefix: '/ko/blog', hreflang: 'ko' },
{ dir: 'site/src/content/blog-es', prefix: '/es/blog', hreflang: 'es' },
{ dir: 'site/src/content/blog-fr', prefix: '/fr/blog', hreflang: 'fr' },
{ dir: 'site/src/content/blog-de', prefix: '/de/blog', hreflang: 'de' },
{ dir: 'site/src/content/blog-pt', prefix: '/pt/blog', hreflang: 'pt-BR' },
{ dir: 'site/src/content/blog-hi', prefix: '/hi/blog', hreflang: 'hi' },
{ dir: 'site/src/content/blog-id', prefix: '/id/blog', hreflang: 'id' },
];
function escapeXml(value) {
return String(value).replace(/[<>&'"]/g, (char) => ({
'<': '<',
'>': '>',
'&': '&',
"'": ''',
'"': '"',
})[char]);
}
async function* walk(dir) {
let items;
try {
items = await readdir(dir, { withFileTypes: true });
} catch (error) {
if (error.code === 'ENOENT') return;
throw error;
}
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory()) {
yield* walk(fullPath);
} else if (/\.(md|mdx)$/.test(item.name)) {
yield fullPath;
}
}
}
function frontmatterOf(source) {
return source.match(/^---\n([\s\S]*?)\n---/)?.[1] ?? '';
}
function dateField(frontmatter, key) {
return frontmatter.match(new RegExp(`^${key}:\\s*["']?(\\d{4}-\\d{2}-\\d{2})`, 'm'))?.[1];
}
function routeSlug(collectionDir, filePath) {
return path
.relative(collectionDir, filePath)
.replace(/\\/g, '/')
.replace(/\.(md|mdx)$/, '')
.replace(/\/index$/, '');
}
function encodeRoute(slug) {
return slug.split('/').map(encodeURIComponent).join('/');
}
async function collectEntries() {
const bySlug = new Map();
for (const collection of collections) {
for await (const filePath of walk(collection.dir)) {
const source = await readFile(filePath, 'utf8');
const frontmatter = frontmatterOf(source);
if (/^draft:\s*true\s*$/m.test(frontmatter)) continue;
const info = await stat(filePath);
const slug = routeSlug(collection.dir, filePath);
const lastmod =
dateField(frontmatter, 'updatedDate') ??
dateField(frontmatter, 'pubDate') ??
info.mtime.toISOString().slice(0, 10);
const route = `${collection.prefix}/${encodeRoute(slug)}/`;
const variant = {
loc: `${SITE_URL}${route}`,
hreflang: collection.hreflang,
lastmod,
};
const variants = bySlug.get(slug) ?? [];
variants.push(variant);
bySlug.set(slug, variants);
}
}
return [...bySlug.values()].flatMap((variants) =>
variants.map((variant) => ({
...variant,
alternates: variants.map(({ hreflang, loc }) => ({ hreflang, loc })),
})),
);
}
function buildSitemap(entries) {
const urls = entries.map((entry) => ` <url>
<loc>${escapeXml(entry.loc)}</loc>
<lastmod>${entry.lastmod}</lastmod>
${entry.alternates.map((alt) => ` <xhtml:link rel="alternate" hreflang="${escapeXml(alt.hreflang)}" href="${escapeXml(alt.loc)}" />`).join('\n')}
</url>`).join('\n');
return `<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
${urls}
</urlset>
`;
}
const entries = await collectEntries();
if (entries.length === 0) {
throw new Error('sitemap के लिए कोई public URL नहीं मिला।');
}
await mkdir(OUT_DIR, { recursive: true });
await writeFile(OUT_FILE, buildSitemap(entries), 'utf8');
console.log(`${OUT_FILE} में ${entries.length} URL लिखे गए।`);
चलाने का तरीका:
SITE_URL=https://claudecodelab.com node scripts/generate-sitemap.mjs
उपयोग उदाहरण 3: लेख, उत्पाद और दस्तावेज़ अलग रखें
छोटे blog के लिए एक sitemap.xml काफी हो सकता है। बड़ी साइट में लेख, static pages, products और documentation को अलग फाइलों में रखना बेहतर है। इससे official limit से बचना आसान होता है और Search Console में समस्या पहचानना भी तेज होता है।
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://example.com/sitemap-pages.xml</loc>
<lastmod>2026-06-03</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-blog.xml</loc>
<lastmod>2026-06-03</lastmod>
</sitemap>
<sitemap>
<loc>https://example.com/sitemap-products.xml</loc>
<lastmod>2026-06-03</lastmod>
</sitemap>
</sitemapindex>
Claude Code को साफ कहें कि हर फाइल की URL गिनती लॉग करे, 50,000 URL से पहले खंड बनाए, और sitemap index में उसी साइट की साइटमैप फाइलें डाले।
robots.txt, Search Console और verification
सार्वजनिक साइट के robots.txt में sitemap लिखें:
User-agent: *
Allow: /
Sitemap: https://claudecodelab.com/sitemap.xml
इसके बाद Google Search Console में sitemap URL एक बार जमा करें। प्रकाशन के बाद यह भी जांचें कि सार्वजनिक URL HTTP 200 देता है और XML root urlset या sitemapindex है।
// scripts/verify-sitemap.mjs
const sitemapUrl = process.env.SITEMAP_URL ?? 'https://example.com/sitemap.xml';
const response = await fetch(sitemapUrl);
if (!response.ok) {
throw new Error(`sitemap request असफल: HTTP ${response.status}`);
}
const xml = await response.text();
if (!xml.includes('<urlset') && !xml.includes('<sitemapindex')) {
throw new Error('response sitemap XML जैसा नहीं दिखता।');
}
console.log(`${sitemapUrl} जांचा गया। size: ${xml.length} bytes`);
प्रकाशित करने से पहले पकड़ने वाली गलतियां
पहली गलती है हर lastmod को build date बना देना। यदि पेज में वास्तविक बदलाव नहीं हुआ, तो तारीख भी नहीं बदलनी चाहिए।
दूसरी गलती है draft, noindex पेज, redirect source या duplicate URL शामिल करना। Sitemap में वही canonical URL होने चाहिए जिन्हें आप search result में दिखाना चाहते हैं।
तीसरी गलती है hreflang को एक दिशा में छोड़ देना। हर भाषा संस्करण को अपने आप और बाकी सभी भाषा संस्करणों को सूचीबद्ध करना चाहिए।
चौथी गलती XML escaping भूलना है। Query string में & हो तो XML में & लिखना होगा।
कमाई और असली जांच का परिणाम
साइटमैप अकेले आय नहीं बढ़ाता, लेकिन ट्यूटोरियल, तुलना पेज, मुफ्त संसाधन और परामर्श पेज जैसे मूल्यवान पेजों की खोज को मजबूत करता है। साइटमैप सुधारने के बाद आंतरिक लिंक और CTA भी देखें ताकि पाठक स्वाभाविक रूप से Claude Code प्रशिक्षण या संबंधित संसाधनों तक पहुंच सकें।
Masa ने ClaudeCodeLab प्रक्रिया में यह तरीका आजमाया तो सबसे उपयोगी बदलाव तीन थे: पुराना ping code हटाना, lastmod को updatedDate से मिलाना, और 10 भाषा संस्करणों को परस्पर hreflang से जोड़ना। इससे संपादक MDX frontmatter देखकर जान सकता था कि कौन सा भाषा संस्करण अपडेट हुआ है, और Search Console में जांच भी ज्यादा साफ हो गई।
मुफ़्त PDF: Claude Code cheatsheet
Email डालें और commands, review habits तथा safe workflow वाली एक-page PDF पाएँ.
हम आपका data सुरक्षित रखते हैं और spam नहीं भेजते.
लेखक के बारे में
Masa
Claude Code workflow और team adoption पर काम करने वाला engineer.
संबंधित लेख
Claude Code Obsidian to CLAUDE.md workflow: context बार-बार न समझाएं
Obsidian notes को CLAUDE.md operating notes में बदलकर Claude Code sessions को resume करना आसान बनाएं.
Claude Code Revenue CTA Routing: article से PDF, Gumroad और consultation तक
Reader intent के आधार पर free PDF, Gumroad products और consultation तक CTA route करने वाला workflow.
Claude Code टीम हैंडऑफ नियम: review proof, permissions, rollback और revenue path
Claude Code टीम काम के लिए evidence, permission rules, rollback, free PDF, Gumroad और consultation path वाला handoff.