diff --git a/docs/Makefile b/docs/Makefile index bee0b28..8a67535 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -23,9 +23,9 @@ endif endif # ====================================================================== --include $(Metadata)/phase_1.make +-include $(Metadata)/phase1.make # -# Load site global parameters. If `phase_1.make` not exists it is built when +# Load site global parameters. If `phase1.make` not exists it is built when # restarting with a rule defined in `config.make`. # # Exported variables: @@ -39,85 +39,41 @@ endif # Styles # ====================================================================== -# ====================================================================== include make.d/config.make -# -# Build files derived from user defined configuration: -# config.{yaml,json} => config.json => site.json => phase_1.make -# -# Imported variables: -# Metadata -# Version -# Exported rules for: -# $(Metadata) -# $(Metadata)/config.json -# $(Metadata)/site.json -# $(Metadata)/phase_1.make -# ====================================================================== # Warning: # -# If `__phase_1` is not defined because `phase_1.make` does not exists, after -# this point most of the file is ignored, but `phase_1.make` is built because a +# If `__phase_1` is not defined because `phase1.make` does not exists, after +# this point most of the file is ignored, but `phase1.make` is built because a # rule exists in the file `config.make`. Then this `Makefile` is restarted, -# `MAKE_RESTARTS` will be equal to 1, `phase_1.make` is now loaded and -# `__phase_1` is defined. +# `MAKE_RESTARTS` is be equal to 1, `phase1.make` is now loaded and +# `__phase_1` is defined. Equivalent situation happens in all phases. -ifdef __phase_1 # not defined in a fresh start +ifdef __phase_1 # ====================================================================== --include $(Metadata)/phase_2.make +-include $(Metadata)/phase2.make # -# Build metadata from filesystem introspection. +# Load variables for several pathnames. # # Exported variables: # __phase_2 # DestinationPages # DestinationPaths -# HomePage # MetadataPages # MetadataPaths +# Exported dependencies: +# $(Metadata)/pages/.../page.json: | $$(dir $$@) # ====================================================================== -# ====================================================================== include make.d/pathnames.make -# -# ???????' -# -# Imported variables: -# Content -# Destination -# Metadata -# Exported rules for: -# $(Destination) -# $(Destination)/.../ -# $(Metadata)/.../ -# all:: $(DestinationPages) -# Additional dependencies defined: -# $(Destination)/.../page.html => $(Metadata)/pages/.../page.json -# ====================================================================== -#ifdef __phase_2 +ifdef __phase_2 -# ====================================================================== include make.d/front-matter.make -# -# Collect metadata from front-matter sections. -# -# Imported variables: -# Content -# Metadata -# MetadataPages -# Exported rules for: -# $(Metadata)/pages/.../page.json -# $(Metadata)/nodes/.../section.json -# $(Metadata)/pages.json -# $(Metadata)/nodes.json -# $(Metadata)/sections.json -# ====================================================================== # ====================================================================== --include $(Metadata)/phase_3.make +-include $(Metadata)/phase3.make # # Load rules for pages and nodes. If not exists is built when restarting with # rule defined in `pages.make`. @@ -125,77 +81,23 @@ include make.d/front-matter.make # Exported variables: # __phase_3 # Exported rules for: -# rules for all HTML files +# dependencies and rules for all HTML files # ====================================================================== -# ====================================================================== include make.d/pages.make -# -# Define standard rules and rules for HTML pages and nodes. -# -# Imported variables: -# Assets -# Destination -# Layouts -# Metadata -# JQTFLAGS -# Exported rules for: -# $(Metadata)/phase_3.make -# all:: # assets -# build -# clean:: -# clobber:: -# xbuild -# xxbuild -# ====================================================================== -# ====================================================================== -include make.d/sitemap.make -# -# Define rules for sitemap. -# -# Imported variables: -# Destination -# Metadata -# Exported rules for: -# $(Destination)/sitemap.* -# all:: $(Destination)/sitemap.* -# ====================================================================== +ifdef __phase_3 -# ====================================================================== +include make.d/sitemap.make include make.d/styles.make -# -# Build CSS main stylesheet. -# -# Imported variables: -# Destination -# Blocks -# Styles -# Exported rules for: -# $(Destination)/styles.css -# all:: $(Destination)/styles.css -# ====================================================================== - -# ====================================================================== include make.d/tools.make -# -# Tools independent of any target. -# -# Parameters: -# vnudir -# Imported variables: -# Destination -# Exported rules for: -# help -# valid -# lint -# ====================================================================== ######################################################################## # Specific rules for this web site ######################################################################## -ifdef __phase_3 +# Call jqt with user defined flags +JQT = jqt $(JQTFLAGS) # Options for `jqt`. JQTFLAGS += \ @@ -270,7 +172,7 @@ clean:: @rm -f /tmp/help endif # __phase_3 -#endif # __phase_2 +endif # __phase_2 endif # __phase_1 # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/config.make b/docs/make.d/config.make index 3024086..4aa20c4 100644 --- a/docs/make.d/config.make +++ b/docs/make.d/config.make @@ -9,6 +9,7 @@ # Version # Exported rules for: # $(Metadata) +# $(Metadata)/ # $(Metadata)/config.json # $(Metadata)/site.json # $(Metadata)/phase_1.make @@ -54,47 +55,20 @@ endif # # Create `$(Metadata)/site.json` from `$(Metadata)/config.json`. # - -# Add some new members to `$(Metadata)/config.json` and delete `.defaults`. -define m_SITE_JSON.jq := - 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 - -# Global configuration file with some added members. -$(Metadata)/site.json: $(Metadata)/config.json +$(Metadata)/site.json: $(Metadata)/config.json make.d/config.make $(info ==> $@) - @jq --sort-keys '$(m_SITE_JSON.jq)' < $< > $@ + @jq --sort-keys \ + --from-file make.d/phase0.jq \ + --arg Version $(Version) \ + < $< > $@ # -# Create `$(Metadata)/phase_1.make` from `$(Metadata)/site.json`. +# Create `$(Metadata)/phase1.make` from `$(Metadata)/site.json`. # - -# Format members as make variables. -define PHASE_1.jq := - "__phase_1 := 1", \ - "Assets := " + .Assets, \ - "Blocks := " + .Blocks, \ - "Content := " + .Content, \ - "Data := " + .Data, \ - "Destination := " + .Destination, \ - "Layouts := " + .Layouts, \ - "Styles := " + .Styles, \ - "# vim:syntax=make" -endef - -# Makefile to be included in `Makefile`. -$(Metadata)/phase_1.make: $(Metadata)/site.json make.d/config.make +$(Metadata)/phase1.make: $(Metadata)/site.json make.d/config.make make.d/phase1.jq $(info ==> $@) - @jq --raw-output '$(PHASE_1.jq)' < $< > $@ + @jq --raw-output \ + --from-file make.d/phase1.jq \ + < $< > $@ # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/front-matter.make b/docs/make.d/front-matter.make index cff2765..c665af7 100644 --- a/docs/make.d/front-matter.make +++ b/docs/make.d/front-matter.make @@ -4,17 +4,57 @@ # Collect metadata from front-matter sections. # # Imported variables: -# Content -# Metadata +# DestinationPages # Exported rules for: -# $(Metadata)/pages/.../page.json -# $(Metadata)/nodes/.../section.json -# $(Metadata)/pages.json -# $(Metadata)/nodes.json -# $(Metadata)/sections.json +# ?? ######################################################################## -# Collect metadata for pages +# Extra dependencies +######################################################################## + +# Add prerequisites to default goal +all:: $(DestinationPages) + +$(DestinationPages): $(Destination)/%.html : $(Metadata)/pages/%.json +$(DestinationPages): $(Layouts)/default.html + +######################################################################## +# Rules for directories +######################################################################## + +# Destination directory. +# Define targets with and without trailing slash. +$(Destination) $(Destination)/: + $(info ==> $@) + @mkdir --parents $@ >/dev/null 2>&1 || true + +# Directories starting at `$(Destination)/` +$(DestinationPaths): + $(info ==> $@) + @mkdir --parents $@ >/dev/null 2>&1 || true + +# Directories starting at `$(Metadata)/pages/`. +$(MetadataPaths): + $(info ==> $@) + @mkdir --parents $@ >/dev/null 2>&1 || true + +$(DestinationPages): | $$(dir $$@) +$(MetadataPages): | $$(dir $$@) + +######################################################################## +# Group metadata +######################################################################## + +$(Metadata)/pages.json: $(MetadataPages) + $(info ==> $@) + @jq --slurp '.' $^ > $@ + +$(Metadata)/sections.json: $(Metadata)/pages.json + $(info ==> $@) + @jq '[.[].section] | unique | map(select(.))' < $< > $@ + +######################################################################## +# TODO: phase21.jq !!!!!!!!!!! ######################################################################## # `$(Metadata)/pages/path/to/page.json` => `path/to/page` @@ -85,7 +125,7 @@ define f_PAGE_JSON.jq = endef # Extract YAML front matter. -define f_extract_front_matter = +define EXTRACT_FRONT_MATTER = sed -n -e '1d' \ -e '/^---$$/q' \ -e '/^\.\.\.$$/q' \ @@ -95,24 +135,12 @@ endef # Build metadata for pages. $(MetadataPages): $(Metadata)/config.json -$(MetadataPages): $(Metadata)/pages/%.json : $(Content)/%.md +$(MetadataPages): $(Metadata)/pages/%.json : $(Content)/%.md # TODO: any accepted extension $(info ==> $@) - @$(f_extract_front_matter) < $< \ + @$(EXTRACT_FRONT_MATTER) < $< \ | yaml2json \ | jq --sort-keys \ --slurpfile config $(Metadata)/config.json \ '$(call f_PAGE_JSON.jq,$<,$@)' > $@ -######################################################################## -# Group metadata -######################################################################## - -$(Metadata)/pages.json: $(MetadataPages) - $(info ==> $@) - @jq --slurp '.' $^ > $@ - -$(Metadata)/sections.json: $(Metadata)/pages.json - $(info ==> $@) - @jq '[.[].section] | unique | map(select(.))' < $< > $@ - # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/pages.make b/docs/make.d/pages.make index b5021f3..c869b69 100644 --- a/docs/make.d/pages.make +++ b/docs/make.d/pages.make @@ -10,13 +10,13 @@ # Metadata # JQTFLAGS # Exported rules for: -# $(Metadata)/phase_3.make # all:: # assets # build # clean # clobber # touch # fresh +# $(Metadata)/phase3.make ######################################################################## # Standard targets @@ -60,45 +60,27 @@ fresh: clobber init: @rm -rf $(Metadata) - @$(MAKE) -s $(Metadata)/phase_3.make + @$(MAKE) -s $(Metadata)/phase3.make ######################################################################## # Create makefile containing rules for all HTML files ######################################################################## -# Call jqt with user defined flags -JQT = jqt $(JQTFLAGS) - -# hack to modify markup -define p_DETAILS := - sed -e 's/^

