import fs from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const data = JSON.parse(fs.readFileSync(path.join(root, "src/content/site-content.json"), "utf8")); const rating = data.site.aggregateRating; const proof = data.pages.find((page) => page.caseStudyNote)?.caseStudyNote; const ratingText = rating ? `${data.labels.reviewsLabel}: ${rating.ratingValue}/${rating.bestRating} (${rating.reviewCount}); ${data.labels.updated}: ${rating.verifiedAt}. ${rating.source}` : ""; const intro = [`# ${data.site.name}`, "", data.site.description, "", `## ${data.labels.about}`, "", data.site.legalEntity.name, "", ...(proof ? [proof, ""] : []), ...(ratingText ? [ratingText, ""] : []), ...["/chi-siamo", "/prezzi"].flatMap((route) => { const page = data.pages.find((item) => item.path === route); return page ? [page.summary, ""] : []; })]; const pages = data.pages.filter((page) => page.indexable); const url = (page) => data.site.url + (page.path === "/" ? "" : page.path); const index = [...intro, `## ${data.labels.browse}`, "", ...pages.map((page) => `- [${page.h1}](${url(page)}): ${page.summary}${page.caseStudyNote ? " " + page.caseStudyNote : ""}`), "", data.labels.ymyl, ""].join("\n"); const full = [...intro, ...pages.flatMap((page) => [`## ${page.h1}`, "", `URL: ${url(page)}`, "", page.summary, "", ...(page.caseStudyNote ? [page.caseStudyNote, ""] : []), ...page.sections.flatMap((section) => [`### ${section.heading}`, "", section.body, ...(section.items ?? []), ...(section.steps ?? []), ...(section.table ? [section.table.headers.join(" | "), ...section.table.rows.map((row) => row.join(" | "))] : []), ""]), ...page.faq.flatMap((faq) => [`### ${faq.question}`, "", faq.answer, ""])]), data.labels.ymyl, ""].join("\n"); fs.writeFileSync(path.join(root, "public/llms.txt"), index); fs.writeFileSync(path.join(root, "public/llms-full.txt"), full); console.log(`${data.site.code}: generated llms.txt and llms-full.txt`);