Skip to content

Commit

Permalink
Generated makefile for extra dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 8, 2017
1 parent 6c3eed6 commit 79ed95a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# cache
/docs/.yummy
/docs/.meta
# experiments
/docs/content/xxx*
/docs/content/yyy*
Expand Down
35 changes: 16 additions & 19 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -17,7 +21,7 @@ Version := $(shell cat ../VERSION)
########################################################################

# Metadata directory
Metadata := .yummy
Metadata := .meta

# Load global parameters
-include $(Metadata)/globals.make
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand Down Expand Up @@ -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) > $$@
Expand Down
96 changes: 65 additions & 31 deletions docs/make.d/front-matter.make
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -74,44 +74,78 @@ 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

# 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
Expand Down

0 comments on commit 79ed95a

Please sign in to comment.