diff --git a/docs/Makefile b/docs/Makefile index c4dde0a..075e212 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -1,6 +1,6 @@ # jqt documentation management -include make.d/config.make +include make.d/prelude.make ######################################################################## # Globals and setup @@ -19,20 +19,20 @@ Version := $(shell cat ../VERSION) # Defined in globals.make # ======================= # Variables: -# __globals__ -# Assets -# Blocks -# Content -# Data -# Destination -# Layouts -# Styles +# __globals__ +# Assets +# Blocks +# Content +# Data +# Destination +# Layouts +# Styles # If not clobbering ifneq (clobber,$(MAKECMDGOALS)) # Define targets for basic metadata -include make.d/metadata.make +include make.d/config.make # Defined in metadata.make # ======================== @@ -41,6 +41,7 @@ include make.d/metadata.make # $(Metadata)/config.json # $(Metadata)/site.json # $(Metadata)/globals.make +# $(Metadata)/pages/**.json # Build metadata from introspection ifdef __globals__ @@ -57,7 +58,8 @@ endif # NodesJSON # Targets: # $(Destination) -# all paths from $(Destination) and $(Metadata) +# all paths at $(Destination) and $(Metadata) +# each page from his metadata endif # not clobbering @@ -132,8 +134,8 @@ Targets := $(Pages) $(Files) $(ManPage) $(Pages): \ $(Blocks)/*/markup.html \ $(Blocks)/filters.jq \ - $(Content)/LINKS.txt \ $(Content)/macros.m \ + $(Content)/LINKS.txt \ $(Metadata)/snippets.json \ $(Metadata)/config.json \ @@ -141,8 +143,8 @@ $(Pages): \ other_pages := $(filter-out $(HomePage),$(Pages)) $(other_pages): \ $(Content)/FLOW.txt \ - $(Layouts)/page.html \ $(Content)/opt/*.txt \ + $(Layouts)/page.html \ $(HomePage) \ $(Destination)/structure.html: \ @@ -162,12 +164,10 @@ endif # __globals__ ifdef __globals__ -# Default target +# Default target (always try to copy assets) all: $(Targets) -# Copy assets @cp --verbose --recursive --update $(Assets)/* $(Destination) \ | sed "s/^.*-> ./==> /;s/.$$//" -# All done @echo 1>&2 'Imprimatur.' # Snippets @@ -238,10 +238,14 @@ endif # __globals__ # External utilities ######################################################################## +ifdef __globals__ + # help and other targets include make.d/tools.make # HTML 5 validation include make.d/vnu.make +endif # __globals__ + # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/content/content.md b/docs/content/content.md index 99e0948..3ba9681 100644 --- a/docs/content/content.md +++ b/docs/content/content.md @@ -4,6 +4,7 @@ title: Authoring content in jqt using MarkDown description: jqt transforms MarkDown documents to HTML using Pandoc. keywords: jqt, markdown, pandoc, gpp, preprocessing, authoring content updated: "2016-08-28T10:27:09Z" +use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4DdiT].txt"] --- <%include content/macros.m>& <%include content/LINKS.txt>& diff --git a/docs/content/data.md b/docs/content/data.md index e5186bb..4bee361 100644 --- a/docs/content/data.md +++ b/docs/content/data.md @@ -4,6 +4,7 @@ title: Managing the data model with jqt description: jqt combines one template with one MarkDown document and a data model. keywords: jqt, JSON, YAML, gpp, preprocessing, data model updated: "2016-08-28T10:27:09Z" +use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[DeIMmnPRT].txt"] --- <%include content/macros.m>& <%include content/LINKS.txt>& diff --git a/docs/content/engine.md b/docs/content/engine.md index dfa6e34..3ae3a6c 100644 --- a/docs/content/engine.md +++ b/docs/content/engine.md @@ -4,6 +4,7 @@ title: The jqt template engine description: jqt orchestrates several shell utilities to transform MarkDown text and YAML or JSON data into a final HTML page. keywords: jqt, jq, YAML, gpp, preprocessing, template engine updated: "2016-08-28T10:27:09Z" +use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4CDdeHhIijLMmnPprSTtVw].txt"] --- <%include content/macros.m>& <%include content/LINKS.txt>& diff --git a/docs/content/index.md b/docs/content/index.md index 1b2f6f8..2cd02ce 100644 --- a/docs/content/index.md +++ b/docs/content/index.md @@ -4,6 +4,7 @@ title: Welcome to jqt description: Could be jq the basis for a web template engine? keywords: jqt, jq, template engine updated: "2016-08-28T10:27:09Z" +use: [content/macros.m, content/LINKS.txt, content/EXAMPLE.txt] --- <%include content/macros.m>& <%include content/LINKS.txt>& diff --git a/docs/content/structure.md b/docs/content/structure.md index 4668a13..1ef28fa 100644 --- a/docs/content/structure.md +++ b/docs/content/structure.md @@ -4,6 +4,7 @@ title: Defining the page structure with jqt description: Web pages structure is defined by the HTML macros. keywords: jqt, jq, gpp, preprocessing, template engine updated: "2016-08-28T10:27:09Z" +use: [content/macros.m, content/LINKS.txt, content/EXAMPLE.txt, content/FLOW.txt, "content/opt/[DIijL].txt"] --- <%include content/macros.m>& <%include content/LINKS.txt>& diff --git a/docs/make.d/config.make b/docs/make.d/config.make index 4b14241..e8e92cf 100644 --- a/docs/make.d/config.make +++ b/docs/make.d/config.make @@ -2,92 +2,83 @@ # Configuration ######################################################################## -# Exported macros: -# comma -# empty -# space -# rest +# Imported variables: +# Metadata +# Version +# Exported targets: +# $(Metadata) +# $(Metadata)/config.json +# $(Metadata)/site.json +# $(Metadata)/globals.make +# Order of dependencies: +# globals.make => site.json => config.json => config.yaml + +# Metadata directory +$(Metadata): + $(info ==> $@) + @mkdir --parents $@ >/dev/null 2>&1 || true # -# Prerequisites +# Target files # -# We are using some of the newest GNU Make features... so require GNU -# Make version >= 3.82 -version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82))) -ifndef version_test -$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed) -endif - -# Only one target at the same time -MAKECMDGOALS ?= all - -# Check 'root' intentions -ifeq (,$(filter install uninstall,$(MAKECMDGOALS))) -ifeq (0,$(shell id --user)) -$(error Root only can make "(un)install" targets) -endif -SUDO := -else -SUDO := sudo -endif - -# Target 'clobber' must be alone -ifeq (clobber,$(filter clobber,$(MAKECMDGOALS))) -ifneq (1,$(words $(MAKECMDGOALS))) -$(error Target "clobber" must be alone) -endif -endif - -# -# Parameters -# +# Create $(Metadata)/config.json +# Input is user defined config.yaml or config.json. +ifeq (config.yaml, $(wildcard config.yaml)) -# Disable builtins. -MAKEFLAGS += --no-builtin-rules -MAKEFLAGS += --no-builtin-variables +# Convert config.yaml to $(Metadata)/config.json +$(Metadata)/config.json: config.yaml \ +| $(Metadata) + $(info ==> $@) + @yaml2json < $< > $@ -# Warn when an undefined variable is referenced. -MAKEFLAGS += --warn-undefined-variables +else ifeq (config.json, $(wildcard config.json)) -# Make will not print the recipe used to remake files. -#.SILENT: +# Convert config.json to $(Metadata)/config.json +$(Metadata)/config.json: config.json \ +| $(Metadata) + $(info ==> $@) + @jqt -Pjson < $< > $@ -# Eliminate use of the built-in implicit rules. Also clear out the -# default list of suffixes for suffix rules. -.SUFFIXES: - -# Sets the default goal to be used if no targets were specified on the -# command line. -.PHONY: all -.DEFAULT_GOAL := all - -# Default shell: if we require GNU Make, why not require Bash? -SHELL := /bin/bash - -# The argument(s) passed to the shell are taken from the variable -# .SHELLFLAGS. -.SHELLFLAGS := -o errexit -o pipefail -o nounset -c - -# Make will delete the target of a rule if it has changed and its recipe -# exits with a nonzero exit status. -.DELETE_ON_ERROR: - -# Enable a second expansion of the prerequisites -.SECONDEXPANSION: - -# -# Common macros -# +else +$(error Configuration file not found) +endif -# Hacks for string manipulation -comma := , -empty := -space := $(empty) $(empty) +# Globals definition to mix with config.json +define m_SITE_JSON := + del(.defaults) \ + | . + { \ + Destination: (.Destination // "./_site"), \ + Assets: (.Assets // "./assets"), \ + Blocks: (.Blocks // "./blocks"), \ + Content: (.Content // "./content"), \ + Data: (.Data // "./data"), \ + Layouts: (.Layouts // "./layouts"), \ + Styles: (.Styles // "./styles"), \ + Version: (.Version // "$(Version)") \ + } +endef -# Hack for list manipulation -define rest = - $(wordlist 2,2147483648,$1) +$(Metadata)/site.json: $(Metadata)/config.json + $(info ==> $@) + @jq --sort-keys '$(m_SITE_JSON)' < $< > $@ + +# Variables to define in globals.make +define m_GLOBALS_MAKE := + "__globals__ := 1", \ + "Assets := " + .Assets, \ + "Blocks := " + .Blocks, \ + "Content := " + .Content, \ + "Data := " + .Data, \ + "Destination := " + .Destination, \ + "Layouts := " + .Layouts, \ + "Styles := " + .Styles, \ + "# vim:syntax=make" endef +# Create globals.make +$(Metadata)/globals.make: $(Metadata)/site.json + $(info ==> $@) + @jq --raw-output '$(m_GLOBALS_MAKE)' < $< > $@ + # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/introspect.make b/docs/make.d/introspect.make index c4ff099..61d6c94 100644 --- a/docs/make.d/introspect.make +++ b/docs/make.d/introspect.make @@ -15,6 +15,9 @@ # Exported targets: # $(Destination) # all paths at $(Destination) and $(Metadata) +# Additional dependencies +# each page from his metadata +# each node from his metadata # Markdown documents found in the filesystem (only .md extensions) i_documents := $(sort $(shell find $(Content) -type f -a -name '*.md')) @@ -26,35 +29,39 @@ i_paths := $(sort $(dir $(i_documents))) i_paths_destination := $(call rest,$(patsubst $(Content)%,$(Destination)%,$(i_paths))) # Paths to nodes at $(Metadata) -i_paths_meta_nodes := $(patsubst $(Content)%,$(Metadata)/nodes%,$(i_paths)) +i_paths_metadata_nodes := $(patsubst $(Content)%,$(Metadata)/nodes%,$(i_paths)) # Paths to pages at $(Metadata) -i_paths_meta_pages := $(patsubst $(Content)%,$(Metadata)/pages%,$(i_paths)) +i_paths_metadata_pages := $(patsubst $(Content)%,$(Metadata)/pages%,$(i_paths)) # -# Make directories +# Targets for directories # +# Destination directory $(Destination): $(info ==> $@) @mkdir --parents $@ >/dev/null 2>&1 || true -$(i_paths_destination): ## $(Destination)/% : $(Content)/% +# $(Destination)/.../ +$(i_paths_destination): + $(info ==> $@) @mkdir --parents $@ >/dev/null 2>&1 || true -$(i_paths_meta_pages): ## $(Metadata)/pages/% : $(Content)/% +# $(Metadata)/pages/.../ +$(i_paths_metadata_pages): + $(info ==> $@) @mkdir --parents $@ >/dev/null 2>&1 || true -$(i_paths_meta_nodes): ## $(Metadata)/nodes/% : $(Content)/% +# $(Metadata)/nodes/.../ +$(i_paths_metadata_nodes): + $(info ==> $@) @mkdir --parents $@ >/dev/null 2>&1 || true # -# Global names defined +# Exported variables # -# All pathnames to create -#? Paths := $(i_paths_destination) $(i_paths_meta_pages) $(i_paths_meta_nodes) - # Home page HomePage := $(Destination)/index.html @@ -68,7 +75,85 @@ PagesJSON := $(patsubst %.md,%.json,$(patsubst $(Content)%,$(Metadata)/pages%,$( Nodes := $(addsuffix index.html,$(i_paths_destination)) # JSON for each node to generate at $(Metadata)/nodes -NodesJSON := $(call rest,$(patsubst %/,%.json,$(i_paths_meta_nodes))) +NodesJSON := $(call rest,$(patsubst %/,%.json,$(i_paths_metadata_nodes))) + +# +# Pages metadata +# + +# $(Metadata)/pages/path/to/page.json ==> path/to/page +define i_page_id = +$(subst $(Metadata)/pages/,,$(basename $1)) +endef + +# $(Metadata)/pages/path/to/page.json ==> ../+ +define i_page_base = +$(patsubst ../../%,%,$(subst $(space),$(empty),$(patsubst %,../,$(subst /,$(space),$1)))) +endef + +# $(Metadata)/pages/path/to/page.json ==> page +define i_page_name = +$(basename $(notdir $1)) +endef + +# $(Metadata)/pages/path/to/page.json ==> path/to/page.html +define i_page_url = +$(call i_page_id,$1).html +endef + +# $(Metadata)/pages/path/to/page.json ==> path/to/ +define i_page_path = +$(dir $(call i_page_id,$1)) +endef + +# $(Metadata)/pages/path/to/page.json ==> path/to +define i_page_section = +$(patsubst %/,%,$(call i_page_path,$1)) +endef + +# . is a MarkDown file front matter +define i_PAGE_JSON = + . + { \ + "id": "$(call i_page_id,$1)", \ + "base": "$(call i_page_base,$1)", \ + "filename": "$(call i_page_name,$1)", \ + "path": "$(call i_page_path,$1)", \ + "url": "$(call i_page_url,$1)", \ + "section": "$(call i_page_section,$1)", \ + "isnode": false, \ + "ispage": true \ + } as $$page | \ + $$config[0].defaults as $$defaults | \ + reduce $$defaults[] as $$d \ + ({}; if "$(call i_page_id,$1)" | test("^" + $$d.idprefix) \ + then . + $$d.properties \ + else . end) + $$page +endef + +# Extract YAML front matter +define i_extract_front_matter + sed -n -e '1d' \ + -e '/^---$$/q' \ + -e '/^\.\.\.$$/q' \ + -e '/^\#/d' \ + -e 'p' +endef + +# Build metadata for a page +$(PagesJSON): $(Metadata)/pages/%.json : $(Content)/%.md \ +| $$(dir $$@) + $(info ==> $@) + @$(i_extract_front_matter) < $< \ + | yaml2json \ + | jq --sort-keys \ + --slurpfile config $(Metadata)/config.json \ + '$(call i_PAGE_JSON,$@)' > $@ + +# Each page depend on his metadata +$(Pages): $(Destination)/%.html : $(Metadata)/pages/%.json + +# Each node depend on his metadata +#$(Nodes): $(Destination)/%.html : $(Metadata)/nodes/%.json ######################################################################### # Test @@ -82,8 +167,8 @@ intro: @echo 'i_paths: $(i_paths)' @echo @echo 'i_paths_destination: $(i_paths_destination)' - @echo 'i_paths_meta_nodes: $(i_paths_meta_nodes)' - @echo 'i_paths_meta_pages: $(i_paths_meta_pages)' + @echo 'i_paths_metadata_nodes: $(i_paths_metadata_nodes)' + @echo 'i_paths_metadata_pages: $(i_paths_metadata_pages)' @echo @echo 'HomePage: $(HomePage)' @echo 'Pages: $(Pages)' diff --git a/docs/make.d/metadata.make b/docs/make.d/metadata.make deleted file mode 100644 index 21abf14..0000000 --- a/docs/make.d/metadata.make +++ /dev/null @@ -1,124 +0,0 @@ -######################################################################## -# Metadata -######################################################################## - -# Imported variables: -# Metadata -# Version -# Exported targets: -# $(Metadata) -# $(Metadata)/config.json -# $(Metadata)/site.json -# $(Metadata)/globals.make -# $(Metadata)/pages/**.json -# Order of dependencies: -# globals.make => site.json => config.json => config.yaml - -# Metadata directory -$(Metadata): - $(info ==> $@) - @mkdir --parents $@ >/dev/null 2>&1 || true - -# -# Configuration -# - -# Create $(Metadata)/config.json -# Input is user defined config.yaml or config.json. -ifeq (config.yaml, $(wildcard config.yaml)) - -# Convert config.yaml to $(Metadata)/config.json -$(Metadata)/config.json: config.yaml \ -| $(Metadata) - $(info ==> $@) - @yaml2json < $< > $@ - -else ifeq (config.json, $(wildcard config.json)) - -# Convert config.json to $(Metadata)/config.json -$(Metadata)/config.json: config.json \ -| $(Metadata) - $(info ==> $@) - @jqt -Pjson < $< > $@ - -else -$(error Configuration file not found) -endif - -# Globals definition to mix with config.json -define m_SITE_JSON := - del(.defaults) \ - | . + { \ - Destination: (.Destination // "./_site"), \ - Assets: (.Assets // "./assets"), \ - Blocks: (.Blocks // "./blocks"), \ - Content: (.Content // "./content"), \ - Data: (.Data // "./data"), \ - Layouts: (.Layouts // "./layouts"), \ - Styles: (.Styles // "./styles"), \ - Version: (.Version // "$(Version)") \ - } -endef - -$(Metadata)/site.json: $(Metadata)/config.json - $(info ==> $@) - @jq --sort-keys '$(m_SITE_JSON)' < $< > $@ - -# Variables to define in globals.make -define m_MAKE_GLOBALS := - "__globals__ := 1", \ - "Assets := " + .Assets, \ - "Blocks := " + .Blocks, \ - "Content := " + .Content, \ - "Data := " + .Data, \ - "Destination := " + .Destination, \ - "Layouts := " + .Layouts, \ - "Styles := " + .Styles, \ - "# vim:syntax=make" -endef - -# Create globals.make -$(Metadata)/globals.make: $(Metadata)/site.json - $(info ==> $@) - @jq --raw-output '$(m_MAKE_GLOBALS)' < $< > $@ - -ifdef __globals__ - -#md_page_id = $(subst $(MetaDB)/pages/,,$(basename $1)) -#md_page_url = $(call md_page_id,$1).html -#md_page_name = $(basename $(notdir $1)) -#md_page_path = $(dir $(call md_page_id,$1)) -#md_page_section = $(patsubst %/,%,$(call md_page_path,$1)) -#md_page_base = $(patsubst ../../%,%,$(subst $(space),,$(patsubst %,../,$(subst /, ,$1)))) -# -## . is a MarkDown file front matter -#define md_entry_page -# . + { \ -# "id": "$(call md_page_id,$1)", \ -# "base": "$(call md_page_base,$1)", \ -# "filename": "$(call md_page_name,$1)", \ -# "path": "$(call md_page_path,$1)", \ -# "url": "$(call md_page_url,$1)", \ -# "section": "$(call md_page_section,$1)", \ -# "isnode": false, \ -# "ispage": true \ -# } as $$page | \ -# $$config[0].defaults as $$defaults | \ -# reduce $$defaults[] as $$d \ -# ({}; if ("$(call md_page_id,$1)" | test("^" + $$d.idprefix)) \ -# then . + $$d.properties \ -# else . end) + $$page -#endef - -#$(Metadata)/pages/%.json: $(Content)/%.md $(Metadata)config.json | $$(dir $$@) \ -# $(info ==> $@) -# sed -n -e '1d;/^---$$/q;/^\.\.\.$$/q;/^\#/d;p' < $< \ -# | yaml2json \ -# | jq --sort-keys \ -# --slurpfile config $(MetaDB)/config.json \ -# '$(call md_entry_page,$@)' >$@ -# - -endif # __globals__ - -# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/prelude.make b/docs/make.d/prelude.make new file mode 100644 index 0000000..da7007f --- /dev/null +++ b/docs/make.d/prelude.make @@ -0,0 +1,100 @@ +######################################################################## +# Prelude +######################################################################## + +# Exported macros: +# comma +# empty +# space +# rest +# filename + +# +# Prerequisites +# + +# We are using some of the newest GNU Make features... so require GNU +# Make version >= 3.82 +version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82))) +ifndef version_test +$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed) +endif + +# Only one target at the same time +MAKECMDGOALS ?= all + +# Check 'root' intentions +ifeq (,$(filter install uninstall,$(MAKECMDGOALS))) +ifeq (0,$(shell id --user)) +$(error Root only can make "(un)install" targets) +endif +SUDO := +else +SUDO := sudo +endif + +# Target 'clobber' must be alone +ifeq (clobber,$(filter clobber,$(MAKECMDGOALS))) +ifneq (1,$(words $(MAKECMDGOALS))) +$(error Target "clobber" must be alone) +endif +endif + +# +# Make configuration +# + +# Disable builtins. +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables + +# Warn when an undefined variable is referenced. +MAKEFLAGS += --warn-undefined-variables + +# Make will not print the recipe used to remake files. +#.SILENT: + +# Eliminate use of the built-in implicit rules. Also clear out the +# default list of suffixes for suffix rules. +.SUFFIXES: + +# Sets the default goal to be used if no targets were specified on the +# command line. +.PHONY: all +.DEFAULT_GOAL := all + +# Default shell: if we require GNU Make, why not require Bash? +SHELL := /bin/bash + +# The argument(s) passed to the shell are taken from the variable +# .SHELLFLAGS. +.SHELLFLAGS := -o errexit -o pipefail -o nounset -c + +# Make will delete the target of a rule if it has changed and its recipe +# exits with a nonzero exit status. +.DELETE_ON_ERROR: + +# Enable a second expansion of the prerequisites +.SECONDEXPANSION: + +# +# Common macros +# + +# Hacks for string manipulation +comma := , +empty := +space := $(empty) $(empty) +tab := $(empty) $(empty) + +# Hack for list manipulation +define rest = +$(wordlist 2,2147483648,$1) +endef + +# File name without extension nor directory +define filename +$(basename $(notdir $1)) +endef + +# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/vnu.make b/docs/make.d/vnu.make index 3d85692..cc707ee 100644 --- a/docs/make.d/vnu.make +++ b/docs/make.d/vnu.make @@ -6,8 +6,6 @@ # valid # lint -ifdef __globals__ - .PHONY: valid lint VNU := /usr/local/vnu/vnu.jar @@ -22,6 +20,4 @@ lint: all @xmlwf $(Destination)/*.html @java -jar $(VNU) --format text $(Destination)/*.html -endif # __globals__ - # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make