diff options
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | scripts/metadata.lua | 89 | ||||
-rw-r--r-- | scripts/pages_content.lua (renamed from scripts/subpages.lua) | 0 |
3 files changed, 56 insertions, 51 deletions
@@ -50,13 +50,13 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
50 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ | 50 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -maxdepth 1 -type f -name "*.md" ! -name "index.md") \ |
51 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) | 51 | $(shell test -d $(patsubst .cache/meta%,content%,$(1)) && find $(patsubst .cache/meta%,content%,$(1)) -mindepth 2 -maxdepth 2 -type f -name "index.md")) |
52 | 52 | ||
53 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/subpages.lua scripts/subpages.jq scripts/metadata.json | .cache/meta | 53 | .cache/meta/%.json: content/%.md $$(call subpages,$$(call namespace,$$@,)) filters/*.lua scripts/pages_content.lua scripts/subpages.jq scripts/metadata.json | .cache/meta |
54 | $(info [META] $< -> $@) | 54 | $(info [META] $< -> $@) |
55 | 55 | ||
56 | mkdir -p $(@D) | 56 | mkdir -p $(@D) |
57 | $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) | 57 | $(eval PAGES_FILES = $(filter .cache/meta/%.json,$^)) |
58 | $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) | 58 | $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) |
59 | $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{}" > "$@.pages") | 59 | $(if $(PAGES_FILES),jq -s --arg namespace "$(NAMESPACE)" -f scripts/subpages.jq $(PAGES_FILES) > "$@.pages",echo "{ \"pages\": [] }" > "$@.pages") |
60 | pandoc \ | 60 | pandoc \ |
61 | -f markdown-citations-implicit_figures \ | 61 | -f markdown-citations-implicit_figures \ |
62 | -t html5 \ | 62 | -t html5 \ |
@@ -65,7 +65,7 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
65 | --metadata-file "$@.pages" \ | 65 | --metadata-file "$@.pages" \ |
66 | --template scripts/metadata.json \ | 66 | --template scripts/metadata.json \ |
67 | --metadata namespace="$(NAMESPACE)" \ | 67 | --metadata namespace="$(NAMESPACE)" \ |
68 | --metadata file_out="$(patsubst .cache/meta/%.json,out/%.html,$@)" \ | 68 | --metadata file_out="$(patsubst .cache/meta/%.json,/%.html,$@)" \ |
69 | $(PANDOC_FILTERS) \ | 69 | $(PANDOC_FILTERS) \ |
70 | -o "$@.meta" "$<" | 70 | -o "$@.meta" "$<" |
71 | rm "$@.pages" | 71 | rm "$@.pages" |
@@ -74,11 +74,11 @@ subpages = $(patsubst content/%.md,.cache/meta/%.json, \ | |||
74 | -t html5 \ | 74 | -t html5 \ |
75 | --wrap preserve \ | 75 | --wrap preserve \ |
76 | --lua-filter scripts/metadata.lua \ | 76 | --lua-filter scripts/metadata.lua \ |
77 | --lua-filter scripts/subpages.lua \ | 77 | --lua-filter scripts/pages_content.lua \ |
78 | $(GLOBAL_METADATA) \ | 78 | $(GLOBAL_METADATA) \ |
79 | --metadata-file "$@.meta" \ | 79 | --metadata-file "$@.meta" \ |
80 | --metadata build.mode="$(MODE)" \ | 80 | --metadata build.mode="$(MODE)" \ |
81 | --metadata build.file_out="$@" \ | 81 | --metadata build.file_out="$(patsubst .cache/meta/%.json,/%.html,$@)" \ |
82 | $(PANDOC_FILTERS) \ | 82 | $(PANDOC_FILTERS) \ |
83 | -o "$@.content" "$<" | 83 | -o "$@.content" "$<" |
84 | jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" | 84 | jq '. + { content: $$content }' --rawfile content "$@.content" "$@.meta" > "$@" |
@@ -92,6 +92,7 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT | |||
92 | $(info [MARK] $< -> $@) | 92 | $(info [MARK] $< -> $@) |
93 | 93 | ||
94 | mkdir -p $(@D) | 94 | mkdir -p $(@D) |
95 | $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) | ||
95 | pandoc \ | 96 | pandoc \ |
96 | -f markdown-citations-implicit_figures \ | 97 | -f markdown-citations-implicit_figures \ |
97 | -t html5 \ | 98 | -t html5 \ |
@@ -103,7 +104,8 @@ out/%.html: content/%.md .cache/meta/%.json .cache/assets.json $(CONTENT_TEMPLAT | |||
103 | --metadata-file .cache/assets.json \ | 104 | --metadata-file .cache/assets.json \ |
104 | --metadata-file "$(filter .cache/meta/%.json,$^)" \ | 105 | --metadata-file "$(filter .cache/meta/%.json,$^)" \ |
105 | --metadata build.mode="$(MODE)" \ | 106 | --metadata build.mode="$(MODE)" \ |
106 | --metadata build.file_out="$@" \ | 107 | --metadata build.namespace="$(NAMESPACE)" \ |
108 | --metadata build.file_out="$(patsubst out/%,/%,$@)" \ | ||
107 | $(PANDOC_FILTERS) \ | 109 | $(PANDOC_FILTERS) \ |
108 | -o "$@" "$<" | 110 | -o "$@" "$<" |
109 | 111 | ||
@@ -111,6 +113,7 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml | |||
111 | $(info [FEED] $< -> $@) | 113 | $(info [FEED] $< -> $@) |
112 | 114 | ||
113 | mkdir -p $(@D) | 115 | mkdir -p $(@D) |
116 | $(eval NAMESPACE = $(call namespace,$@,.cache/meta)) | ||
114 | pandoc \ | 117 | pandoc \ |
115 | -f markdown-citations-implicit_figures \ | 118 | -f markdown-citations-implicit_figures \ |
116 | -t html5 \ | 119 | -t html5 \ |
@@ -121,7 +124,8 @@ out/%.xml: content/%.md .cache/meta/%.json $(FEED_TEMPLATES_SRC) metadata/*.yaml | |||
121 | $(GLOBAL_METADATA) \ | 124 | $(GLOBAL_METADATA) \ |
122 | --metadata-file "$(filter .cache/meta/%.json,$^)" \ | 125 | --metadata-file "$(filter .cache/meta/%.json,$^)" \ |
123 | --metadata build.mode="$(MODE)" \ | 126 | --metadata build.mode="$(MODE)" \ |
124 | --metadata build.file_out="$@" \ | 127 | --metadata build.namespace="$(NAMESPACE)" \ |
128 | --metadata build.file_out="$(patsubst out/%,/%,$@)" \ | ||
125 | $(PANDOC_FILTERS) \ | 129 | $(PANDOC_FILTERS) \ |
126 | -o "$@" "$<" | 130 | -o "$@" "$<" |
127 | 131 | ||
diff --git a/scripts/metadata.lua b/scripts/metadata.lua index cb6c6e6..7d9206f 100644 --- a/scripts/metadata.lua +++ b/scripts/metadata.lua | |||
@@ -111,8 +111,8 @@ function process_pages(global, build, order, pages_by_id) | |||
111 | local pages_date_desc = pandoc.List() | 111 | local pages_date_desc = pandoc.List() |
112 | 112 | ||
113 | if pages_by_id then | 113 | if pages_by_id then |
114 | for _, page in pairs(pages_by_id) do | 114 | for _, p in pairs(pages_by_id) do |
115 | local p = process(global, build, page) | 115 | process(global, build, p) |
116 | if not p.unlisted then | 116 | if not p.unlisted then |
117 | pages_all:insert(p) | 117 | pages_all:insert(p) |
118 | if p.last_update then pages_date_desc:insert(p) end | 118 | if p.last_update then pages_date_desc:insert(p) end |
@@ -133,19 +133,35 @@ function find_depth(meta) | |||
133 | 133 | ||
134 | local depth = 0 | 134 | local depth = 0 |
135 | 135 | ||
136 | if meta.pages then | 136 | for _, p in pairs(meta.pages) do |
137 | for _, page in pairs(meta.pages) do | 137 | find_depth(p) |
138 | local p = find_depth(page) | 138 | if not p.unlisted then |
139 | if not p.unlisted then | 139 | local d = p.depth + 1 |
140 | local d = p.depth + 1 | 140 | if d > depth then depth = d end |
141 | if d > depth then depth = d end | ||
142 | end | ||
143 | end | 141 | end |
144 | end | 142 | end |
145 | 143 | ||
146 | meta.depth = depth | 144 | meta.depth = depth |
145 | end | ||
147 | 146 | ||
148 | return meta | 147 | function resolve_urls(global, build, meta) |
148 | meta.url = resolve_url(global.site.url, build.file_out, meta.url) | ||
149 | |||
150 | if meta.feed then | ||
151 | if meta.file_out:match(".html$") then | ||
152 | meta.feed = { | ||
153 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), | ||
154 | } | ||
155 | else | ||
156 | meta.page = { | ||
157 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), | ||
158 | } | ||
159 | end | ||
160 | end | ||
161 | |||
162 | if meta.thumbnail then | ||
163 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) | ||
164 | end | ||
149 | end | 165 | end |
150 | 166 | ||
151 | function d1_page_to_list_item(meta, p) | 167 | function d1_page_to_list_item(meta, p) |
@@ -249,40 +265,20 @@ end | |||
249 | 265 | ||
250 | function process(global, build, meta) | 266 | function process(global, build, meta) |
251 | meta.namespace = resolve_namespace(meta.namespace) | 267 | meta.namespace = resolve_namespace(meta.namespace) |
252 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") | 268 | meta.file_out = pandoc.utils.stringify(meta.file_out) |
253 | meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") | 269 | meta.unlisted = meta.unlisted or (meta.draft and build.mode ~= "dev") |
254 | meta.redirect = meta.url and true | 270 | meta.redirect = meta.url and true |
255 | meta.url = meta.url and pandoc.utils.stringify(meta.url) | 271 | meta.url = meta.url and pandoc.utils.stringify(meta.url) or meta.file_out |
256 | meta.url = resolve_url(global.site.url, build.file_out, meta.url or meta.file_out) | 272 | meta.title = meta.title and pandoc.utils.stringify(meta.title) or "" |
257 | meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" | ||
258 | meta.slug = slug(meta.title) | 273 | meta.slug = slug(meta.title) |
259 | meta.schema_type = (meta.schema_type and pandoc.utils.stringify(meta.schema_type)) or "CreativeWork" | 274 | meta.schema_type = meta.schema_type and pandoc.utils.stringify(meta.schema_type) or "CreativeWork" |
260 | if meta.list_order then meta.list_order = pandoc.utils.stringify(meta.list_order) end | 275 | meta.list_order = meta.list_order and pandoc.utils.stringify(meta.list_order) |
261 | meta.list_layout = prep_layout(meta.list_layout or "list") | 276 | meta.list_layout = prep_layout(meta.list_layout or "list") |
262 | if meta.list_limit then meta.list_limit = tonumber(pandoc.utils.stringify(meta.list_limit)) end | 277 | meta.list_limit = meta.list_limit and tonumber(pandoc.utils.stringify(meta.list_limit)) |
263 | if meta.position then meta.position = tonumber(pandoc.utils.stringify(meta.position)) end | 278 | meta.position = meta.position and tonumber(pandoc.utils.stringify(meta.position)) |
279 | meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), meta.file_out) | ||
264 | 280 | ||
265 | if meta.feed then | 281 | resolve_urls(global, build, meta) |
266 | if meta.file_out:match(".html$") then | ||
267 | meta.feed = { | ||
268 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".html$", ".xml")), | ||
269 | } | ||
270 | else | ||
271 | meta.page = { | ||
272 | url = resolve_url(global.site.url, build.file_out, meta.file_out:gsub(".xml$", ".html")), | ||
273 | } | ||
274 | end | ||
275 | end | ||
276 | |||
277 | if meta.thumbnail then | ||
278 | meta.thumbnail = make_absolute("thumbnail." .. pandoc.utils.stringify(meta.thumbnail), | ||
279 | meta.file_out) | ||
280 | meta.thumbnail = resolve_url(global.site.url, build.file_out, meta.thumbnail) | ||
281 | end | ||
282 | |||
283 | if meta.menus and meta.menus.main then | ||
284 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) | ||
285 | end | ||
286 | 282 | ||
287 | meta.pages = process_pages(global, build, meta.list_order, meta.pages) | 283 | meta.pages = process_pages(global, build, meta.list_order, meta.pages) |
288 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) | 284 | meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) |
@@ -302,10 +298,6 @@ function process(global, build, meta) | |||
302 | end | 298 | end |
303 | 299 | ||
304 | meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd | 300 | meta.was_updated = meta.date and meta.last_update and meta.date.yyyy_mm_dd ~= meta.last_update.yyyy_mm_dd |
305 | |||
306 | meta.list = generate_list(meta) | ||
307 | |||
308 | return meta | ||
309 | end | 301 | end |
310 | 302 | ||
311 | function Meta(meta) | 303 | function Meta(meta) |
@@ -316,11 +308,20 @@ function Meta(meta) | |||
316 | 308 | ||
317 | if suffix then | 309 | if suffix then |
318 | build[suffix] = value | 310 | build[suffix] = value |
311 | meta[key] = nil | ||
319 | end | 312 | end |
320 | end | 313 | end |
321 | 314 | ||
322 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") | 315 | meta.site.url = pandoc.utils.stringify(meta.site.url):gsub("/$", "") |
323 | 316 | ||
324 | find_depth(meta) | 317 | find_depth(meta) |
325 | return process(meta, build, meta) | 318 | process(meta, build, meta) |
319 | |||
320 | meta.list = generate_list(meta) | ||
321 | |||
322 | if meta.menus and meta.menus.main then | ||
323 | meta.menus.main = prep_menu(meta.namespace.root.id, meta.menus.main) | ||
324 | end | ||
325 | |||
326 | return meta | ||
326 | end | 327 | end |
diff --git a/scripts/subpages.lua b/scripts/pages_content.lua index b753b1e..b753b1e 100644 --- a/scripts/subpages.lua +++ b/scripts/pages_content.lua | |||