Skip to content

Commit

Permalink
New name inside introspect
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 6, 2017
1 parent b81000c commit c474a55
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# cache
/docs/.yummy
# experiments
/docs/content/xxx*
/docs/content/yyy*
# built site
/docs/_site
# man pages
Expand Down
65 changes: 39 additions & 26 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Metadata := .yummy
# Styles

# If not clobbering
#ifeq (,$(filter clobber,$(MAKECMDGOALS)))
ifneq (clobber,$(MAKECMDGOALS))

# Define targets for basic metadata
Expand All @@ -34,7 +33,20 @@ ifdef __globals__
include make.d/introspect.make
endif

endif # not clobbering
# Defined in introspect.make:
# HomePage
# Pages
# OtherPages

endif # not clobbering

# Warning:
#
# If `__globals__` is not defined because `globals.make` does not exists, after
# this point most of the file is ignored, but `globals.make` is built because a
# rule exists in the file `metadata.make` (only if the target is not `clobber`).
# Then `Makefile` is restarted, `MAKE_RESTARTS` will be equal to 1,
# `globals.make` is loaded and `__globals__` is defined.

########################################################################
# jqt command with options
Expand Down Expand Up @@ -89,10 +101,7 @@ Static := styles.css
JQT_Man := jqt.1

# Target filenames
HomePage := $(Destination)/$(Home).html
OtherPages := $(foreach p,$(Other),$(Destination)/$(p).html)
Files := $(foreach f,$(Static),$(Destination)/$(f))
Pages := $(HomePage) $(OtherPages)
ManPage := ../$(JQT_Man).gz
Targets := $(Pages) $(Files) $(ManPage)

Expand Down Expand Up @@ -133,8 +142,8 @@ endif # __globals__
ifdef __globals__

# Default target
all: $(Targets) static
@echo 1>&2 'Imprimatur!'
all: static $(Targets)
@echo 1>&2 'Imprimatur.'

# Copy assets
static: | $(Destination)
Expand Down Expand Up @@ -170,6 +179,14 @@ $(ManPage): $(Content)/$(JQT_Man).markdown
| pandoc --standalone --from markdown --to man \
| gzip > $@

# Generate Help text (needs explicit call: `make /tmp/help`)
/tmp/help: $(Content)/help.markdown
$(info ==> $@)
@jqt -P MarkDown -I$(Content) < $< \
| pandoc --from markdown --to plain - \
| sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \
> $@

endif # __globals__

########################################################################
Expand All @@ -178,18 +195,6 @@ endif # __globals__

.PHONY: clean clobber build help

