Skip to content

Commit f521299

Browse files
committed
Add llms.txt generation to build process
1 parent 3333e6b commit f521299

File tree

1 file changed

+88
-2
lines changed

1 file changed

+88
-2
lines changed

scripts/build.js

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,87 @@ async function build() {
426426
console.log(' ✅ Generated sitemap-index.xml');
427427
console.log(' ✅ Generated sitemap.xml\n');
428428

429-
// Step 9: Generate robots.txt
429+
// Step 9: Generate llms.txt
430+
async function generateLlmsTxt(articles, users) {
431+
// Count tags
432+
const tagCounts = {};
433+
articles.forEach(article => {
434+
if (article.cached_tag_list) {
435+
const tags = article.cached_tag_list.split(',').map(t => t.trim());
436+
tags.forEach(tag => {
437+
tagCounts[tag] = (tagCounts[tag] || 0) + 1;
438+
});
439+
}
440+
});
441+
442+
// Get top 15 topics
443+
const topTopics = Object.entries(tagCounts)
444+
.sort((a, b) => b[1] - a[1])
445+
.slice(0, 15);
446+
447+
// Count articles by author
448+
const authorCounts = {};
449+
articles.forEach(article => {
450+
const username = article.cached_user_username;
451+
if (username) {
452+
authorCounts[username] = (authorCounts[username] || 0) + 1;
453+
}
454+
});
455+
456+
// Get top 10 authors
457+
const topAuthors = Object.entries(authorCounts)
458+
.sort((a, b) => b[1] - a[1])
459+
.slice(0, 10);
460+
461+
// Get latest 20 articles
462+
const latestArticles = articles
463+
.sort((a, b) => new Date(b.published_at) - new Date(a.published_at))
464+
.slice(0, 20);
465+
466+
// Build llms.txt
467+
let llmsTxt = `# WEB3DEV Portuguese Archive\n\n`;
468+
llmsTxt += `> A comprehensive archive of ${articles.length} Web3 and blockchain articles in Portuguese, covering topics from smart contract development to decentralized finance.\n\n`;
469+
llmsTxt += `This archive preserves high-quality educational content from the WEB3DEV community, featuring tutorials, guides, and technical articles about blockchain technology, Ethereum, Solana, and Web3 development.\n\n`;
470+
471+
llmsTxt += `## Popular Topics\n\n`;
472+
topTopics.forEach(([tag, count]) => {
473+
const descriptions = {
474+
'Blockchain': 'blockchain fundamentals, architecture, and applications',
475+
'Solidity': 'smart contract programming and development',
476+
'Ethereum': 'the Ethereum ecosystem and EVM',
477+
'Web3': 'Web3 technologies and decentralized applications',
478+
'NFT': 'non-fungible tokens and digital collectibles',
479+
'Web3Dev': 'the Web3Dev community',
480+
'DeFi': 'decentralized finance protocols and concepts',
481+
'Solana': 'Solana development and ecosystem',
482+
'Rust': 'Rust programming for blockchain',
483+
'DApp': 'decentralized application development',
484+
'DAO': 'decentralized autonomous organizations',
485+
'Smart Contract': 'smart contract development and security',
486+
'NEAR': 'NEAR Protocol',
487+
'Token': 'tokenomics and token standards',
488+
'EVM': 'Ethereum Virtual Machine'
489+
};
490+
const desc = descriptions[tag] || tag.toLowerCase();
491+
llmsTxt += `- [${tag}](${SITE_URL}): ${count} articles covering ${desc}\n`;
492+
});
493+
494+
llmsTxt += `\n## Top Authors\n\n`;
495+
topAuthors.forEach(([username, count]) => {
496+
llmsTxt += `- [${username}](${SITE_URL}/${username}): ${count} articles\n`;
497+
});
498+
499+
llmsTxt += `\n## Latest Articles\n\n`;
500+
latestArticles.forEach(article => {
501+
const url = `${SITE_URL}/${article.cached_user_username}/${article.slug}`;
502+
const desc = article.description ? article.description.substring(0, 100) : article.title;
503+
llmsTxt += `- [${article.title}](${url}): ${desc}\n`;
504+
});
505+
506+
fs.writeFileSync(path.join(PUBLIC_DIR, 'llms.txt'), llmsTxt);
507+
}
508+
509+
// Step 10: Generate robots.txt
430510
console.log('🤖 Generating robots.txt...');
431511

432512
const robotsTxt = `# Allow all crawlers
@@ -462,14 +542,20 @@ Sitemap: ${SITE_URL}/sitemap-users.xml
462542

463543
console.log(' ✅ Generated robots.txt\n');
464544

545+
// Generate llms.txt
546+
console.log('🤖 Generating llms.txt...');
547+
await generateLlmsTxt(articles, users);
548+
console.log(' ✅ Generated llms.txt\n');
549+
465550
// Summary
466551
console.log('✨ Build complete!\n');
467552
console.log('📊 Summary:');
468553
console.log(` - ${articleCount} article pages`);
469554
console.log(` - ${profileCount} profile pages`);
470555
console.log(` - 1 homepage`);
471556
console.log(` - sitemap.xml with ${articleCount + profileCount + 1} URLs`);
472-
console.log(` - robots.txt\n`);
557+
console.log(` - robots.txt`);
558+
console.log(` - llms.txt\n`);
473559
console.log(`🌐 Run 'npm run serve' to test locally`);
474560
}
475561

0 commit comments

Comments
 (0)