From ea5ac762b2586a6dc15c6a7e0ad8572eeea346e1 Mon Sep 17 00:00:00 2001 From: seb Date: Sat, 5 Jul 2025 16:20:00 +0200 Subject: [PATCH] Update .gitignore to exclude 404 page and enhance prerendering logic to support pagination for category-specific LLM files. Implemented `generateAllCategoryLlmsPages` function to create multiple paginated files, improving product catalog clarity and organization. --- .gitignore | 1 + prerender.cjs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 83c1ce0..5bb675e 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,7 @@ /public/index.prerender.html /public/Konfigurator /public/profile +/public/404 /public/products.xml /public/llms* diff --git a/prerender.cjs b/prerender.cjs index 33c0040..a3cc34c 100644 --- a/prerender.cjs +++ b/prerender.cjs @@ -50,6 +50,7 @@ const { generateProductsXml, generateLlmsTxt, generateCategoryLlmsTxt, + generateAllCategoryLlmsPages, } = require("./prerender/seo.cjs"); const { fetchCategoryProducts, @@ -661,27 +662,39 @@ const renderApp = async (categoryData, socket) => { productsByCategory[categoryId].push(product); }); - // Generate category-specific LLM files + // Generate category-specific LLM files with pagination let categoryFilesGenerated = 0; let totalCategoryProducts = 0; + let totalPaginatedFiles = 0; for (const category of allCategories) { if (category.seoName) { const categoryProducts = productsByCategory[category.id] || []; const categorySlug = category.seoName.toLowerCase().replace(/[^a-z0-9]/g, '-'); - const categoryLlmsTxt = generateCategoryLlmsTxt(category, categoryProducts, shopConfig.baseUrl, shopConfig); - const categoryLlmsTxtPath = path.resolve(__dirname, config.outputDir, `llms-${categorySlug}.txt`); + // Generate all paginated files for this category + const categoryPages = generateAllCategoryLlmsPages(category, categoryProducts, shopConfig.baseUrl, shopConfig); - fs.writeFileSync(categoryLlmsTxtPath, categoryLlmsTxt, { encoding: 'utf8' }); + // Write each paginated file + for (const page of categoryPages) { + const pagePath = path.resolve(__dirname, config.outputDir, page.fileName); + fs.writeFileSync(pagePath, page.content, { encoding: 'utf8' }); + totalPaginatedFiles++; + } - console.log(` ✅ llms-${categorySlug}.txt - ${categoryProducts.length} products (${Math.round(categoryLlmsTxt.length / 1024)}KB)`); + const pageCount = categoryPages.length; + const totalSize = categoryPages.reduce((sum, page) => sum + page.content.length, 0); + + console.log(` ✅ llms-${categorySlug}-page-*.txt - ${categoryProducts.length} products across ${pageCount} pages (${Math.round(totalSize / 1024)}KB total)`); categoryFilesGenerated++; totalCategoryProducts += categoryProducts.length; } } + console.log(` 📄 Total paginated files generated: ${totalPaginatedFiles}`); + console.log(` 📦 Total products across all categories: ${totalCategoryProducts}`); + try { const verification = fs.readFileSync(llmsTxtPath, 'utf8'); console.log(` - File verification: ✅ All files valid UTF-8`);