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.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -27,6 +27,7 @@
|
|||||||
/public/index.prerender.html
|
/public/index.prerender.html
|
||||||
/public/Konfigurator
|
/public/Konfigurator
|
||||||
/public/profile
|
/public/profile
|
||||||
|
/public/404
|
||||||
|
|
||||||
/public/products.xml
|
/public/products.xml
|
||||||
/public/llms*
|
/public/llms*
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ const {
|
|||||||
generateProductsXml,
|
generateProductsXml,
|
||||||
generateLlmsTxt,
|
generateLlmsTxt,
|
||||||
generateCategoryLlmsTxt,
|
generateCategoryLlmsTxt,
|
||||||
|
generateAllCategoryLlmsPages,
|
||||||
} = require("./prerender/seo.cjs");
|
} = require("./prerender/seo.cjs");
|
||||||
const {
|
const {
|
||||||
fetchCategoryProducts,
|
fetchCategoryProducts,
|
||||||
@@ -661,27 +662,39 @@ const renderApp = async (categoryData, socket) => {
|
|||||||
productsByCategory[categoryId].push(product);
|
productsByCategory[categoryId].push(product);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Generate category-specific LLM files
|
// Generate category-specific LLM files with pagination
|
||||||
let categoryFilesGenerated = 0;
|
let categoryFilesGenerated = 0;
|
||||||
let totalCategoryProducts = 0;
|
let totalCategoryProducts = 0;
|
||||||
|
let totalPaginatedFiles = 0;
|
||||||
|
|
||||||
for (const category of allCategories) {
|
for (const category of allCategories) {
|
||||||
if (category.seoName) {
|
if (category.seoName) {
|
||||||
const categoryProducts = productsByCategory[category.id] || [];
|
const categoryProducts = productsByCategory[category.id] || [];
|
||||||
const categorySlug = category.seoName.toLowerCase().replace(/[^a-z0-9]/g, '-');
|
const categorySlug = category.seoName.toLowerCase().replace(/[^a-z0-9]/g, '-');
|
||||||
|
|
||||||
const categoryLlmsTxt = generateCategoryLlmsTxt(category, categoryProducts, shopConfig.baseUrl, shopConfig);
|
// Generate all paginated files for this category
|
||||||
const categoryLlmsTxtPath = path.resolve(__dirname, config.outputDir, `llms-${categorySlug}.txt`);
|
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++;
|
categoryFilesGenerated++;
|
||||||
totalCategoryProducts += categoryProducts.length;
|
totalCategoryProducts += categoryProducts.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(` 📄 Total paginated files generated: ${totalPaginatedFiles}`);
|
||||||
|
console.log(` 📦 Total products across all categories: ${totalCategoryProducts}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const verification = fs.readFileSync(llmsTxtPath, 'utf8');
|
const verification = fs.readFileSync(llmsTxtPath, 'utf8');
|
||||||
console.log(` - File verification: ✅ All files valid UTF-8`);
|
console.log(` - File verification: ✅ All files valid UTF-8`);
|
||||||
|
|||||||
Reference in New Issue
Block a user