Skip to content

Commit

Permalink
Create site with documentation #164 : fill empty articles with link list
Browse files Browse the repository at this point in the history
  • Loading branch information
xonixx committed Mar 7, 2024
1 parent c8f1262 commit e38bced
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions mdbooker.awk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BEGIN {
Title = Content = ""
delete PathElements
delete Link2Path
delete ContentLinks
}

match($0, /^#+/) { handleTitle(RLENGTH, 1) }
Expand All @@ -16,20 +17,27 @@ function handleTitle(h,pass, indent,dir,i,path) {
for (i = 2; i < H; i++)
dir = dir (dir ? "-" : "") fname(PathElements[i])
path = dir (dir ? "-" : "") fname(Title) ".md"
if (pass == 1)
if (pass == 1) {
Link2Path[linkify(Title)] = path
else {
if (H > 2)
ContentLinks[PathElements[H - 1]] = ContentLinks[PathElements[H - 1]] Title "\n"
}else {
print "generating: " path "..."
print Content > BOOK path
if (!(Content = trim(Content))) {
Content = ContentLinks[Title]
}
print "# " Title > BOOK path
print Content >> BOOK path
if ((indent = H - 2) < 0)
indent = 0
printf "%" (indent * 4) "s%s[%s](%s)\n", "", 1 == H ? "" : "- ", Title, path >> SUMMARY
}
}
Content = "# " (Title = PathElements[H = h] = trim(substr($0, h + 1)))
Content = ""
Title = PathElements[H = h] = trim(substr($0, h + 1))
}

END { handleTitle(0, 1); pass2() }
END { handleTitle(0, 1); for (k in ContentLinks) print k "->" ContentLinks[k] ; pass2() }

function pass2( l,f,t) {
Title = Content = ""
Expand Down

0 comments on commit e38bced

Please sign in to comment.