From e4e7c711de1d7bb067f48896c7d3824cde4863b8 Mon Sep 17 00:00:00 2001 From: Joan Josep Ordinas Rosa Date: Fri, 21 Apr 2017 13:25:35 +0200 Subject: [PATCH] Pages front-matter stored as a stream --- docs/Makefile | 6 +-- docs/blocks/filters.jq | 6 ++- docs/content/blog/2017-04-13-hello.md | 1 - docs/make.d/data.make | 11 ++-- docs/make.d/pages.make | 2 +- docs/make.d/phase2.jq | 2 +- docs/make.d/phase21.jq | 73 +++++++++++++++++++-------- docs/make.d/phase3.jq | 2 +- docs/make.d/sitemap.make | 8 ++- 9 files changed, 70 insertions(+), 41 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index 3da29c7..78fd212 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -75,11 +75,11 @@ ifdef __phase_1 # MetadataPaths # Defined rules for: # $(Metadata)/phase2.make +# $(DataFiles) # $(DestinationPaths) -# $(MetadataPaths) +# $(Metadata)/pages-by-id.json # $(MetadataPages) -# $(Metadata)/pages.json -# $(Metadata)/sections.json +# $(MetadataPaths) # Defined targets: # init # ====================================================================== diff --git a/docs/blocks/filters.jq b/docs/blocks/filters.jq index 69845df..d0e26b6 100644 --- a/docs/blocks/filters.jq +++ b/docs/blocks/filters.jq @@ -2,7 +2,7 @@ # Extra filters for this site # -import "collected-front-matter" as $pages; +import "pages-by-id" as $pages; # Remove XML tags def striptags: @@ -15,7 +15,9 @@ def pages: ; def sections: - [pages[].section] | unique | map(select(.)) + [$pages::pages[0].section] + | unique + | map(select(. != null and . != "")) ; # vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq diff --git a/docs/content/blog/2017-04-13-hello.md b/docs/content/blog/2017-04-13-hello.md index 4649387..fbe26e6 100644 --- a/docs/content/blog/2017-04-13-hello.md +++ b/docs/content/blog/2017-04-13-hello.md @@ -6,7 +6,6 @@ description: | documentation to the JQT site and serve as a test for the build system used. keywords: blog, post, jqt, jq, pandoc -#author: Joan Josep Ordinas Rosa published: "2017-04-13T06:45:07Z" updated: "2017-04-13T06:45:07Z" --- diff --git a/docs/make.d/data.make b/docs/make.d/data.make index ee6ca6e..ef5fcfd 100644 --- a/docs/make.d/data.make +++ b/docs/make.d/data.make @@ -15,11 +15,11 @@ # MetadataPaths # Defined rules for: # $(Metadata)/phase2.make +# $(DataFiles) # $(DestinationPaths) -# $(MetadataPaths) +# $(Metadata)/pages-by-id.json # $(MetadataPages) -# $(Metadata)/collected-front-matter.json -# $(DataFiles) +# $(MetadataPaths) # Targets: # init @@ -98,9 +98,10 @@ $(MetadataPaths): # Group metadata ######################################################################## -$(Metadata)/collected-front-matter.json: $(MetadataPages) +# Bundle all pages as a relation (id => page) +$(Metadata)/pages-by-id.json: $(MetadataPages) $(info ==> $@) - @jq --slurp '.' $^ > $@ + @jq --slurp 'reduce .[] as $$p ({}; . + {($$p.id): $$p})' $^ > $@ ######################################################################## # Files derived from $(Data)/* diff --git a/docs/make.d/pages.make b/docs/make.d/pages.make index e46aa21..19ed048 100644 --- a/docs/make.d/pages.make +++ b/docs/make.d/pages.make @@ -18,7 +18,7 @@ ######################################################################## # Build rules for each page -$(Metadata)/phase3.make: $(Metadata)/collected-front-matter.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make +$(Metadata)/phase3.make: $(Metadata)/pages-by-id.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make $(info ==> $@) @jq --raw-output \ --arg Metadata $(Metadata) \ diff --git a/docs/make.d/phase2.jq b/docs/make.d/phase2.jq index 444421a..d5ccac6 100644 --- a/docs/make.d/phase2.jq +++ b/docs/make.d/phase2.jq @@ -7,7 +7,7 @@ def comment: ; def dir: - sub("/[^/]+$"; "/") + if test("/") then sub("/[^/]+$"; "/") else "./" end ; def dpaths($paths): diff --git a/docs/make.d/phase21.jq b/docs/make.d/phase21.jq index 82f0820..8b4b13c 100644 --- a/docs/make.d/phase21.jq +++ b/docs/make.d/phase21.jq @@ -1,13 +1,13 @@ # phase21.jq - --arg Source s --arg Target s --arg Metadata s --slurpfile config s # -# Generate page.json files +# Generate each page.json files def basename: sub("\\.[^/]+$"; "") ; def dir: - sub("/[^/]+$"; "/") + if test("/") then sub("/[^/]+$"; "/") else "" end ; def notdir: @@ -21,7 +21,6 @@ def page_id: # `$(Metadata)/pages/path/to/page.json` => `(../)+` def page_base: - #$(patsubst ../../../%,%,$(subst $(space),$(empty),$(patsubst %,../,$(subst /,$(space),$1)))) ("../" * ((($Target / "/") | length) - 3)) // "" ; @@ -30,11 +29,6 @@ def page_name: $Target | notdir | basename ; -# `$(Metadata)/pages/path/to/page.json` => `path/to/page.html` -def page_url: - $Target | page_id+".html" -; - # `$(Metadata)/pages/path/to/page.json` => `path/to/` def page_path: $Target | page_id | dir @@ -43,27 +37,62 @@ def page_path: # `$(Metadata)/pages/path/to/page.json` => `path/to` def page_section: $Target - | if test("index.json$") + | if test("(?\\d{4}-\\d{2}-\\d{2})-") | .date) + // "" +; + ######################################################################## # Output object for each page ######################################################################## -. + { - base: page_base, - filename: page_name, - id: page_id, - path: page_path, - section: page_section, - source: $Source, - url: page_url -} + -reduce $config[0].defaults[] as $defaults - ({}; if page_id | test("^" + $defaults.idprefix) - then . + $defaults.properties - else . end) +def defaults: + reduce $config[0].defaults[] as $d + ({}; if page_id | test("^"+$d.idprefix) + then . + $d.properties + else . end) +; + +def properties: + { + base: page_base, + date: page_date, + id: page_id, + path: page_path, + section: page_section, + slug: page_slug, + source: $Source, + url: (page_path+page_slug) + } +; + +. as $front_matter | + +# final object +defaults + properties + $front_matter + +# section slug +# ⊢--^-⊣ ⊢--^----⊣ +#content/extras/name.html +# ⊢--------v⊣ +# ⊢--v--⊣ id +# path + +# path slug +# ⊢-------^-----⊣⊢------^--------⊣ +#content/extras/indexes/name-example.html +# ⊢------------------v------⊣ +# ⊢-----v------⊣ id +# section? or limit to one level? # vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq diff --git a/docs/make.d/phase3.jq b/docs/make.d/phase3.jq index 607f779..d2f15e1 100644 --- a/docs/make.d/phase3.jq +++ b/docs/make.d/phase3.jq @@ -25,7 +25,7 @@ def data: ######################################################################## "__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) > $@" diff --git a/docs/make.d/sitemap.make b/docs/make.d/sitemap.make index 3babb66..e1ea146 100644 --- a/docs/make.d/sitemap.make +++ b/docs/make.d/sitemap.make @@ -14,16 +14,14 @@ define SITEMAP.jq ", \ - ( .[] | \ - "\t", \ + (.[] | ( "\t", \ "\t\t" + $$baseurl + "/" + .url + "", \ "\t\t" + .updated + "", \ - "\t" \ - ), \ + "\t")), \ "" endef -$(Destination)/sitemap.xml: $(Metadata)/collected-front-matter.json $(Metadata)/site.json \ +$(Destination)/sitemap.xml: $(Metadata)/pages-by-id.json $(Metadata)/site.json \ | $(Destination) $(info ==> $@) @jq --raw-output --slurpfile site $(Metadata)/site.json '$(SITEMAP.jq)' < $< > $@