Skip to content

Commit

Permalink
Create site with documentation #164
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Mar 3, 2024
1 parent 1d3ef3d commit 7510581
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions mdbooker.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
BEGIN {
OUTDIR = "book"
SUMMARY = OUTDIR "/SUMMARY.md"
printf "" > SUMMARY
H = 0
Title = ""
Content = ""
}

/^# / { handleTitle(1); next }
/^## / { handleTitle(2); next }
/^### / { handleTitle(3); next }
/^#### / { print "error: ####"; exit 1 }
{ Content = Content $0 "\n"; next }

function handleTitle(h, md) {
if (Title) {
md = Title ".md"
print "generating: " md "..."
print Content > md
printf "%" ((H - 1) * 4) "s%s[%s](%s)\n", "", 1 == H ? "" : "-", Title, md >> SUMMARY
}
H = h
Title = trim(substr($0, h))
Content = ""
}

END { handleTitle(-1) }

function trim(s) { sub(/^[ \t\r\n]+/, "", s); sub(/[ \t\r\n]+$/, "", s); return s }

0 comments on commit 7510581

Please sign in to comment.