Skip to content

Commit 392cb4f

Browse files
Kurt Overmierclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 2bcd7cc commit 392cb4f

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

scripts/docs-sync.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,12 @@ ${generated}"
237237
if [[ "$has_frontmatter" == "false" ]]; then
238238
existing="${CONTENT_DIR}/${page_key}"
239239
if [[ -f "$existing" ]]; then
240-
# Extract existing frontmatter and prepend to new content
241-
existing_fm=$(sed -n '/^---$/,/^---$/p' "$existing")
240+
# Extract existing frontmatter (first --- block only) and prepend.
241+
# awk single-state-machine: include lines starting with the first
242+
# --- and stop after the second one. Robust against bodies that
243+
# use ^---$ as markdown horizontal-rule separators (would otherwise
244+
# double on each sync — see docs#19).
245+
existing_fm=$(awk '/^---$/{n++; print; if(n==2)exit} n==1 && !/^---$/{print}' "$existing")
242246
content="${existing_fm}
243247
244248
${content}"

0 commit comments

Comments
 (0)