Skip to content

Commit

Permalink
More modular jq
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 24, 2017
1 parent e33ca7e commit 439419d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 50 deletions.
18 changes: 8 additions & 10 deletions docs/make.d/phase0.jq
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# phase0.jq --arg Version $(Version) --arg Metadata $(Metadata)
#
# Generate site.json from config.json.

########################################################################
# Output object
########################################################################

# Add some new members if not defined and delete `.defaults`.
# phase0.jq
# --arg Version $(Version)
# --arg Metadata $(Metadata)
# < $(Metadata)/config.json > $(Metadata)/site.json

#
# Delete `.defaults` and add some new members if not defined
#
del(.defaults)
| . + {
+ {
Destination: (.Destination // "_site"),
Assets: (.Assets // "assets"),
Blocks: (.Blocks // "blocks"),
Expand Down
17 changes: 6 additions & 11 deletions docs/make.d/phase1.jq
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# phase1.jq
# phase1.jq < $(Metadata)/site.json > $(Metadata)/phase1.make
#
# Generate phase1.make from site.json.

def comment:
"# vim:syntax=make"
;

########################################################################
# Output makefile
########################################################################

# Format members as make variables.
# Function to cheat vim
def comment: "# vim:syntax=make";

#
# Format some members as make variables
#
"__phase_1 := 1",
"Assets := " + .Assets,
"Blocks := " + .Blocks,
Expand Down
23 changes: 14 additions & 9 deletions docs/make.d/phase2.jq
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# phase2.jq --arg ...
#
# Generate phase2.make from `find` output.
# find $(Content) MARKDOWN FILES |
# phase2.jq
# --arg DF "$$(find $(Data) -name '*.*')"
# --arg Content $(Content)
# --arg Data $(Data)
# --arg Destination $(Destination)
# --arg Metadata $(Metadata)
# > $(Metadata)/phase1.make

def comment:
"# vim:syntax=make"
;
def comment: "# vim:syntax=make";

def dir:
if test("/") then sub("/[^/]+$"; "/") else "./" end
if test("/")
then sub("/[^/]+$"; "/")
else "./" end
;

def dpaths($paths):
Expand Down Expand Up @@ -69,9 +74,9 @@ def data($files):
else "DataCSV := " + ($DataCSV | map(d2m("csv")) | join(" ")) + "\n" end
;

########################################################################
#
# Output makefile
########################################################################
#

(.[:-1] / "\n") as $documents
| [$documents[] | dir] | unique as $paths
Expand Down
9 changes: 6 additions & 3 deletions docs/make.d/phase21.jq
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# phase21.jq - --arg Source s --arg Target s --arg Metadata s --slurpfile config s
#
# Generate each page.json files
# FRONT-MATTER | phase21.jq
# --arg Source s
# --arg Target s
# --arg Metadata s
# --slurpfile config s
# > $(Metadata)/pages/PAGE.json

def basename:
sub("\\.[^/]+$"; "")
Expand Down
45 changes: 28 additions & 17 deletions docs/make.d/phase3.jq
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
# phase3.jq --arg Metadata $(Metadata) --arg Layouts $(Layouts) --arg Destination $(Destination)
#
# Generate phase3.make from pages.json
# phase3.jq
# --arg Metadata $(Metadata)
# --arg Layouts $(Layouts)
# --arg Destination $(Destination)
# < $(Metadata)/pages-by-id.json > $(Metadata)/phase3.make

def comment:
"# vim:syntax=make"
;
def comment: "# vim:syntax=make";

def use:
if .use
then " "+(.use | join(" "))
then " " + (.use | join(" "))
else "" end
;

def flags:
if .flags
then .flags | join(" ")
then " " + (.flags | join(" "))
else "" end
;

def layout:
" " + $Layouts + "/" + .layout + ".html"
;

def data:
if .data
then .data | map("-m\(.):$(Metadata)/snippets.json") | join(" ")
then " " + (.data | map("-m\(.):$(Metadata)/snippets.json") | join(" "))
else "" end
;

########################################################################

def page:
" -mpage:" + $Metadata + "/pages/" + .id + ".json"
;

# makefile rule for HTML page
def page_rule:
$Destination+"/"+.url+": " + .source + " " + layout + use,
"\t$(info ==> $@)",
"\t@$(JQT) -d $< " + data + flags + page + layout + " | $(DETAILS) > $@"
;

#
# Output makefile
########################################################################
#

"__phase_3 := 1",
(.[] | ( # for each page
$Destination+"/"+.url+": "+.source+" "+$Layouts+"/"+.layout+".html"+use,
"\t$(info ==> $@)",
"\t@$(JQT) "+data+" "+flags+" -mpage:"+$Metadata+"/pages/"+.id+".json -d $< "+$Layouts+"/"+.layout+".html | $(DETAILS) > $@"
)
),
(.[] | page_rule), # for each page
comment

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq

0 comments on commit 439419d

Please sign in to comment.