From 8dc0e9d30a3d0aa1de7884cbf69850d37e1c42ed Mon Sep 17 00:00:00 2001 From: Joan Josep Ordinas Rosa Date: Wed, 5 Apr 2017 13:17:46 +0200 Subject: [PATCH] Exploring introspection --- docs/Makefile | 16 ++++----- docs/make.d/introspect.make | 66 +++++++++++++++++++++++++++++++++++++ docs/make.d/metadata.make | 10 +++--- 3 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 docs/make.d/introspect.make diff --git a/docs/Makefile b/docs/Makefile index b017715..9509282 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -3,7 +3,7 @@ include make.d/config.make ######################################################################## -# Globals +# Globals and setup ######################################################################## # Metadata directory @@ -22,15 +22,20 @@ Metadata := .yummy # Layouts # Styles -# While clobbering don't introspect +# If not clobbering #ifeq (,$(filter clobber,$(MAKECMDGOALS))) ifneq (clobber,$(MAKECMDGOALS)) -# Include metadata +# Define targets for basic metadata include make.d/metadata.make +# Build metadata from introspection +ifdef __globals__ +include make.d/introspect.make endif +endif # not clobbering + ######################################################################## # jqt command with options ######################################################################## @@ -131,11 +136,6 @@ ifdef __globals__ all: $(Targets) static @echo 1>&2 'Imprimatur!' -# Destination directory -$(Destination): - $(info ==> $@) - @mkdir $@ >/dev/null 2>&1 || true - # Copy assets static: | $(Destination) @cp --verbose --recursive --update $(Assets)/* $(Destination) \ diff --git a/docs/make.d/introspect.make b/docs/make.d/introspect.make new file mode 100644 index 0000000..9c01a1e --- /dev/null +++ b/docs/make.d/introspect.make @@ -0,0 +1,66 @@ +######################################################################## +# Introspect filesystem and files's front-matter to build metadata +######################################################################## + +# Imported variables: +# Metadata +# Content +# Destination + +# Destination directory +$(Destination): + $(info ==> $@) + @mkdir $@ >/dev/null 2>&1 || true + +# Markdown document found in the filesystem (only .md extensions) +_documents := $(shell find $(Content) -type f -a -name '*.md') + +# Pages to be generated, and related JSON +define fsys_pages = + $(patsubst %.md,%.$1,$(patsubst $(Content)%,$2%,$(_documents))) +endef + +PagesHTML := $(call fsys_pages,html,$(Destination)) +PagesJSON := $(call fsys_pages,json,$(Metadata)/pages) + +# Tree structure of directories +fsys_tree_docs := $(sort $(dir $(_documents))) + +define fsys_tree = + $(patsubst $(Content)%,$1%,$(fsys_tree_docs)) +endef + +fsys_tree_site := $(call fsys_tree,$(Destination)) +fsys_tree_page := $(call fsys_tree,$(Metadata)/pages) +fsys_tree_node := $(call fsys_tree,$(Metadata)/nodes) + +# All sections and subsections, removing home page node +define fsys_derived_nodes = + $(call rest,$(patsubst %/,%$1,$2)) +endef + +NodesJSON := $(call fsys_derived_nodes,.json,$(fsys_tree_node)) +NodesHTML := $(call fsys_derived_nodes,/index.html,$(fsys_tree_site)) + +# Make directories +$(fsys_tree_site): $(Destination)/% : $(Content)/% + @mkdir $@ >/dev/null 2>&1 || true +$(fsys_tree_page): $(Metadata)/pages/% : $(Content)/% + @mkdir $@ >/dev/null 2>&1 || true +$(fsys_tree_node): $(Metadata)/nodes/% : $(Content)/% + @mkdir $@ >/dev/null 2>&1 || true + +######################################################################### +# Test +intro: + @echo '_documents: $(_documents)' + @echo 'PagesHTML: $(PagesHTML)' + @echo 'PagesJSON: $(PagesJSON)' + @echo 'fsys_tree_docs: $(fsys_tree_docs)' + @echo 'fsys_tree_site: $(fsys_tree_site)' + @echo 'fsys_tree_page: $(fsys_tree_page)' + @echo 'fsys_tree_node: $(fsys_tree_node)' + @echo 'NodesJSON: $(NodesJSON)' + @echo 'NodesHTML: $(NodesHTML)' + +# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make diff --git a/docs/make.d/metadata.make b/docs/make.d/metadata.make index b6ae52e..2fdccd1 100644 --- a/docs/make.d/metadata.make +++ b/docs/make.d/metadata.make @@ -5,6 +5,11 @@ # Imported variables: # Metadata +# Metadata directory +$(Metadata): + $(info ==> $@) + @mkdir $@ >/dev/null 2>&1 || true + # Build all metadata files .PHONY: metadata metadata: \ @@ -12,11 +17,6 @@ metadata: \ $(Metadata)/globals.make @: -# Metadata directory -$(Metadata): - $(info ==> $@) - @mkdir $@ >/dev/null 2>&1 || true - # # Configuration files #