Skip to content

Commit

Permalink
Pages front-matter stored as a stream
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 23, 2017
1 parent 835f6ee commit e4e7c71
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 41 deletions.
6 changes: 3 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ ifdef __phase_1
# MetadataPaths
# Defined rules for:
# $(Metadata)/phase2.make
# $(DataFiles)
# $(DestinationPaths)
# $(MetadataPaths)
# $(Metadata)/pages-by-id.json
# $(MetadataPages)
# $(Metadata)/pages.json
# $(Metadata)/sections.json
# $(MetadataPaths)
# Defined targets:
# init
# ======================================================================
Expand Down
6 changes: 4 additions & 2 deletions docs/blocks/filters.jq
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Extra filters for this site
#

import "collected-front-matter" as $pages;
import "pages-by-id" as $pages;

# Remove XML tags
def striptags:
Expand All @@ -15,7 +15,9 @@ def pages:
;

def sections:
[pages[].section] | unique | map(select(.))
[$pages::pages[0].section]
| unique
| map(select(. != null and . != ""))
;

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq
1 change: 0 additions & 1 deletion docs/content/blog/2017-04-13-hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ description: |
documentation to the JQT site and serve as a test for the build system
used.
keywords: blog, post, jqt, jq, pandoc
#author: Joan Josep Ordinas Rosa
published: "2017-04-13T06:45:07Z"
updated: "2017-04-13T06:45:07Z"
---
Expand Down
11 changes: 6 additions & 5 deletions docs/make.d/data.make
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
# MetadataPaths
# Defined rules for:
# $(Metadata)/phase2.make
# $(DataFiles)
# $(DestinationPaths)
# $(MetadataPaths)
# $(Metadata)/pages-by-id.json
# $(MetadataPages)
# $(Metadata)/collected-front-matter.json
# $(DataFiles)
# $(MetadataPaths)
# Targets:
# init

Expand Down Expand Up @@ -98,9 +98,10 @@ $(MetadataPaths):
# Group metadata
########################################################################

$(Metadata)/collected-front-matter.json: $(MetadataPages)
# Bundle all pages as a relation (id => page)
$(Metadata)/pages-by-id.json: $(MetadataPages)
$(info ==> $@)
@jq --slurp '.' $^ > $@
@jq --slurp 'reduce .[] as $$p ({}; . + {($$p.id): $$p})' $^ > $@

########################################################################
# Files derived from $(Data)/*
Expand Down
2 changes: 1 addition & 1 deletion docs/make.d/pages.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
########################################################################

# Build rules for each page
$(Metadata)/phase3.make: $(Metadata)/collected-front-matter.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
$(Metadata)/phase3.make: $(Metadata)/pages-by-id.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
$(info ==> $@)
@jq --raw-output \
--arg Metadata $(Metadata) \
Expand Down
2 changes: 1 addition & 1 deletion docs/make.d/phase2.jq
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def comment:
;

def dir:
sub("/[^/]+$"; "/")
if test("/") then sub("/[^/]+$"; "/") else "./" end
;

def dpaths($paths):
Expand Down
73 changes: 51 additions & 22 deletions docs/make.d/phase21.jq
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# phase21.jq - --arg Source s --arg Target s --arg Metadata s --slurpfile config s
#
# Generate page.json files
# Generate each page.json files

def basename:
sub("\\.[^/]+$"; "")
;

def dir:
sub("/[^/]+$"; "/")
if test("/") then sub("/[^/]+$"; "/") else "" end
;

def notdir:
Expand All @@ -21,7 +21,6 @@ def page_id:

# `$(Metadata)/pages/path/to/page.json` => `(../)+`
def page_base:
#$(patsubst ../../../%,%,$(subst $(space),$(empty),$(patsubst %,../,$(subst /,$(space),$1))))
("../" * ((($Target / "/") | length) - 3)) // ""
;

Expand All @@ -30,11 +29,6 @@ def page_name:
$Target | notdir | basename
;

# `$(Metadata)/pages/path/to/page.json` => `path/to/page.html`
def page_url:
$Target | page_id+".html"
;

# `$(Metadata)/pages/path/to/page.json` => `path/to/`
def page_path:
$Target | page_id | dir
Expand All @@ -43,27 +37,62 @@ def page_path:
# `$(Metadata)/pages/path/to/page.json` => `path/to`
def page_section:
$Target
| if test("index.json$")
| if test("(?<!/pages)/index.json$") # index but not home page
then null
else page_path[:-1] end
;

def page_slug:
$Target | page_name+".html"
;

def page_date:
page_name |
(capture("^(?<date>\\d{4}-\\d{2}-\\d{2})-") | .date)
// ""
;

########################################################################
# Output object for each page
########################################################################

. + {
base: page_base,
filename: page_name,
id: page_id,
path: page_path,
section: page_section,
source: $Source,
url: page_url
} +
reduce $config[0].defaults[] as $defaults
({}; if page_id | test("^" + $defaults.idprefix)
then . + $defaults.properties
else . end)
def defaults:
reduce $config[0].defaults[] as $d
({}; if page_id | test("^"+$d.idprefix)
then . + $d.properties
else . end)
;

def properties:
{
base: page_base,
date: page_date,
id: page_id,
path: page_path,
section: page_section,
slug: page_slug,
source: $Source,
url: (page_path+page_slug)
}
;

. as $front_matter |

# final object
defaults + properties + $front_matter

# section slug
# ⊢--^-⊣ ⊢--^----⊣
#content/extras/name.html
# ⊢--------v⊣
# ⊢--v--⊣ id
# path

# path slug
# ⊢-------^-----⊣⊢------^--------⊣
#content/extras/indexes/name-example.html
# ⊢------------------v------⊣
# ⊢-----v------⊣ id
# section? or limit to one level?

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq
2 changes: 1 addition & 1 deletion docs/make.d/phase3.jq
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def data:
########################################################################

"__phase_3 := 1",
(.[] | (
(.[] | ( # for each page
$Destination+"/"+.url+": "+.source+" "+$Layouts+"/"+.layout+".html"+use,
"\t$(info ==> $@)",
"\t@$(JQT) "+data+" "+flags+" -mpage:"+$Metadata+"/pages/"+.id+".json -d $< "+$Layouts+"/"+.layout+".html | $(DETAILS) > $@"
Expand Down
8 changes: 3 additions & 5 deletions docs/make.d/sitemap.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,14 @@ define SITEMAP.jq
<urlset xmlns:xsi='\''http://www.w3.org/2001/XMLSchema-instance'\'' \
xsi:schemaLocation='\''http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'\'' \
xmlns='\''http://www.sitemaps.org/schemas/sitemap/0.9'\''>", \
( .[] | \
"\t<url>", \
(.[] | ( "\t<url>", \
"\t\t<loc>" + $$baseurl + "/" + .url + "</loc>", \
"\t\t<lastmod>" + .updated + "</lastmod>", \
"\t</url>" \
), \
"\t</url>")), \
"</urlset>"
endef

$(Destination)/sitemap.xml: $(Metadata)/collected-front-matter.json $(Metadata)/site.json \
$(Destination)/sitemap.xml: $(Metadata)/pages-by-id.json $(Metadata)/site.json \
| $(Destination)
$(info ==> $@)
@jq --raw-output --slurpfile site $(Metadata)/site.json '$(SITEMAP.jq)' < $< > $@
Expand Down

0 comments on commit e4e7c71

Please sign in to comment.