fix: repair AVB parser to correctly detect ## headers and strip markdown artifacts
Some checks failed
🚀 Build & Deploy / 🔍 Prepare (push) Successful in 4s
🚀 Build & Deploy / 🧪 QA (push) Successful in 2m8s
🚀 Build & Deploy / 🏗️ Build (push) Failing after 11m43s
🚀 Build & Deploy / 🚀 Deploy (push) Has been skipped
🚀 Build & Deploy / 🧪 Post-Deploy Verification (push) Has been skipped
🚀 Build & Deploy / 🔔 Notify (push) Successful in 7s

This commit is contained in:
2026-04-22 08:58:36 +02:00
parent 785e36af08
commit 3906838dc1

View File

@@ -6,61 +6,41 @@ export default function AVB() {
const filePath = path.join(process.cwd(), "context/avbs.md"); const filePath = path.join(process.cwd(), "context/avbs.md");
const fileContent = fs.readFileSync(filePath, "utf8"); const fileContent = fs.readFileSync(filePath, "utf8");
// Split by double newlines to get major blocks (headers + their first paragraphs, or subsequent paragraphs) // Split by double newlines to get major blocks
const blocks = fileContent const rawBlocks = fileContent
.split(/\n\s*\n/) .split(/\n\s*\n/)
.map((b) => b.trim()) .map((b) => b.trim())
.filter((b) => b !== ""); .filter((b) => b !== "");
const title = blocks[0] || "Liefer- und Zahlungsbedingungen"; const title = rawBlocks[0]?.replace(/^#\s+/, "") || "Allgemeine Verkaufsbedingungen";
const stand = blocks[1] || "Stand Januar 2026"; const stand = rawBlocks[1] || "Stand: April 2026";
const sections: { title: string; content: string[] }[] = []; const sections: { title: string; content: string[] }[] = [];
let currentSection: { title: string; content: string[] } | null = null; let currentSection: { title: string; content: string[] } | null = null;
// Skip title and stand // Skip title and stand
blocks.slice(2).forEach((block) => { rawBlocks.slice(2).forEach((block) => {
const lines = block if (block.startsWith("##")) {
.split("\n") // New section header: e.g. "## 1. Geltungsbereich"
.map((l) => l.trim())
.filter((l) => l !== "");
if (lines.length === 0) return;
const firstLine = lines[0];
if (/^\d+\./.test(firstLine)) {
// New section
if (currentSection) sections.push(currentSection); if (currentSection) sections.push(currentSection);
currentSection = {
currentSection = { title: firstLine, content: [] }; title: block.replace(/^##\s+/, "").trim(),
content: []
// If there are more lines in this block, they form the first paragraph(s) };
if (lines.length > 1) {
// Join subsequent lines as they might be part of the same paragraph
// In this MD, we'll assume lines in the same block belong together
// unless they are clearly separate paragraphs (but we already split by double newline)
const remainingText = lines.slice(1).join(" ");
if (remainingText) currentSection.content.push(remainingText);
}
} else if (currentSection) { } else if (currentSection) {
// Continuation of current section // Content block: might be multiple paragraphs if not split by double newline,
const blockText = lines.join(" "); // but here each block is one "paragraph" due to our split logic.
if (blockText) currentSection.content.push(blockText); // We clean up bold markers for better display if they are just numbering.
const cleanedBlock = block.replace(/\*\*(.*?)\*\*/g, "$1");
currentSection.content.push(cleanedBlock);
} }
}); });
if (currentSection) sections.push(currentSection); if (currentSection) sections.push(currentSection);
// The last block is the footer // The very last block might be a footer/schlussbestimmung if it's not in a section
const footer = blocks[blocks.length - 1]; // In our MD, everything is in a section, so we just use the last block of the last section as potential footer if we want,
if (sections.length > 0) { // but the current UI expects a separate 'footer' variable.
const lastSection = sections[sections.length - 1]; const footer = "MB Grid Solutions & Services";
if (lastSection.content.includes(footer) || lastSection.title === footer) {
lastSection.content = lastSection.content.filter((c) => c !== footer);
if (sections[sections.length - 1].title === footer) {
sections.pop();
}
}
}
return ( return (
<div className="bg-slate-50 min-h-screen pt-40 pb-20"> <div className="bg-slate-50 min-h-screen pt-40 pb-20">