diff --git a/.gitignore b/.gitignore index 74a26fc..fc30d75 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ # cache -/docs/.jqt +/docs/.yummy # output of templates expansion tests/generated/*.jqe tests/generated/*.jqs diff --git a/Makefile b/Makefile index 188e934..d86fac2 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,8 @@ $(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed) endif # Paranoia -ifeq (0,$(shell id --user)) ifeq (,$(filter install uninstall,$(MAKECMDGOALS))) +ifeq (0,$(shell id --user)) $(error Root only can make "(un)install" targets) endif SUDO := diff --git a/bin/jqt b/bin/jqt index 86184ad..e89ed81 100755 --- a/bin/jqt +++ b/bin/jqt @@ -368,7 +368,7 @@ function fork_yaml # Markup document ######################################################################## -declare DOCUMENT='' DOCUMENT_ID='stdin' HTML_VERSION='html' +declare DOCUMENT='(standard input)' HTML_VERSION='html' declare -a PANDOC_OPTS=( '--from=markdown-pandoc_title_block' ) # < stdin > stdout @@ -410,7 +410,7 @@ declare -A JSON_DATA_DOT=() YAML_DATA_DOT=() # .page ... # .page._content # .page._highlight -# .page._id +# .page._path # .page._toc # < stdin > stdout @@ -424,7 +424,7 @@ function merge echo '(. / "") as [$body, $toc, $css] |' # page echo "{ $DOCUMENT_METADATA_NAME: ("; yaml2json < $FRONT_MATTER - echo "+ { _id: \"${DOCUMENT_ID}\","' _content: $body, _toc: $toc, _highlight: $css })}' + echo "+ { _path: \"${DOCUMENT}\", "'_content: $body, _toc: $toc, _highlight: $css })}' # additional data for key in "${!YAML_DATA[@]}"; do echo "+{ $key:" @@ -627,7 +627,6 @@ while getopts :hVD:I:P:L:i:j:45d:eprtn:m:M:T:CHS-: opt; do ;; d) [[ -e $OPTARG ]] || usage "File '$OPTARG' does not exists" DOCUMENT=$OPTARG - DOCUMENT_ID=${DOCUMENT%.md} ;; e) extract=1 ;; @@ -762,7 +761,7 @@ elif (( flagH )); then expand_md | markup elif (( flagC )); then declare -r FRONT_MATTER=$(mkpipe) expand_md | fork_yaml $FRONT_MATTER | markup | merge $FRONT_MATTER -elif [[ -z $DOCUMENT ]]; then +elif [[ $DOCUMENT == '(standard input)' ]]; then # equivalent to flagH expand_md | markup else diff --git a/docs/Makefile b/docs/Makefile index 84f1392..eb9719f 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -50,22 +50,22 @@ SHELL := /bin/bash ######################################################################## # Output directories -Meta := .jqt +Meta := .yummy Destination := /tmp/jqt # Directories for input files Assets := ./assets Content := ./content -Presentation := ./presentation -Structure := ./structure +Styles := ./styles +Layouts := ./layouts # Common sources for all targets Common := \ $(Meta)/config.json \ $(Meta)/snippets.json \ - $(Structure)/default.html \ - $(Structure)/head.html \ - $(Structure)/footer.html \ + $(Layouts)/default.html \ + $(Layouts)/head.html \ + $(Layouts)/footer.html \ $(Content)/LINKS.txt \ filters.jq \ macros.m \ @@ -87,7 +87,7 @@ Targets := \ # The template engine (.site and .snippets defined in the jqt call) JQT = jqt $(JQTFLAGS) JQTFLAGS := \ - -I$(Structure) \ + -I$(Layouts) \ -I$(Content) \ -ifilters \ -msite:$(Meta)/config.json \ @@ -98,6 +98,7 @@ JQTFLAGS := \ XHTMLValid := test -f /etc/xml/xhtml1-dtds.xml \ && xmllint --noout --valid $(Destination)/*.html \ && echo 'XHTML valid!' +# Uncomment to disable XML validation #XHTMLValid := : ######################################################################## @@ -114,11 +115,11 @@ $(Meta) $(Destination): ; mkdir $@ >/dev/null 2>&1 || true # Metad files $(Meta)/config.json: config.yaml \ | $(Meta) - yaml2json < $< > $@ + yaml2json <$< >$@ $(Meta)/snippets.json: $(Content)/snippets.yaml \ | $(Meta) - jqt -T -- $< | yaml2json > $@ + jqt -T -- <$< | yaml2json > $@ # Target files $(Destination)/README.md: $(Assets)/README.md \ @@ -129,34 +130,34 @@ $(Destination)/README.md: $(Assets)/README.md \ $(Destination)/index.html: $(Content)/home.md $(Common) \ | $(Destination) $(info ==> $@) - $(JQT) -d $< $(Structure)/default.html > $@ + $(JQT) -d $< $(Layouts)/default.html > $@ $(foreach p,$(Pages),$(Destination)/$(p).html): $(Content)/FLOW.txt $(Content)/opt/*.txt $(Destination)/index.html $(Destination)/structure.html: $(Content)/EXAMPLE.txt define Target -$(Destination)/$(1).html: $(Content)/$(1).md $(Structure)/$(2).html $(Common) \ +$(Destination)/$(1).html: $(Content)/$(1).md $(Layouts)/$(2).html $(Common) \ | $(Destination) $$(info ==> $$@) - $(JQT) -d $$< $(Structure)/$(2).html > $$@ + $(JQT) -d $$< $(Layouts)/$(2).html > $$@ endef $(foreach p,$(Pages),$(eval $(call Target,$(p),page))) -$(Destination)/jqt.css: $(Presentation)/jqt.css $(Presentation)/github.css +$(Destination)/jqt.css: $(Styles)/jqt.css $(Styles)/github.css $(info ==> $@) - jqt -P CSS-min -I$(Presentation) $< > $@ + jqt -P CSS-min -I$(Styles) <$< >$@ # Man page $(ManPage): $(Content)/jqt.1.markdown $(info ==> $@) - jqt -P MarkDown -I$(Content) $< \ + jqt -P MarkDown -I$(Content) <$< \ | pandoc --standalone --from markdown --to man \ | gzip > $@ # Help text /tmp/help: $(Content)/help.markdown - jqt -P MarkDown -I$(Content) $< \ + jqt -P MarkDown -I$(Content) <$< \ | pandoc --from markdown --to plain - \ | sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \ > $@ diff --git a/docs/config.yaml b/docs/config.yaml index 2269f72..6be64be 100644 --- a/docs/config.yaml +++ b/docs/config.yaml @@ -1,3 +1,4 @@ +--- # # jqt docs configuration # @@ -18,16 +19,17 @@ author: menu: - URL: ./engine.html - id: content/engine + path: content/engine.md name: Engine - URL: ./structure.html - id: content/structure + path: content/structure.md name: Structure - URL: ./content.html - id: content/content + path: content/content.md name: Content - URL: ./data.html - id: content/data + path: content/data.md name: Data # vim:ts=2:sw=2:ai:et:fileencoding=utf8:syntax=yaml +... diff --git a/docs/content/content.md b/docs/content/content.md index 03e30d5..7c0628c 100644 --- a/docs/content/content.md +++ b/docs/content/content.md @@ -34,11 +34,12 @@ and injects it into the render stage under a global JSON object named `.page`. ### Body -Pandoc will convert the document body to HTML, -and _jqt_ will inject it into the render stage under the global JSON scalar +Pandoc converts the document body to HTML, +and _jqt_ injects it into the render stage under the global JSON scalar `.page._content`. If the document contains fenced code blocks specifying the language of -the code block, the highlight code will be in the scalar `.page._css`. Also, the -table of contents will be in the scalar `.page._toc`. +the code block, the highlight code will be in the scalar `.page._highlight`. Also, the +table of contents is available in the scalar `.page._toc`, and the path to the document +file in the scalar `.page._path`. ## Document syntax diff --git a/docs/content/data.md b/docs/content/data.md index 94a3cef..dbbd7a0 100644 --- a/docs/content/data.md +++ b/docs/content/data.md @@ -34,6 +34,15 @@ data and influence JSON preprocessing: Document front matter metadata and additional input YAML files are converted to JSON and merged to be the `jq` input in the render stage. +The front matter content is available in the global object `.page`. The object +member names prefixed with the underline character (`_`) are reserved, and the following +are provided: + +* `.page._content`: the rendered input document. +* `.page._highlight`: CSS styles for highlighted code. +* `.page._path`: the input document pathname as provided to `jqt`. +* `.page._toc`: the rendered input document table of contents. + ### JSON Additional JSON files can be provided and are merged with front matter metadata diff --git a/docs/structure/default.html b/docs/layouts/default.html similarity index 88% rename from docs/structure/default.html rename to docs/layouts/default.html index b1df4e2..a4fdf2c 100644 --- a/docs/structure/default.html +++ b/docs/layouts/default.html @@ -13,7 +13,7 @@