Skip to content

Commit

Permalink
Generate site.json
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 6, 2017
1 parent c474a55 commit 10a8e24
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 60 deletions.
33 changes: 28 additions & 5 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ include make.d/config.make
# Metadata directory
Metadata := .yummy

# jqt/yummy version
Version := $(shell cat ../VERSION)

# Load global parameters
# As a side effect config.json and site.json are built
-include $(Metadata)/globals.make

# Defined in globals.make:
# Defined in globals.make
# =======================
# Variables:
# __globals__
# Assets
# Blocks
Expand All @@ -28,15 +34,31 @@ ifneq (clobber,$(MAKECMDGOALS))
# Define targets for basic metadata
include make.d/metadata.make

# Defined in metadata.make
# ========================
# Targets:
# $(Metadata)
# $(Metadata)/config.json
# $(Metadata)/site.json
# $(Metadata)/globals.make

# Build metadata from introspection
ifdef __globals__
include make.d/introspect.make
endif

# Defined in introspect.make:
# Defined in introspect.make
# ==========================
# Variables:
# HomePage
# Pages
# OtherPages
# PagesJSON
# Nodes
# NodesJSON
# Targets:
# $(Destination)
# all paths at $(Destination) and $(Metadata)

endif # not clobbering

Expand Down Expand Up @@ -109,15 +131,16 @@ Targets := $(Pages) $(Files) $(ManPage)
# Extra dependencies
#

