Skip to content

Commit

Permalink
Exploring introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 5, 2017
1 parent 2e55c2e commit 8dc0e9d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
16 changes: 8 additions & 8 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
include make.d/config.make

########################################################################
# Globals
# Globals and setup
########################################################################

# Metadata directory
Expand All @@ -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
########################################################################
Expand Down Expand Up @@ -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) \
Expand Down
66 changes: 66 additions & 0 deletions docs/make.d/introspect.make
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
# Imported variables:
# Metadata

# Metadata directory
$(Metadata):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true

# Build all metadata files
.PHONY: metadata
metadata: \
$(Metadata)/config.json \
$(Metadata)/globals.make
@:

# Metadata directory
$(Metadata):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true

#
# Configuration files
#
Expand Down

0 comments on commit 8dc0e9d

Please sign in to comment.