fix(sync): normalize section separators in regenerate()
A previous run could merge the '---' separator with the next section
header (---## ✅ Befejezett), breaking section detection. Prefix/suffix
are now trimmed and rejoined with fixed separators. Regression test
added; also create Plane issues for local-only completed work
(MITHOME-28 Custom CMS, MITHOME-29 Webmail) to avoid ID collisions.
This commit is contained in:
@@ -64,7 +64,9 @@ function buildTable(sec, rows) {
|
||||
return [header, separator, ...body].join('\n');
|
||||
}
|
||||
|
||||
// WHY: only the section region is regenerated, prefix/suffix (overview, commands) are preserved
|
||||
// WHY: only the section region is regenerated, prefix/suffix (overview, commands) are preserved.
|
||||
// Prefix/suffix are trimmed and rejoined with normalized separators so that a previous run
|
||||
// that dropped the blank line after `---` cannot corrupt the section headers (`---## ✅`).
|
||||
function regenerate(content, finalSections) {
|
||||
const lines = content.split('\n');
|
||||
const firstIdx = lines.findIndex(l => SECTIONS[0].header.test(l));
|
||||
@@ -79,8 +81,8 @@ function regenerate(content, finalSections) {
|
||||
}
|
||||
}
|
||||
|
||||
const prefix = lines.slice(0, firstIdx).join('\n');
|
||||
const suffix = lines.slice(endIdx + 1).join('\n');
|
||||
const prefix = lines.slice(0, firstIdx).join('\n').trimEnd();
|
||||
const suffix = lines.slice(endIdx + 1).join('\n').trimStart();
|
||||
|
||||
const headerOf = key => {
|
||||
const sec = SECTIONS.find(s => s.key === key);
|
||||
@@ -92,9 +94,8 @@ function regenerate(content, finalSections) {
|
||||
const rows = finalSections[sec.key] || [];
|
||||
return `## ${headerOf(sec.key)}\n\n${buildTable(sec, rows)}`;
|
||||
});
|
||||
const middle = blocks.join('\n\n---\n\n') + '\n\n---\n';
|
||||
|
||||
const result = `${prefix}${middle}${suffix}`;
|
||||
const middle = blocks.join('\n\n---\n\n');
|
||||
const result = `${prefix}\n\n${middle}\n\n---\n\n${suffix}`;
|
||||
return result.endsWith('\n') ? result : `${result}\n`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user