Skip to content

Commit

Permalink
Generated JSON for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 7, 2017
1 parent 89a5dff commit 4bff2b1
Show file tree
Hide file tree
Showing 11 changed files with 290 additions and 233 deletions.
36 changes: 20 additions & 16 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# jqt documentation management

include make.d/config.make
include make.d/prelude.make

########################################################################
# Globals and setup
Expand All @@ -19,20 +19,20 @@ Version := $(shell cat ../VERSION)
# Defined in globals.make
# =======================
# Variables:
# __globals__
# Assets
# Blocks
# Content
# Data
# Destination
# Layouts
# Styles
# __globals__
# Assets
# Blocks
# Content
# Data
# Destination
# Layouts
# Styles

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

# Define targets for basic metadata
include make.d/metadata.make
include make.d/config.make

# Defined in metadata.make
# ========================
Expand All @@ -41,6 +41,7 @@ include make.d/metadata.make
# $(Metadata)/config.json
# $(Metadata)/site.json
# $(Metadata)/globals.make
# $(Metadata)/pages/**.json

# Build metadata from introspection
ifdef __globals__
Expand All @@ -57,7 +58,8 @@ endif
# NodesJSON
# Targets:
# $(Destination)
# all paths from $(Destination) and $(Metadata)
# all paths at $(Destination) and $(Metadata)
# each page from his metadata

endif # not clobbering

