Skip to content

Commit

Permalink
Defined "pages" filter
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 21, 2017
1 parent e2381d7 commit 835f6ee
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The tools used in the implementation of _jqt_ are:
If you want to learn how to use _jqt_ visit the site
<https://fadado.github.io/jqt/>. The site pages are generated using _jqt_ in
the [`docs`](./docs/) folder of this repository.
If you are interested in _jq_ you can see also [JBOL](https://fadado.github.io/jbol/),
If you are interested in _jqt_ you can see also [JBOL](https://github.com/fadado/jbol),
a related project with a collection of modules for the _jq_ language.

_jqt_ is developed under the _Fedora_ Linux distribution, and a lot of
Expand Down
2 changes: 1 addition & 1 deletion docs/blocks/body/_blog/markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Body for blog posts
######################################################################>&
<main class="#body">
{% $pages::pages[0][] | select(.section=="blog") %}<#TODO: sort?#>
{% pages[] | select(.section=="blog") %}<#TODO: sort?#>
<div class="post-excerpt">
<a class="post-excerpt__title" href="{{.base}}{{.url}}">{{.title}}</a>
<p class="post-excerpt__test">{{.description}}
Expand Down
10 changes: 10 additions & 0 deletions docs/blocks/filters.jq
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
# Extra filters for this site
#

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

# Remove XML tags
def striptags:
# warning: algorithm too simplistic
gsub("<[^>]*>"; "")
;

def pages:
$pages::pages[0]
;

def sections:
[pages[].section] | unique | map(select(.))
;

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq
4 changes: 2 additions & 2 deletions docs/blocks/menu-bar/markup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Menu Bar
######################################################################>&
<ol class="menu-bar">
{% $pages::pages[0] as $pages | .site.menu[] %}
{% .site.menu[] %}
<li class='menu-bar__item {{if .==$M.page.id then "menu-bar__item_current" else "" end}}'>
{% (. as $id | $pages[] | select($id == .id)) as $page %}
{% (. as $id | pages[] | select($id == .id)) as $page %}
<a href="{{$M.page.base}}{{$page.url}}">{{$page.name}}</a>
{% end %}
</li>
Expand Down
7 changes: 7 additions & 0 deletions docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,12 @@ defaults:
author: *author
lang: *lang

# data:
# - snippets

# TODO: explore flags here!
# flags:
# - -msnippets:$(Metadata)/snippets.json

# vim:ts=2:sw=2:ai:et:fileencoding=utf8:syntax=yaml
...
9 changes: 2 additions & 7 deletions docs/make.d/data.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
# $(DestinationPaths)
# $(MetadataPaths)
# $(MetadataPages)
# $(Metadata)/pages.json
# $(Metadata)/sections.json
# $(Metadata)/collected-front-matter.json
# $(DataFiles)
# Targets:
# init
Expand Down Expand Up @@ -99,14 +98,10 @@ $(MetadataPaths):
# Group metadata
########################################################################

$(Metadata)/pages.json: $(MetadataPages)
$(Metadata)/collected-front-matter.json: $(MetadataPages)
$(info ==> $@)
@jq --slurp '.' $^ > $@

$(Metadata)/sections.json: $(Metadata)/pages.json
$(info ==> $@)
@jq '[.[].section] | unique | map(select(.))' < $< > $@

########################################################################
# Files derived from $(Data)/*
########################################################################
Expand Down
8 changes: 4 additions & 4 deletions 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)/pages.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
$(Metadata)/phase3.make: $(Metadata)/collected-front-matter.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
$(info ==> $@)
@jq --raw-output \
--arg Metadata $(Metadata) \
Expand All @@ -34,9 +34,9 @@ ifdef __phase_3
#

define JQTFLAGS :=
-msite:$(Metadata)/config.json \
-j'$$'pages:$(Metadata)/pages \
-I./
-msite:$(Metadata)/site.json \
-I./ -L$(Metadata) -L$(Blocks) \
-ifilters
endef

JQT = jqt $(JQTFLAGS)
Expand Down
10 changes: 9 additions & 1 deletion docs/make.d/phase3.jq
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def use:
else "" end
;

def flags:
if .flags then .flags | join(" ") else "" end
;

def data:
if .data then .data | map("-m\(.):$(Metadata)/snippets.json") | join(" ") else "" end
;

########################################################################
# Output makefile
########################################################################
Expand All @@ -20,7 +28,7 @@ def use:
(.[] | (
$Destination+"/"+.url+": "+.source+" "+$Layouts+"/"+.layout+".html"+use,
"\t$(info ==> $@)",
"\t@$(JQT) -mpage:"+$Metadata+"/pages/"+.id+".json -d $< "+$Layouts+"/"+.layout+".html | $(DETAILS) > $@"
"\t@$(JQT) "+data+" "+flags+" -mpage:"+$Metadata+"/pages/"+.id+".json -d $< "+$Layouts+"/"+.layout+".html | $(DETAILS) > $@"
)
),
comment
Expand Down
2 changes: 1 addition & 1 deletion docs/make.d/sitemap.make
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define SITEMAP.jq
"</urlset>"
endef

$(Destination)/sitemap.xml: $(Metadata)/pages.json $(Metadata)/site.json \
$(Destination)/sitemap.xml: $(Metadata)/collected-front-matter.json $(Metadata)/site.json \
| $(Destination)
$(info ==> $@)
@jq --raw-output --slurpfile site $(Metadata)/site.json '$(SITEMAP.jq)' < $< > $@
Expand Down
14 changes: 3 additions & 11 deletions docs/project.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,10 @@
# Build pages options
########################################################################

# Declare explicitly modules with -m, -M or -j; this must be decided by a
# human!
JQTFLAGS += -msnippets:$(Metadata)/snippets.json
JQTFLAGS += -msnippets:$(Metadata)/snippets.json

# Options for `jqt`.
JQTFLAGS += \
-5 \
--toc-depth=4 \
-iblocks/filters \

# only for derived nodes?
# -msections:$(Metadata)/sections.json \
# Pandoc options
JQTFLAGS += -5 --toc-depth=4

# Extra dependencies
#?$(DestinationPages): $(Blocks)/filters.jq $(Blocks)/*/*.html $(Blocks)/*/*/*.html
Expand Down

0 comments on commit 835f6ee

Please sign in to comment.