terms
All checks were successful
Build & Deploy MB Grid Solutions / build-and-deploy (push) Successful in 1m42s
All checks were successful
Build & Deploy MB Grid Solutions / build-and-deploy (push) Successful in 1m42s
This commit is contained in:
@@ -6,34 +6,53 @@ export default function AGB() {
|
||||
const filePath = path.join(process.cwd(), 'context/agbs.md');
|
||||
const fileContent = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
// Simple parsing of the markdown file
|
||||
const lines = fileContent.split('\n').map(l => l.trim()).filter(line => line !== '');
|
||||
// Split by double newlines to get major blocks (headers + their first paragraphs, or subsequent paragraphs)
|
||||
const blocks = fileContent.split(/\n\s*\n/).map(b => b.trim()).filter(b => b !== '');
|
||||
|
||||
const title = lines[0] || 'Liefer- und Zahlungsbedingungen';
|
||||
const stand = lines[1] || 'Stand Januar 2026';
|
||||
const title = blocks[0] || 'Liefer- und Zahlungsbedingungen';
|
||||
const stand = blocks[1] || 'Stand Januar 2026';
|
||||
|
||||
const sections: { title: string; content: string[] }[] = [];
|
||||
let currentSection: { title: string; content: string[] } | null = null;
|
||||
|
||||
// Skip title and stand
|
||||
lines.slice(2).forEach(line => {
|
||||
// Check if line starts with a number followed by a dot (e.g., "1. ", "10. ")
|
||||
if (/^\d+\./.test(line)) {
|
||||
blocks.slice(2).forEach(block => {
|
||||
const lines = block.split('\n').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);
|
||||
currentSection = { title: line, content: [] };
|
||||
|
||||
currentSection = { title: firstLine, 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) {
|
||||
currentSection.content.push(line);
|
||||
// Continuation of current section
|
||||
const blockText = lines.join(' ');
|
||||
if (blockText) currentSection.content.push(blockText);
|
||||
}
|
||||
});
|
||||
if (currentSection) sections.push(currentSection);
|
||||
|
||||
// The last line is usually the location/date
|
||||
const footer = lines[lines.length - 1];
|
||||
// Remove footer from the last section's content if it was added there
|
||||
// The last block is the footer
|
||||
const footer = blocks[blocks.length - 1];
|
||||
if (sections.length > 0) {
|
||||
const lastSection = sections[sections.length - 1];
|
||||
if (lastSection.content.includes(footer)) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user