From 392cb4f8ff21bc9f02bf9115188fa1910f81d95b Mon Sep 17 00:00:00 2001 From: Kurt Overmier Date: Sat, 2 May 2026 11:05:58 -0500 Subject: [PATCH] fix(docs-sync): use awk to extract only first frontmatter block (#19) The sed range pattern '/^---$/,/^---$/p' restarts after termination, capturing every '^---$' pair in the file. Files with markdown HR separators in the body (api-reference.md upstream has 65) had their content doubled on each sync, then re-doubled on the next. Replaced with an awk single-state-machine: increments n on each ---, prints the line, exits at the second ---; in between, prints body lines. Idempotent for files with body HR separators; behavior unchanged for files without (mcp.md, platform.md, etc.). Verified by re-running the sync after the fix: Sync complete: 0 updated, 4 unchanged, 0 failed api-reference.md stays at 1861 lines (was doubling to 2906 with the sed pattern). Closes #19. Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/docs-sync.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/docs-sync.sh b/scripts/docs-sync.sh index 9638ba0..076e9b3 100644 --- a/scripts/docs-sync.sh +++ b/scripts/docs-sync.sh @@ -237,8 +237,12 @@ ${generated}" if [[ "$has_frontmatter" == "false" ]]; then existing="${CONTENT_DIR}/${page_key}" if [[ -f "$existing" ]]; then - # Extract existing frontmatter and prepend to new content - existing_fm=$(sed -n '/^---$/,/^---$/p' "$existing") + # Extract existing frontmatter (first --- block only) and prepend. + # awk single-state-machine: include lines starting with the first + # --- and stop after the second one. Robust against bodies that + # use ^---$ as markdown horizontal-rule separators (would otherwise + # double on each sync — see docs#19). + existing_fm=$(awk '/^---$/{n++; print; if(n==2)exit} n==1 && !/^---$/{print}' "$existing") content="${existing_fm} ${content}"