diff options
author | Volpeon <git@volpeon.ink> | 2021-05-27 20:53:44 +0200 |
---|---|---|
committer | Volpeon <git@volpeon.ink> | 2021-05-27 20:53:44 +0200 |
commit | 4df33046d142554c16a8dba9bfcc03c4be157dd9 (patch) | |
tree | 11adbf88e76f8c37cb7a9b7e6e38cdb83e2f4ff5 | |
parent | Rephrased personal section description (diff) | |
download | volpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.tar.gz volpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.tar.bz2 volpeon.ink-4df33046d142554c16a8dba9bfcc03c4be157dd9.zip |
Automatic titlecase for page titles
-rw-r--r-- | content/9thPK7O3xn/index.md | 2 | ||||
-rw-r--r-- | scripts/metadata_filter.lua | 20 |
2 files changed, 18 insertions, 4 deletions
diff --git a/content/9thPK7O3xn/index.md b/content/9thPK7O3xn/index.md index fb6160a..47e789b 100644 --- a/content/9thPK7O3xn/index.md +++ b/content/9thPK7O3xn/index.md | |||
@@ -6,5 +6,3 @@ create_feed: true | |||
6 | 6 | ||
7 | Welcome to the personal section of my website! | 7 | Welcome to the personal section of my website! |
8 | Here you will find content that doesn't belong in the public sections of my website, such as test pages for development purposes or content that's too personal in nature. | 8 | Here you will find content that doesn't belong in the public sections of my website, such as test pages for development purposes or content that's too personal in nature. |
9 | |||
10 | Please avoid sharing anything from here with larger audiences. | ||
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 | ||