<\/p>/
/' \ - -e 's/^

<\/details><\/p>/<\/details>/' \ - -e 's/^

//' \ - -e 's/<\/summary><\/p>/<\/summary>/' -endef - -# Complete command -define p_recipe := -"\t$$(info ==> $$@)\n\t@$$(JQT) -mpage:$(Metadata)/pages/"+.id+".json -d $$< $(Layouts)/"+.layout+".html | $$(p_DETAILS) > $$@" -endef - -define p_layouts := -$(Layouts)/default.html $(Layouts)/"+.layout+".html | $$$$(dir $$$$@)" -endef - -# . is $(Metadata)/pages.json -define PHASE_3.jq := - "__phase_3 := 1", \ - (.[] | ( \ - "$(Destination)/"+.url+": "+(.use//[]|join(" ")), \ - "$(Destination)/"+.url+": $(p_layouts), \ - "$(Destination)/"+.url+": "+.source+"\n"+$(p_recipe) \ - )), "# vim:syntax=make" +define DETAILS := + sed -e 's/^

<\/p>/
/' \ + -e 's/^

<\/details><\/p>/<\/details>/' \ + -e 's/^

//' \ + -e 's/<\/summary><\/p>/<\/summary>/' endef # Rules for each page (depend also on sections.json only to force build) -$(Metadata)/phase_3.make: $(Metadata)/pages.json $(Metadata)/sections.json +$(Metadata)/phase3.make: $(Metadata)/pages.json $(Metadata)/sections.json make.d/pages.make make.d/phase3.jq $(info ==> $@) - @jq --raw-output '$(PHASE_3.jq)' < $< > $@ + @jq --raw-output \ + --arg Metadata $(Metadata) \ + --arg Layouts $(Layouts) \ + --arg Destination $(Destination) \ + --from-file make.d/phase3.jq \ + < $< > $@ # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/pathnames.make b/docs/make.d/pathnames.make index cb69935..f9e5a6a 100644 --- a/docs/make.d/pathnames.make +++ b/docs/make.d/pathnames.make @@ -3,96 +3,26 @@ # # Build metadata from filesystem introspection. # -# Imported variables: -# Content -# Destination -# Metadata -# Exported variables: -# DestinationPages -# DestinationPaths -# HomePage -# MetadataPages -# MetadataPaths # Exported rules for: -# $(Destination) -# $(Destination)/.../ -# $(Metadata)/.../ -# all:: $(DestinationPages) -# Additional dependencies defined: -# $(Destination)/.../page.html => $(Metadata)/pages/.../page.json +# $(Metadata)/phase2.make ######################################################################## -# Derived pathnames +# Create makefile defining global parameters about pathnames ######################################################################## -# Markdown documents found in the filesystem (only `.md` extensions). -#i_suffixes := -name '*.md' -o -name '*.mkd' -o -name '*.markdown' -i_suffixes := -name '[!_]*.md' -i_documents := $(sort $(shell find $(Content) -type f -a $(i_suffixes))) - -# Unique paths to documents directories. -i_paths := $(sort $(dir $(i_documents))) - -######################################################################## -# Exported variables -######################################################################## - -# Paths to create at `$(Destination)`. -DestinationPaths := $(call rest,$(patsubst $(Content)%,$(Destination)%,$(i_paths))) - -# Paths to pages at `$(Metadata)`. -MetadataPaths := $(patsubst $(Content)%,$(Metadata)/pages%,$(i_paths)) - -# Home page. -HomePage := $(Destination)/index.html - -# Pages to generate at `$(Destination)`. -DestinationPages := $(patsubst %.md,%.html,$(patsubst $(Content)%,$(Destination)%,$(i_documents))) - -# JSON for each page to generate at `$(Metadata)/pages`. -MetadataPages := $(patsubst %.md,%.json,$(patsubst $(Content)%,$(Metadata)/pages%,$(i_documents))) - -######################################################################## -# Extra dependencies -######################################################################## - -# Each HTML file depends on his metadata and directory. -$(DestinationPages): $(Destination)/%.html : $(Metadata)/pages/%.json -$(DestinationPages): | $$(dir $$@) - -# Each JSON file depends on his directory. -$(MetadataPages): | $$(dir $$@) - -# Add prerequisites to default goal -all:: $(DestinationPages) - -######################################################################## -# Rules for directories -######################################################################## - -# Destination directory. -# Define targets with and without trailing slash. -$(Destination) $(Destination)/: - $(info ==> $@) - @mkdir --parents $@ >/dev/null 2>&1 || true - -# Directories starting at `$(Destination)/` -$(DestinationPaths): +$(Metadata)/phase2.make: make.d/pathnames.make make.d/phase2.jq $(info ==> $@) - @mkdir --parents $@ >/dev/null 2>&1 || true - -# Directories starting at `$(Metadata)/pages/`. -$(MetadataPaths): - $(info ==> $@) - @mkdir --parents $@ >/dev/null 2>&1 || true - -######################################################################## -# -######################################################################## - -# Makefile to be included in `Makefile`. -#!$(Metadata)/phase_2.make: $(Metadata)/phase_1.json make.d/pathnames.make -#! $(info ==> $@) -#! @jq --raw-output '$(PHASE_1.jq)' < $< > $@ + @find $(Content) -type f -a \ + -name '[!_]*.md' -o \ + -name '[!_]*.mkd' -o \ + -name '[!_]*.markdown' \ + | jq --raw-input \ + --slurp \ + --raw-output \ + --from-file make.d/phase2.jq \ + --arg Content $(Content) \ + --arg Destination $(Destination) \ + --arg Metadata $(Metadata) \ + > $@ # vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/phase0.jq b/docs/make.d/phase0.jq new file mode 100644 index 0000000..f64b876 --- /dev/null +++ b/docs/make.d/phase0.jq @@ -0,0 +1,18 @@ +# phase0.jq --arg Version s +# +# Generate site.json from config.json. Add some new members +# and delete `.defaults`. + +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) +} + +# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq diff --git a/docs/make.d/phase1.jq b/docs/make.d/phase1.jq new file mode 100644 index 0000000..8861569 --- /dev/null +++ b/docs/make.d/phase1.jq @@ -0,0 +1,21 @@ +# phase1.jq +# +# Generate phase1.make from site.json. + +# Format members as make variables. + +def comment: + "# vim:syntax=make" +; + +"__phase_1 := 1", +"Assets := " + .Assets, +"Blocks := " + .Blocks, +"Content := " + .Content, +"Data := " + .Data, +"Destination := " + .Destination, +"Layouts := " + .Layouts, +"Styles := " + .Styles, +comment + +# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq diff --git a/docs/make.d/phase2.jq b/docs/make.d/phase2.jq new file mode 100644 index 0000000..3a4259e --- /dev/null +++ b/docs/make.d/phase2.jq @@ -0,0 +1,61 @@ +# phase2.jq --arg Destination s -arg Content s --arg Metadata s +# +# Generate phase2.make from `find` output. + +def comment: + "# vim:syntax=make" +; + +def dir: + sub("/[^/]+$"; "/") +; + +def dpaths($p): + def dpath: + sub("^"+$Content; $Destination) + ; + "DestinationPaths := " + ([$p[] | dpath][1:] | join(" ")) +; + +def mpaths($p): + def mpath: + sub("^"+$Content; $Metadata+"/pages") + ; + "MetadataPaths := " + ([$p[] | mpath] | join(" ")) +; + +def dpages($d): + def dpage: + sub("^"+$Content; $Destination) + | sub("\\.(?:markdown|mk?d)$"; ".html") + ; + "DestinationPages := " + ([$d[] | dpage] | join(" ")) +; + +def mpages($d): + def mpage: + sub("^"+$Content; $Metadata+"/pages") + | sub("\\.(?:markdown|mk?d)$"; ".json") + ; + [$d[] | mpage] as $json + | "MetadataPages := " + ($json | join(" ")) #+ "\n" + #+ ([$json[] | . + ": | $$(dir $$@)"] | join("\n")) +; + +######################################################################## + +(.[:-1]/"\n") as $documents +| [$documents[] | dir] | unique as $paths +| dpaths($paths) as $DestinationPaths +| mpaths($paths) as $MetadataPaths +| dpages($documents) as $DestinationPages +| mpages($documents) as $MetadataPages +| +"__phase_2 := 1", +$DestinationPaths, +$MetadataPaths, +$DestinationPages, +$MetadataPages, +comment + +# 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 new file mode 100644 index 0000000..7abd3b6 --- /dev/null +++ b/docs/make.d/phase3.jq @@ -0,0 +1,24 @@ +# phase3.jq --arg Destination s -arg Layouts s --arg Metadata s +# +# Generate phase3.make from pages.json from pages.json + +def comment: + "# vim:syntax=make" +; + +def use: + if .use + then " "+(.use | join(" ")) + else "" end +; + +"__phase_3 := 1", +(.[] | ( + $Destination+"/"+.url+": "+.source+" "+$Layouts+"/"+.layout+".html"+use, + "\t$(info ==> $@)", + "\t@$(JQT) -mpage:"+$Metadata+"/pages/"+.id+".json -d $< "+$Layouts+"/"+.layout+".html | $(DETAILS) > $@" + ) +), +comment + +# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq