diff --git a/.gitignore b/.gitignore index 510f5d3..54e73d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # cache /docs/.yummy +/docs/.meta # experiments /docs/content/xxx* /docs/content/yyy* diff --git a/docs/Makefile b/docs/Makefile index 6dc6aee..7ef87fe 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -6,6 +6,10 @@ # Published: https://fadado.github.io/jqt/ ######################################################################## +ifdef MAKE_RESTARTS +$(info make restarted: $(MAKE_RESTARTS)) +endif + # Make configuration include make.d/prelude.make @@ -17,7 +21,7 @@ Version := $(shell cat ../VERSION) ######################################################################## # Metadata directory -Metadata := .yummy +Metadata := .meta # Load global parameters -include $(Metadata)/globals.make @@ -67,7 +71,16 @@ endif # Build metadata from files front-matter ifdef __globals__ + +# Extra dependencies for pages +-include $(Metadata)/pages-d.make + +# Extra dependencies for nodes +#-include $(Metadata)/nodes-d.make NOT YET + +# Extract front-mater from Markdown files include make.d/front-matter.make + endif # Defined in front-matter.make @@ -147,25 +160,9 @@ Targets := $(Pages) $(Files) $(ManPage) # # All pages -$(Pages): \ - $(Blocks)/*/markup.html \ - $(Blocks)/filters.jq \ - $(Content)/macros.m \ - $(Content)/LINKS.txt \ - $(Metadata)/snippets.json \ - $(Metadata)/config.json \ +$(Pages): $(Metadata)/snippets.json # All pages except home page -other_pages := $(filter-out $(HomePage),$(Pages)) -$(other_pages): \ - $(Content)/FLOW.txt \ - $(Content)/opt/*.txt \ - $(Layouts)/default.html \ - -$(HomePage) \ -$(Destination)/structure.html: \ - $(Content)/EXAMPLE.txt \ - $(Destination)/styles.css: \ $(Blocks)/*/*style.css \ $(Styles)/*.css \ @@ -194,7 +191,7 @@ $(Metadata)/snippets.json: $(Content)/snippets.yaml \ # HTML pages define Target = -$(Destination)/$(1).html: $(Content)/$(1).md $(Layouts)/$(2).html \ +$(Destination)/$(1).html: $(Content)/$(1).md \ | $(Destination) $$(info ==> $$@) @$(JQT) -d $$< $(Layouts)/$(2).html | $(DETAILS) > $$@ diff --git a/docs/make.d/front-matter.make b/docs/make.d/front-matter.make index 1dccf08..0be0815 100644 --- a/docs/make.d/front-matter.make +++ b/docs/make.d/front-matter.make @@ -13,56 +13,56 @@ ######################################################################## # $(Metadata)/pages/path/to/page.json ==> path/to/page -define i_page_id = +define f_page_id = $(subst $(Metadata)/pages/,,$(basename $1)) endef # $(Metadata)/pages/path/to/page.json ==> ../+ -define i_page_base = +define f_page_base = $(patsubst ../../%,%,$(subst $(space),$(empty),$(patsubst %,../,$(subst /,$(space),$1)))) endef # $(Metadata)/pages/path/to/page.json ==> page -define i_page_name = +define f_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 +define f_page_url = +$(call f_page_id,$1).html endef # $(Metadata)/pages/path/to/page.json ==> path/to/ -define i_page_path = -$(dir $(call i_page_id,$1)) +define f_page_path = +$(dir $(call f_page_id,$1)) endef # $(Metadata)/pages/path/to/page.json ==> path/to -define i_page_section = -$(patsubst %/,%,$(call i_page_path,$1)) +define f_page_section = +$(patsubst %/,%,$(call f_page_path,$1)) endef # . is a MarkDown file front matter -define i_PAGE_JSON.jq = +define f_PAGE_JSON.jq = . + { \ - 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)", \ + id: "$(call f_page_id,$1)", \ + base: "$(call f_page_base,$1)", \ + filename: "$(call f_page_name,$1)", \ + path: "$(call f_page_path,$1)", \ + url: "$(call f_page_url,$1)", \ + section: "$(call f_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) \ + ({}; if "$(call f_page_id,$1)" | test("^" + $$d.idprefix) \ then . + $$d.properties \ else . end) + $$page endef # Extract YAML front matter -define i_extract_front_matter = +define f_extract_front_matter = sed -n -e '1d' \ -e '/^---$$/q' \ -e '/^\.\.\.$$/q' \ @@ -74,36 +74,36 @@ endef $(PagesJSON): $(Metadata)/config.json $(PagesJSON): $(Metadata)/pages/%.json : $(Content)/%.md $(info ==> $@) - @$(i_extract_front_matter) < $< \ + @$(f_extract_front_matter) < $< \ | yaml2json \ | jq --sort-keys \ --slurpfile config $(Metadata)/config.json \ - '$(call i_PAGE_JSON.jq,$@)' > $@ + '$(call f_PAGE_JSON.jq,$@)' > $@ ######################################################################## # Collect metadata for nodes ######################################################################## -define i_node_id = +define f_node_id = $(subst $(Metadata)/nodes/,$(empty),$(basename $1))/index endef # . is $(Metadata)/config.json -define i_NODE_JSON.jq = - { id: "$(call i_node_id,$1)", \ - base: "$(call i_page_base,$1)", \ - title: "$(call md_page_name,$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)", \ +define f_NODE_JSON.jq = + { id: "$(call f_node_id,$1)", \ + base: "$(call f_page_base,$1)", \ + title: "$(call f_page_name,$1)", \ + filename: "$(call f_page_name,$1)", \ + path: "$(call f_page_path,$1)", \ + url: "$(call f_page_url,$1)", \ + section: "$(call f_page_section,$1)", \ date: (now | todateiso8601), \ ishome: false, \ isnode: true, \ ispage: false \ } as $$node | \ reduce .defaults[] as $$d \ - ({}; if "$(call i_node_id,$1)" | test("^" + $$d.idprefix) \ + ({}; if "$(call f_node_id,$1)" | test("^" + $$d.idprefix) \ then . + $$d.properties \ else . end) + $$node endef @@ -111,7 +111,41 @@ endef # Build metadata for nodes $(NodesJSON): $(Metadata)/config.json $(info ==> $@) - jq --sort-keys '$(call i_NODE_JSON.jq,$@)' < $< > $@ + jq --sort-keys '$(call f_NODE_JSON.jq,$@)' < $< > $@ + +######################################################################## +# Group metadata +######################################################################## + +$(Metadata)/pages.json: $(PagesJSON) + $(info ==> $@) + @jq --slurp '{ pages: . }' $^ > $@ + +$(Metadata)/nodes.json: $(NodesJSON) + $(info ==> $@) + @[[ "$^" != "" ]] && jq --slurp '{ nodes: . }' $^ > $@ || true + +$(Metadata)/sections.json: $(Metadata)/pages.json + $(info ==> $@) + @jq '{ sections: ([.pages[].section] | unique) }' < $< > $@ + +######################################################################## +# Create makefiles for extra dependencies +######################################################################## + +# . is $(Metadata)/config.json +define f_PAGES_D_MAKE.jq := + (.pages[]|"$(Destination)/"+.url+": $(Blocks)/*/markup.html $(Blocks)/filters.jq"), \ + (.pages[]|"$(Destination)/"+.url+": $(Layouts)/default.html"), \ + (.pages[]|"$(Destination)/"+.url+": "+(.use|join(" "))), \ + (.pages[]|"$(Destination)/"+.url+": $(Layouts)/"+(.layout)+".html"), \ + "# vim:syntax=make" +endef + +# Dependencies for each page (depend also on sections.json only to force build) +$(Metadata)/pages-d.make: $(Metadata)/pages.json $(Metadata)/sections.json + $(info ==> $@) + @jq --raw-output '$(f_PAGES_D_MAKE.jq)' < $< > $@ ######################################################################### # Test