From: Michael D. Lowis Date: Thu, 20 Aug 2015 01:37:29 +0000 (-0400) Subject: Add support for multi section pages X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c4c9e8b9c18c10b48e69fab81a796bf496238802;p=projs%2Fmikedlowis.github.io Add support for multi section pages --- diff --git a/Makefile b/Makefile index 171bddd..2878de1 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ PAGES = $(addprefix site/,$(addsuffix .html,$(basename $(notdir $(wildcard pages all: $(PAGES) serve: - serve + tools/serve site/%.html : pages/%.md genpage $< > $@ diff --git a/pages/articles.md b/pages/articles.md index 76fa143..998a635 100644 --- a/pages/articles.md +++ b/pages/articles.md @@ -1,4 +1,8 @@ TYPE page MENUID 1 --- +# Articles +articles +--- +foo diff --git a/pages/projects.md b/pages/projects.md index 5428d35..0439d65 100644 --- a/pages/projects.md +++ b/pages/projects.md @@ -1,4 +1,6 @@ TYPE page MENUID 2 --- +# Projects +projects diff --git a/pages/prototypes.md b/pages/prototypes.md index 7f406b1..49d20d8 100644 --- a/pages/prototypes.md +++ b/pages/prototypes.md @@ -1,4 +1,7 @@ TYPE page MENUID 3 --- +# Prototypes + +prototypes diff --git a/site/articles.html b/site/articles.html index 32a6729..ff44218 100644 --- a/site/articles.html +++ b/site/articles.html @@ -35,7 +35,8 @@
- +

Articles

+

articles

diff --git a/site/projects.html b/site/projects.html index 2545fb9..051853c 100644 --- a/site/projects.html +++ b/site/projects.html @@ -35,7 +35,8 @@
- +

Projects

+

projects

diff --git a/site/prototypes.html b/site/prototypes.html index fa0a90a..1fa2443 100644 --- a/site/prototypes.html +++ b/site/prototypes.html @@ -35,7 +35,8 @@
- +

Prototypes

+

prototypes

diff --git a/site/style.css b/site/style.css index dc83528..ad20ea2 100644 --- a/site/style.css +++ b/site/style.css @@ -114,4 +114,3 @@ a { margin: 0 0 1.5em 0; border-top: 1px solid #cccccc; } - diff --git a/templates/article.html b/templates/article.html new file mode 100644 index 0000000..f41fa0f --- /dev/null +++ b/templates/article.html @@ -0,0 +1,35 @@ + + + + {{TITLE}} + + + + + + +
+ + mdlowis + {{SUBTITLE}} +
+ + + +
+ +
+ {{SECTION2}} +
+
+ + +
diff --git a/templates/page.html b/templates/page.html index 4e66a66..37bce89 100644 --- a/templates/page.html +++ b/templates/page.html @@ -30,7 +30,7 @@
- {{CONTENT}} + {{SECTION1}}
diff --git a/tools/genpage b/tools/genpage index 0bee9cf..14af164 100755 --- a/tools/genpage +++ b/tools/genpage @@ -1,30 +1,44 @@ #!/bin/sh -awk_script=' -BEGIN { - file = OFILE - mode = 0 -} -mode == 1 { print $0 > file } +#awk_script=' +#BEGIN { +# file = OFILE +# mode = 0 +#} +# +#mode == 1 { print $0 > file } +# +#mode == 0 { +# if (($0 != "") && ($1 != "#")) { +# if ($0 != "---") { +# first = $1 +# $1 = "" +# print "export " first "=\"" substr($0, 2) "\"" +# } else { +# mode = 1 +# } +# } +#}' -mode == 0 { - if (($0 != "") && ($1 != "#")) { - if ($0 != "---") { - first = $1 - $1 = "" - print "export " first "=\"" substr($0, 2) "\"" - } else { - mode = 1 - } - } -}' ifile=${1:?"missing filename"} -ofile="contents.${0##*/}-$$" -touch $ofile -eval `awk -v OFILE="$ofile" "$awk_script" $ifile` -export CONTENT="`md2html.awk $ofile`" +sections=(`awk -v PID="$$" -f ./tools/sections.awk $ifile`) + +for i in "${!sections[@]}"; do + if [[ "$i" -eq "0" ]]; then + source "${sections[$i]}" + else + eval "export SECTION$i=\"`./tools/md2html.awk ${sections[$i]}`\"" + fi + rm "${sections[$i]}" +done + +#ifile=${1:?"missing filename"} +#ofile="contents.${0##*/}-$$" +#touch $ofile +#eval `awk -v OFILE="$ofile" "$awk_script" $ifile` +#export CONTENT="`md2html.awk $ofile`" . ./config.sh if [ -f "templates/$TYPE.html" ]; then mo "templates/$TYPE.html" fi -rm $ofile +#rm $ofile diff --git a/tools/sections.awk b/tools/sections.awk new file mode 100755 index 0000000..ecc46b9 --- /dev/null +++ b/tools/sections.awk @@ -0,0 +1,40 @@ +#!/bin/env awk -f + +BEGIN { + mode = 0 + pid = PID + sectid = 0 + newfile = "section-" sectid "-" pid + ofile = "" +} + +ofile == "" { + ofile = newfile + print ofile +} + +mode == 0 { + if (($0 != "") && ($1 != "#")) { + if ($0 != "---") { + first = $1 + $1 = "" + print "export " first "=\"" substr($0, 2) "\"" > ofile + } else { + mode = 1 + sectid = sectid + 1 + newfile = "section-" sectid "-" pid + ofile = "" + } + } +} + +mode == 1 { + if ($0 != "---") { + print $0 > ofile + } else { + sectid = sectid + 1 + newfile = "section-" sectid "-" pid + ofile = "" + } +} +