diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/metadata_filter.lua | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/metadata_filter.lua b/scripts/metadata_filter.lua index ebbd6d4..6c3817a 100644 --- a/scripts/metadata_filter.lua +++ b/scripts/metadata_filter.lua | |||
@@ -146,7 +146,7 @@ function process_pages(global, pages_by_id) | |||
146 | pages_list:sort(function(p1, p2) | 146 | pages_list:sort(function(p1, p2) |
147 | if p1.position then | 147 | if p1.position then |
148 | if p2.position then | 148 | if p2.position then |
149 | return p1.position < p2.position | 149 | return tonumber(p1.position) < tonumber(p2.position) |
150 | else | 150 | else |
151 | return true | 151 | return true |
152 | end | 152 | end |
@@ -197,12 +197,28 @@ function pages_last_update(all_pages) | |||
197 | return last_update | 197 | return last_update |
198 | end | 198 | end |
199 | 199 | ||
200 | local titlecase_exceptions = pandoc.List({ | ||
201 | "a", "an", "and", "as", "at", "but", "by", "en", "for", "if", "in", "nor", "of", "on", "or", | ||
202 | "per", "the", "to", "v%.?", "vs%.?", "via", | ||
203 | }) | ||
204 | |||
205 | function titlecase(str) | ||
206 | return str:gsub("(%S)(%S*)(%s*)", function(a, b, space) | ||
207 | local word = a .. b | ||
208 | local is_exception = word:match("%u") or | ||
209 | titlecase_exceptions:find_if( | ||
210 | function(exception) return word:match("^" .. exception .. "$") end) | ||
211 | if is_exception then return word .. space end | ||
212 | return string.upper(a) .. b .. space | ||
213 | end) | ||
214 | end | ||
215 | |||
200 | function process(global, meta) | 216 | function process(global, meta) |
201 | meta.namespace = resolve_namespace(meta.namespace) | 217 | meta.namespace = resolve_namespace(meta.namespace) |
202 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") | 218 | meta.file_out = pandoc.utils.stringify(meta.file_out):gsub("^out", "") |
203 | meta.layout = resolve_layout(meta.layout) | 219 | meta.layout = resolve_layout(meta.layout) |
204 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) | 220 | meta.url = resolve_url(global.site.url, global.file_out, meta.file_out) |
205 | meta.title = (meta.title and pandoc.utils.stringify(meta.title)) or "" | 221 | meta.title = (meta.title and titlecase(pandoc.utils.stringify(meta.title))) or "" |
206 | 222 | ||
207 | if meta.position then meta.position = pandoc.utils.stringify(meta.position) end | 223 | if meta.position then meta.position = pandoc.utils.stringify(meta.position) end |
208 | 224 | ||