clean:
@rm -rf $(Destination)/* $(ManPage)

ifdef __globals__
clobber:
@rm -rf $(Destination) $(ManPage) $(Metadata)
else
clobber: ;
endif

build: clean all

# Show targets
help:
@echo 'Usage: make TARGET [parameter=value...]'
Expand All @@ -201,6 +206,20 @@ help:
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4

ifndef __globals__

clobber: ;

else

clean:
@rm -rf $(Destination)/* $(ManPage)

clobber:
@rm -rf $(Destination) $(ManPage) $(Metadata)

build: clean all

.PHONY: valid lint

# Validation using vnu.jar
Expand All @@ -214,12 +233,6 @@ lint: all
@xmlwf $(Destination)/*.html
@java -jar $(VNU) --format text $(Destination)/*.html

# Generate Help text (need explicit call: `make /tmp/help`)
/tmp/help: $(Content)/help.markdown
$(info ==> $@)
@jqt -P MarkDown -I$(Content) < $< \
| pandoc --from markdown --to plain - \
| sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \
> $@
endif # __globals__

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
94 changes: 58 additions & 36 deletions docs/make.d/introspect.make
Original file line number Diff line number Diff line change
@@ -1,66 +1,88 @@
########################################################################
# Introspect filesystem and files's front-matter to build metadata
# Introspection of filesystem and files's front-matter
########################################################################

# Imported variables:
# Metadata
# Content
# Destination
# Exported variables:
# ?
# HomePage
# Pages
# OtherPages
# ...

# Destination directory
$(Destination):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true
# Markdown documents found in the filesystem (only .md extensions)
_documents := $(sort $(shell find $(Content) -type f -a -name '*.md'))

# Markdown document found in the filesystem (only .md extensions)
_documents := $(shell find $(Content) -type f -a -name '*.md')
# Tree structure of directories
# Unique paths to documents directories
_paths := $(sort $(dir $(_documents)))

# Pages to be generated, and related JSON
define fsys_pages =
$(patsubst %.md,%.$1,$(patsubst $(Content)%,$2%,$(_documents)))
endef
# Paths to create at $(Destination)
_paths_destination := $(patsubst $(Content)%,$(Destination)%,$(_paths))

define fsys_tree =
$(patsubst $(Content)%,$1%,$(_paths))
endef
# Paths to nodes at $(Metadata)
_paths_meta_nodes := $(patsubst $(Content)%,$(Metadata)/nodes%,$(_paths))

# All sections and subsections, removing home page node
define fsys_nodes =
$(call rest,$(patsubst %/,%$1,$2))
endef
# Paths to pages at $(Metadata)
_paths_meta_pages := $(patsubst $(Content)%,$(Metadata)/pages%,$(_paths))

#
PagesHTML := $(call fsys_pages,html,$(Destination))
PagesJSON := $(call fsys_pages,json,$(Metadata)/pages)
fsys_tree_site := $(call fsys_tree,$(Destination))
fsys_tree_page := $(call fsys_tree,$(Metadata)/pages)
fsys_tree_node := $(call fsys_tree,$(Metadata)/nodes)
NodesJSON := $(call fsys_nodes,.json,$(fsys_tree_node))
NodesHTML := $(call fsys_nodes,/index.html,$(fsys_tree_site))

# Make directories
$(fsys_tree_site): $(Destination)/% : $(Content)/%
#

$(Destination):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true
$(fsys_tree_page): $(Metadata)/pages/% : $(Content)/%

$(_paths_destination): $(Destination)/% : $(Content)/%
@mkdir $@ >/dev/null 2>&1 || true

$(_paths_meta_pages): $(Metadata)/pages/% : $(Content)/%
@mkdir $@ >/dev/null 2>&1 || true
$(fsys_tree_node): $(Metadata)/nodes/% : $(Content)/%

$(_paths_meta_nodes): $(Metadata)/nodes/% : $(Content)/%
@mkdir $@ >/dev/null 2>&1 || true

#
# Global names defined
#

# Home page
HomePage := $(Destination)/index.html

# Pages to generate at $(Destination)
Pages := $(patsubst %.md,%.html,$(patsubst $(Content)%,$(Destination)%,$(_documents)))
OtherPages := $(filter-out $(HomePage),$(Pages))

# JSON for each page to generate at $(Metadata)/pages
PagesJSON := $(patsubst %.md,%.json,$(patsubst $(Content)%,$(Metadata)/pages%,$(_documents)))

# Nodes to generate at $(Destination)
NodesHTML := $(call rest,$(patsubst %/,%/index.html,$(_paths_destination))))

# JSON for each node to generate at $(Metadata)/nodes
NodesJSON := $(call rest,$(patsubst %/,%.json,$(_paths_meta_nodes))))

#########################################################################
# Test
intro:
@echo 'Metadata: $(Metadata)'
@echo 'Content: $(Content)'
@echo 'Destination: $(Destination)'
@echo
@echo '_documents: $(_documents)'
@echo '_paths: $(_paths)'
@echo 'PagesHTML: $(PagesHTML)'
@echo
@echo '_paths_meta_nodes: $(_paths_meta_nodes)'
@echo '_paths_meta_pages: $(_paths_meta_pages)'
@echo '_paths_destination: $(_paths_destination)'
@echo
@echo 'HomePage: $(HomePage)'
@echo 'Pages: $(Pages)'
@echo 'OtherPages: $(OtherPages)'
@echo 'PagesJSON: $(PagesJSON)'
@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)'
@echo 'NodesJSON: $(NodesJSON)'

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
21 changes: 14 additions & 7 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@ $(Metadata):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true

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

#
# Configuration files
#
Expand Down Expand Up @@ -79,4 +72,18 @@ $(Metadata)/globals.make: $(Metadata)/config.json
'$(MAKE_GLOBALS)' \
< $< > $@

ifdef __globals__

# TODO: rest of metadata files...


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

endif # __globals__

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make

0 comments on commit c474a55

Please sign in to comment.