summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/common.lua34
-rw-r--r--scripts/metadata.lua13
-rw-r--r--scripts/page.lua11
3 files changed, 35 insertions, 23 deletions
diff --git a/scripts/lib/common.lua b/scripts/lib/common.lua
index ee7c6aa..d3c6c44 100644
--- a/scripts/lib/common.lua
+++ b/scripts/lib/common.lua
@@ -1,15 +1,4 @@
1function dump(o) 1local utils = require 'pandoc.utils'
2 if type(o) == 'table' then
3 local s = '{ '
4 for k, v in pairs(o) do
5 if type(k) ~= 'number' then k = '"' .. k .. '"' end
6 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
7 end
8 return s .. '} '
9 else
10 return tostring(o)
11 end
12end
13 2
14function string.split(str, sep) 3function string.split(str, sep)
15 sep = sep or '%s' 4 sep = sep or '%s'
@@ -82,6 +71,25 @@ function pandoc.List:shuffle()
82 return self 71 return self
83end 72end
84 73
74function dump(o)
75 if type(o) == 'table' then
76 local s = '{ '
77 for k, v in pairs(o) do
78 if type(k) ~= 'number' then k = '"' .. k .. '"' end
79 s = s .. '[' .. k .. '] = ' .. dump(v) .. ','
80 end
81 return s .. '} '
82 else
83 return tostring(o)
84 end
85end
86
87function prep_layout(layout)
88 layout = utils.stringify(layout)
89 return { id = layout, ["is_" .. layout] = true }
90end
91
85return { 92return {
86 dump = dump 93 dump = dump,
94 prep_layout = prep_layout
87} 95}
diff --git a/scripts/metadata.lua b/scripts/metadata.lua
index 9c8a964..843ed3c 100644
--- a/scripts/metadata.lua
+++ b/scripts/metadata.lua
@@ -42,11 +42,6 @@ function resolve_layout(depth)
42 return layout 42 return layout
43end 43end
44 44
45function prep_layout(layout)
46 layout = utils.stringify(layout)
47 return { id = layout, ["is_" .. layout] = true }
48end
49
50function prep_namespace(namespace) 45function prep_namespace(namespace)
51 namespace = utils.stringify(namespace) 46 namespace = utils.stringify(namespace)
52 47
@@ -138,11 +133,11 @@ function process_base(build, meta)
138 meta.title = meta.title and utils.stringify(meta.title) or "" 133 meta.title = meta.title and utils.stringify(meta.title) or ""
139 meta.slug = slug(meta.title) 134 meta.slug = slug(meta.title)
140 meta.schema_type = meta.schema_type or "CreativeWork" 135 meta.schema_type = meta.schema_type or "CreativeWork"
141 meta.list_layout = prep_layout(meta.list_layout or "list") 136 meta.list_layout = common.prep_layout(meta.list_layout or "list")
142 meta.list_order = meta.list_order and utils.stringify(meta.list_order) 137 meta.list_order = meta.list_order and utils.stringify(meta.list_order)
143 meta.position = meta.position and tonumber(utils.stringify(meta.position)) 138 meta.position = meta.position and tonumber(utils.stringify(meta.position))
144 meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. utils.stringify(meta.thumbnail), meta.file_out) 139 meta.thumbnail = meta.thumbnail and make_absolute("thumbnail." .. utils.stringify(meta.thumbnail), meta.file_out)
145 meta.layout = prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth)) 140 meta.layout = common.prep_layout(meta.layout or (meta.redirect and "redirect") or resolve_layout(meta.depth))
146 141
147 meta.show_date = meta.parent and meta.parent.list_order == "date_desc" 142 meta.show_date = meta.parent and meta.parent.list_order == "date_desc"
148 meta.category = meta.parent and meta.parent.title 143 meta.category = meta.parent and meta.parent.title
@@ -179,8 +174,8 @@ function find_pos(meta)
179 174
180 if index == nil then return end 175 if index == nil then return end
181 176
182 meta.prev = index >= 2 and pages[index - 1] or nil 177 meta.prev = index <= #pages - 1 and pages[index + 1] or nil
183 meta.next = index <= #pages - 1 and pages[index + 1] or nil 178 meta.next = index >= 2 and pages[index - 1] or nil
184end 179end
185 180
186function Meta(meta) 181function Meta(meta)
diff --git a/scripts/page.lua b/scripts/page.lua
index 7378bfc..48eef6e 100644
--- a/scripts/page.lua
+++ b/scripts/page.lua
@@ -144,11 +144,20 @@ function generate_related(meta)
144 meta.prev = meta.prev and d1_page_to_list_item(deref(meta.prev)) 144 meta.prev = meta.prev and d1_page_to_list_item(deref(meta.prev))
145 meta.next = meta.next and d1_page_to_list_item(deref(meta.next)) 145 meta.next = meta.next and d1_page_to_list_item(deref(meta.next))
146 146
147 if meta.prev then meta.prev.is_prev = true end
148 if meta.next then meta.next.is_next = true end
149
147 if not meta.prev and not meta.next then return nil end 150 if not meta.prev and not meta.next then return nil end
148 151
152 local layout = meta.parent.list_layout
153 local layout_id = utils.stringify(layout.id)
154 if layout_id ~= "grid-2" and layout_id ~= "gallery-2" then
155 layout = common.prep_layout("grid-2")
156 end
157
149 return { 158 return {
150 url = meta.parent.url, 159 url = meta.parent.url,
151 layout = meta.parent.list_layout, 160 layout = layout,
152 prev = meta.prev, 161 prev = meta.prev,
153 next = meta.next 162 next = meta.next
154 } 163 }