summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorVolpeon <git@volpeon.ink>2021-05-27 20:53:44 +0200
committerVolpeon <git@volpeon.ink>2021-05-27 20:53:44 +0200
commit4df33046d142554c16a8dba9bfcc03c4be157dd9 (patch)
tree11adbf88e76f8c37cb7a9b7e6e38cdb83e2f4ff5 /scripts
parentRephrased personal section description (diff)
downloadvolpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.tar.gz
volpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.tar.bz2
volpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.zip
Automatic titlecase for page titles
Diffstat (limited to 'scripts')
-rw-r--r--scripts/metadata_filter.lua20
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
198end 198end
199 199
200local 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
205function 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)
214end
215
200function process(global, meta) 216function 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