|
| 1 | +const fs = require('fs').promises; |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +const siteConfig = require('../site-config.json'); |
| 5 | +const projectRoot = path.join(__dirname, '..', 'web'); |
| 6 | +const templatePath = path.join(projectRoot, 'templates', 'category-base.html'); |
| 7 | +const audienceMappingPath = path.join(projectRoot, 'data', 'audience-mapping.json'); |
| 8 | +const toolsIndexPath = path.join(projectRoot, 'data', 'tools-index-unified.json'); |
| 9 | + |
| 10 | +const categories = [ |
| 11 | + { id: 'developers', slug: { es: 'desarrolladores', en: 'developers' }, icon: '💻' }, |
| 12 | + { id: 'designers', slug: { es: 'disenadores', en: 'designers' }, icon: '🎨' }, |
| 13 | + { id: 'writers', slug: { es: 'escritores', en: 'writers' }, icon: '✍️' }, |
| 14 | + { id: 'data-analysts', slug: { es: 'analistas-datos', en: 'data-analysts' }, icon: '📊' }, |
| 15 | + { id: 'marketers', slug: { es: 'marketing', en: 'marketers' }, icon: '📱' }, |
| 16 | + { id: 'productivity', slug: { es: 'productividad', en: 'productivity' }, icon: '⚡' }, |
| 17 | + { id: 'ai-tools', slug: { es: 'ia', en: 'ai' }, icon: '🤖' } |
| 18 | +]; |
| 19 | + |
| 20 | +const categoryNames = { |
| 21 | + developers: { es: 'Desarrolladores', en: 'Developers' }, |
| 22 | + designers: { es: 'Diseñadores', en: 'Designers' }, |
| 23 | + writers: { es: 'Escritores', en: 'Writers' }, |
| 24 | + 'data-analysts': { es: 'Analistas de Datos', en: 'Data Analysts' }, |
| 25 | + marketers: { es: 'Marketing', en: 'Marketers' }, |
| 26 | + productivity: { es: 'Productividad', en: 'Productivity' }, |
| 27 | + 'ai-tools': { es: 'IA', en: 'AI' } |
| 28 | +}; |
| 29 | + |
| 30 | +const categoryDescriptions = { |
| 31 | + developers: { |
| 32 | + es: 'Herramientas esenciales para programadores y desarrolladores web', |
| 33 | + en: 'Essential tools for programmers and web developers' |
| 34 | + }, |
| 35 | + designers: { |
| 36 | + es: 'Herramientas para diseñadores gráficos y creativos', |
| 37 | + en: 'Tools for graphic designers and creatives' |
| 38 | + }, |
| 39 | + writers: { |
| 40 | + es: 'Herramientas para escritores, editores y creadores de contenido', |
| 41 | + en: 'Tools for writers, editors and content creators' |
| 42 | + }, |
| 43 | + 'data-analysts': { |
| 44 | + es: 'Herramientas para análisis y conversión de datos', |
| 45 | + en: 'Tools for data analysis and conversion' |
| 46 | + }, |
| 47 | + marketers: { |
| 48 | + es: 'Herramientas para profesionales del marketing digital', |
| 49 | + en: 'Tools for digital marketing professionals' |
| 50 | + }, |
| 51 | + productivity: { |
| 52 | + es: 'Herramientas para mejorar tu productividad diaria', |
| 53 | + en: 'Tools to improve your daily productivity' |
| 54 | + }, |
| 55 | + 'ai-tools': { |
| 56 | + es: 'Herramientas potenciadas con inteligencia artificial', |
| 57 | + en: 'AI-powered tools' |
| 58 | + } |
| 59 | +}; |
| 60 | + |
| 61 | +async function generateCategoryPages() { |
| 62 | + console.log('🎯 Generando páginas de categorías...\n'); |
| 63 | + |
| 64 | + const template = await fs.readFile(templatePath, 'utf8'); |
| 65 | + const audienceMapping = JSON.parse(await fs.readFile(audienceMappingPath, 'utf8')); |
| 66 | + const toolsData = JSON.parse(await fs.readFile(toolsIndexPath, 'utf8')); |
| 67 | + |
| 68 | + for (const category of categories) { |
| 69 | + const toolIds = audienceMapping[category.id] || []; |
| 70 | + |
| 71 | + for (const lang of siteConfig.languages) { |
| 72 | + const toolsIndexLangPath = path.join(projectRoot, 'data', `tools-index-${lang}.json`); |
| 73 | + const toolsIndex = JSON.parse(await fs.readFile(toolsIndexLangPath, 'utf8')); |
| 74 | + |
| 75 | + const categoryTools = toolsIndex.filter(tool => toolIds.includes(tool.id)); |
| 76 | + |
| 77 | + let toolsGrid = ''; |
| 78 | + categoryTools.forEach(tool => { |
| 79 | + const toolUrl = lang === siteConfig.defaultLanguage ? tool.slug : tool.slug; |
| 80 | + toolsGrid += ` |
| 81 | + <div class="col-md-6 col-lg-4"> |
| 82 | + <div class="card h-100"> |
| 83 | + <div class="card-body"> |
| 84 | + <h5 class="card-title">${tool.icon} ${tool.title}</h5> |
| 85 | + <p class="card-text">${tool.description}</p> |
| 86 | + <a href="${lang === siteConfig.defaultLanguage ? '/' : '/' + lang + '/'}${toolUrl}" class="btn btn-primary">${lang === 'es' ? 'Abrir' : 'Open'}</a> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + </div>`; |
| 90 | + }); |
| 91 | + |
| 92 | + let html = template; |
| 93 | + html = html.replace(/{{lang}}/g, lang); |
| 94 | + html = html.replace(/{{category_name}}/g, categoryNames[category.id][lang]); |
| 95 | + html = html.replace(/{{category_description}}/g, categoryDescriptions[category.id][lang]); |
| 96 | + html = html.replace(/{{category_icon}}/g, category.icon); |
| 97 | + html = html.replace(/{{tools_grid}}/g, toolsGrid); |
| 98 | + html = html.replace(/{{view_all_tools}}/g, lang === 'es' ? 'Ver todas las herramientas' : 'View all tools'); |
| 99 | + html = html.replace(/{{css_path}}/g, lang === siteConfig.defaultLanguage ? '' : '../'); |
| 100 | + html = html.replace(/{{home_path}}/g, lang === siteConfig.defaultLanguage ? '/' : '/' + lang + '/'); |
| 101 | + html = html.replace(/{{hreflang_tags}}/g, ''); |
| 102 | + |
| 103 | + const outputDir = lang === siteConfig.defaultLanguage ? projectRoot : path.join(projectRoot, lang); |
| 104 | + const fileName = `${category.slug[lang]}.html`; |
| 105 | + const outputPath = path.join(outputDir, fileName); |
| 106 | + |
| 107 | + await fs.writeFile(outputPath, html, 'utf8'); |
| 108 | + console.log(`✅ ${lang}/${fileName}`); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + console.log('\n✨ Páginas de categorías generadas!'); |
| 113 | +} |
| 114 | + |
| 115 | +generateCategoryPages().catch(console.error); |
0 commit comments