Expand Down Expand Up @@ -132,17 +134,17 @@ Targets := $(Pages) $(Files) $(ManPage)
$(Pages): \
$(Blocks)/*/markup.html \
$(Blocks)/filters.jq \
$(Content)/LINKS.txt \
$(Content)/macros.m \
$(Content)/LINKS.txt \
$(Metadata)/snippets.json \
$(Metadata)/config.json \

# All pages except home page
other_pages := $(filter-out $(HomePage),$(Pages))
$(other_pages): \
$(Content)/FLOW.txt \
$(Layouts)/page.html \
$(Content)/opt/*.txt \
$(Layouts)/page.html \

$(HomePage) \
$(Destination)/structure.html: \
Expand All @@ -162,12 +164,10 @@ endif # __globals__

ifdef __globals__

# Default target
# Default target (always try to copy assets)
all: $(Targets)
# Copy assets
@cp --verbose --recursive --update $(Assets)/* $(Destination) \
| sed "s/^.*-> ./==> /;s/.$$//"
# All done
@echo 1>&2 'Imprimatur.'

# Snippets
Expand Down Expand Up @@ -238,10 +238,14 @@ endif # __globals__
# External utilities
########################################################################

ifdef __globals__

# help and other targets
include make.d/tools.make

# HTML 5 validation
include make.d/vnu.make

endif # __globals__

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
1 change: 1 addition & 0 deletions docs/content/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Authoring content in jqt using MarkDown
description: jqt transforms MarkDown documents to HTML using Pandoc.
keywords: jqt, markdown, pandoc, gpp, preprocessing, authoring content
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4DdiT].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
1 change: 1 addition & 0 deletions docs/content/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Managing the data model with jqt
description: jqt combines one template with one MarkDown document and a data model.
keywords: jqt, JSON, YAML, gpp, preprocessing, data model
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[DeIMmnPRT].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
1 change: 1 addition & 0 deletions docs/content/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: The jqt template engine
description: jqt orchestrates several shell utilities to transform MarkDown text and YAML or JSON data into a final HTML page.
keywords: jqt, jq, YAML, gpp, preprocessing, template engine
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4CDdeHhIijLMmnPprSTtVw].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
1 change: 1 addition & 0 deletions docs/content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Welcome to jqt
description: Could be jq the basis for a web template engine?
keywords: jqt, jq, template engine
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/EXAMPLE.txt]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
1 change: 1 addition & 0 deletions docs/content/structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ title: Defining the page structure with jqt
description: Web pages structure is defined by the HTML macros.
keywords: jqt, jq, gpp, preprocessing, template engine
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/EXAMPLE.txt, content/FLOW.txt, "content/opt/[DIijL].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
143 changes: 67 additions & 76 deletions docs/make.d/config.make
Original file line number Diff line number Diff line change
Expand Up @@ -2,92 +2,83 @@
# Configuration
########################################################################

# Exported macros:
# comma
# empty
# space
# rest
# Imported variables:
# Metadata
# Version
# Exported targets:
# $(Metadata)
# $(Metadata)/config.json
# $(Metadata)/site.json
# $(Metadata)/globals.make
# Order of dependencies:
# globals.make => site.json => config.json => config.yaml

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

#
# Prerequisites
# Target files
#

# We are using some of the newest GNU Make features... so require GNU
# Make version >= 3.82
version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82)))
ifndef version_test
$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed)
endif

# Only one target at the same time
MAKECMDGOALS ?= all

# Check 'root' intentions
ifeq (,$(filter install uninstall,$(MAKECMDGOALS)))
ifeq (0,$(shell id --user))
$(error Root only can make "(un)install" targets)
endif
SUDO :=
else
SUDO := sudo
endif

# Target 'clobber' must be alone
ifeq (clobber,$(filter clobber,$(MAKECMDGOALS)))
ifneq (1,$(words $(MAKECMDGOALS)))
$(error Target "clobber" must be alone)
endif
endif

#
# Parameters
#
# Create $(Metadata)/config.json
# Input is user defined config.yaml or config.json.
ifeq (config.yaml, $(wildcard config.yaml))

# Disable builtins.
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
# Convert config.yaml to $(Metadata)/config.json
$(Metadata)/config.json: config.yaml \
| $(Metadata)
$(info ==> $@)
@yaml2json < $< > $@

# Warn when an undefined variable is referenced.
MAKEFLAGS += --warn-undefined-variables
else ifeq (config.json, $(wildcard config.json))

# Make will not print the recipe used to remake files.
#.SILENT:
# Convert config.json to $(Metadata)/config.json
$(Metadata)/config.json: config.json \
| $(Metadata)
$(info ==> $@)
@jqt -Pjson < $< > $@

# Eliminate use of the built-in implicit rules. Also clear out the
# default list of suffixes for suffix rules.
.SUFFIXES:

# Sets the default goal to be used if no targets were specified on the
# command line.
.PHONY: all
.DEFAULT_GOAL := all

# Default shell: if we require GNU Make, why not require Bash?
SHELL := /bin/bash

# The argument(s) passed to the shell are taken from the variable
# .SHELLFLAGS.
.SHELLFLAGS := -o errexit -o pipefail -o nounset -c

# Make will delete the target of a rule if it has changed and its recipe
# exits with a nonzero exit status.
.DELETE_ON_ERROR:

# Enable a second expansion of the prerequisites
.SECONDEXPANSION:

#
# Common macros
#
else
$(error Configuration file not found)
endif

# Hacks for string manipulation
comma := ,
empty :=
space := $(empty) $(empty)
# Globals definition to mix with config.json
define m_SITE_JSON :=
del(.defaults) \
| . + { \
Destination: (.Destination // "./_site"), \
Assets: (.Assets // "./assets"), \
Blocks: (.Blocks // "./blocks"), \
Content: (.Content // "./content"), \
Data: (.Data // "./data"), \
Layouts: (.Layouts // "./layouts"), \
Styles: (.Styles // "./styles"), \
Version: (.Version // "$(Version)") \
}
endef

# Hack for list manipulation
define rest =
$(wordlist 2,2147483648,$1)
$(Metadata)/site.json: $(Metadata)/config.json
$(info ==> $@)
@jq --sort-keys '$(m_SITE_JSON)' < $< > $@

# Variables to define in globals.make
define m_GLOBALS_MAKE :=
"__globals__ := 1", \
"Assets := " + .Assets, \
"Blocks := " + .Blocks, \
"Content := " + .Content, \
"Data := " + .Data, \
"Destination := " + .Destination, \
"Layouts := " + .Layouts, \
"Styles := " + .Styles, \
"# vim:syntax=make"
endef

# Create globals.make
$(Metadata)/globals.make: $(Metadata)/site.json
$(info ==> $@)
@jq --raw-output '$(m_GLOBALS_MAKE)' < $< > $@

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

0 comments on commit 4bff2b1

Please sign in to comment.