$(Pages): \
# All pages
$(Pages): \
$(Blocks)/*/markup.html \
$(Blocks)/filters.jq \
$(Content)/LINKS.txt \
$(Content)/macros.m \
$(Metadata)/config.json \
$(Metadata)/snippets.json \
$(Metadata)/config.json \


# All pages except home page
$(OtherPages): \
$(Content)/FLOW.txt \
$(Layouts)/page.html \
Expand Down
12 changes: 10 additions & 2 deletions docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ Layouts: ./blocks # shared space

title: jqt, the jq template engine
baseURL: https://fadado.github.com/jqt/
lang: en
lang: &lang en
logo: "❴❴❏❵❵"

author:
- email: [email protected]
name: Joan Josep Ordinas Rosa
name: &author Joan Josep Ordinas Rosa

# TODO: instrospect
menu:
Expand All @@ -55,5 +55,13 @@ menu:
path: content/data.md
name: Data

# Default values
defaults:
- idprefix: "" # all files
properties:
title-prefix: jqt
author: *author
lang: *lang

# vim:ts=2:sw=2:ai:et:fileencoding=utf8:syntax=yaml
...
51 changes: 28 additions & 23 deletions docs/make.d/introspect.make
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,44 @@
# HomePage
# Pages
# OtherPages
# ...
# PagesJSON
# Nodes
# NodesJSON
# Targets for:
# $(Destination)
# all paths at $(Destination) and $(Metadata)

# Markdown documents found in the filesystem (only .md extensions)
_documents := $(sort $(shell find $(Content) -type f -a -name '*.md'))
i_documents := $(sort $(shell find $(Content) -type f -a -name '*.md'))

# Unique paths to documents directories
_paths := $(sort $(dir $(_documents)))
i_paths := $(sort $(dir $(i_documents)))

# Paths to create at $(Destination)
_paths_destination := $(patsubst $(Content)%,$(Destination)%,$(_paths))
i_paths_destination := $(patsubst $(Content)%,$(Destination)%,$(i_paths))

# Paths to nodes at $(Metadata)
_paths_meta_nodes := $(patsubst $(Content)%,$(Metadata)/nodes%,$(_paths))
i_paths_meta_nodes := $(patsubst $(Content)%,$(Metadata)/nodes%,$(i_paths))

# Paths to pages at $(Metadata)
_paths_meta_pages := $(patsubst $(Content)%,$(Metadata)/pages%,$(_paths))
i_paths_meta_pages := $(patsubst $(Content)%,$(Metadata)/pages%,$(i_paths))

#
# Make directories
#

$(Destination):
$(info ==> $@)
@mkdir $@ >/dev/null 2>&1 || true
@mkdir -p $@ >/dev/null 2>&1 || true

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

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

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

#
# Global names defined
Expand All @@ -52,17 +57,17 @@ $(_paths_meta_nodes): $(Metadata)/nodes/% : $(Content)/%
HomePage := $(Destination)/index.html

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

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

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

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

#########################################################################
# Test
Expand All @@ -71,18 +76,18 @@ intro:
@echo 'Content: $(Content)'
@echo 'Destination: $(Destination)'
@echo
@echo '_documents: $(_documents)'
@echo '_paths: $(_paths)'
@echo 'i_documents: $(i_documents)'
@echo 'i_paths: $(i_paths)'
@echo
@echo '_paths_meta_nodes: $(_paths_meta_nodes)'
@echo '_paths_meta_pages: $(_paths_meta_pages)'
@echo '_paths_destination: $(_paths_destination)'
@echo 'i_paths_meta_nodes: $(i_paths_meta_nodes)'
@echo 'i_paths_meta_pages: $(i_paths_meta_pages)'
@echo 'i_paths_destination: $(i_paths_destination)'
@echo
@echo 'HomePage: $(HomePage)'
@echo 'Pages: $(Pages)'
@echo 'OtherPages: $(OtherPages)'
@echo 'PagesJSON: $(PagesJSON)'
@echo 'NodesHTML: $(NodesHTML)'
@echo 'Nodes: $(Nodes)'
@echo 'NodesJSON: $(NodesJSON)'

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
72 changes: 42 additions & 30 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,65 @@

# Imported variables:
# Metadata
# Version
# Targets for:
# $(Metadata)
# $(Metadata)/config.json ==>
# $(Metadata)/site.json ==>
# $(Metadata)/globals.make

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

#
# Configuration files
# config.json, site.json and globals.make
#

# Members to mix with config.yaml when converted to JSON
define JSON_GLOBALS :=
. + { \
Destination: (.Destination // "./_site"), \
Assets: (.Assets // "./assets"), \
Blocks: (.Blocks // "./blocks"), \
Content: (.Content // "./content"), \
Data: (.Data // "./data"), \
Layouts: (.Layouts // "./layouts"), \
Styles: (.Styles // "./styles") \
}
endef

# Main configuration file.
# Must be named config.yaml or config.json and must exist.
# Create $(Metadata)/config.json
# Input is user defined config.yaml or config.json.
ifeq (config.yaml, $(wildcard config.yaml))

# Convert config.yaml to $(Metadata)/config.json
$(Metadata)/config.json: config.yaml \
| $(Metadata)
$(info ==> $@)
@yaml2json < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@
@yaml2json < $< > $@

else ifeq (config.json, $(wildcard config.json))

# Convert config.json to $(Metadata)/config.json
$(Metadata)/config.json: config.json \
| $(Metadata)
$(info ==> $@)
@jqt -Pjson < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@
@jqt -Pjson < $< > $@

else
$(error Configuration file not found)
endif

# 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

$(Metadata)/site.json: $(Metadata)/config.json
$(info ==> $@)
@jq --sort-keys '$(m_SITE_JSON)' < $< > $@

# Variables to define in globals.make
define MAKE_GLOBALS :=
define m_MAKE_GLOBALS :=
"__globals__ := 1", \
"Destination := " + .Destination, \
"Assets := " + .Assets, \
Expand All @@ -64,24 +74,26 @@ define MAKE_GLOBALS :=
"# vim:syntax=make"
endef

# Create makefile with globals
$(Metadata)/globals.make: $(Metadata)/config.json
# Create globals.make
$(Metadata)/globals.make: $(Metadata)/site.json
$(info ==> $@)
@jq --sort-keys \
--raw-output \
'$(MAKE_GLOBALS)' \
@jq --raw-output \
'$(m_MAKE_GLOBALS)' \
< $< > $@

ifdef __globals__

# TODO: rest of metadata files...

#
# TODO: in this file???
# Metadata files built with globals defined
#

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

endif # __globals__
Expand Down

0 comments on commit 10a8e24

Please sign in to comment.