klaanon-builder

klaanon builder - html ja epub
git clone https://neny.bioklaani.fi/git/klaanon-builder.git
Log | Files | Refs | README

commit b8307f04a6f1e27f9ffdcad4ce38454adfddf921
parent fe03f06d27f46315389000bd701889ce47405207
Author: nindwen <me@nindwen.blue>
Date:   Thu,  1 Aug 2019 19:36:51 +0300

Move repeated code to json_parse.sh

Diffstat:
MMakefile | 14+++++++-------
Ajson_parse.sh | 11+++++++++++
2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile @@ -6,7 +6,7 @@ default: output/klaanon.html output/klaanon1.html output/klaanon2.html output/kl epub: output/klaanon.epub output/klaanon.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content.html + ./json_parse.sh > content.html cat header.html content.html foot.html > output/klaanon.html rm content.html @@ -19,32 +19,32 @@ output/content.md: klaanon.json rm linkless.html output/klaanon1.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id < 250) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content1.html + ./json_parse.sh ".id < 250" > content1.html cat header.html content1.html foot.html > output/klaanon1.html rm content1.html output/klaanon2.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id >= 250 and .id < 500) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content2.html + ./json_parse.sh ".id >= 250 and .id < 500" > content2.html cat header.html content2.html foot.html > output/klaanon2.html rm content2.html output/klaanon3.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id >= 500 and .id < 750) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content3.html + ./json_parse.sh ".id >= 500 and .id < 750" > content3.html cat header.html content3.html foot.html > output/klaanon3.html rm content3.html output/klaanon4.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id >= 750 and .id < 1000) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content4.html + ./json_parse.sh ".id >= 750 and .id < 1000" > content4.html cat header.html content4.html foot.html > output/klaanon4.html rm content4.html output/klaanon5.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id >= 1000 and .id < 1250) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content5.html + ./json_parse.sh ".id >= 1000 and .id < 1250" > content5.html cat header.html content5.html foot.html > output/klaanon5.html rm content5.html output/klaanon6.html: klaanon.json header.html foot.html - jq -r 'def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | select(.id >= 1250 and .id < 1500) | "<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' klaanon.json > content6.html + ./json_parse.sh ".id >= 1250 and .id < 1500" > content6.html cat header.html content6.html foot.html > output/klaanon6.html rm content6.html diff --git a/json_parse.sh b/json_parse.sh @@ -0,0 +1,11 @@ +command1='def time: . | strptime("%Y-%m-%dT%H:%M")|mktime|strflocaltime("%d.%m.%Y"); .posts | .[] | ' +if [ -z "$1" ] +then + condition="" +else + condition="select($1) | " +fi +command2='"<h1><a href=#\(.id) id=\(.id)>\(.creator)</a></h1><div class=\"timestamp\">\(.timestamp|time)</div><p>\(.content)</p>"' + +full_command="$command1$condition$command2" +jq -r "$full_command" klaanon.json