diff --git a/env.lua b/env.lua index 3a3d08a..73663aa 100644 --- a/env.lua +++ b/env.lua @@ -4,7 +4,7 @@ local env = {} env.app = { name = "gemwriter", exec_name = "gemwriter", - version = "0.2", + version = "0.3", last_updated = "2022-08-05", } diff --git a/gemwriter.lua b/gemwriter.lua index 5e0d2c2..ef5b156 100644 --- a/gemwriter.lua +++ b/gemwriter.lua @@ -33,7 +33,7 @@ end writer.docs.parse_config = [[ - Read a config file in TOML format and load the values into a table. + Read the config and template files, and load the values into a table. ]] function writer.parse_config(config_file) local lines = util.split_lines(config_file) @@ -107,6 +107,14 @@ function writer.parse_config(config_file) -- Set lang lang = require("lang." .. writer.conf.app_lang) + + -- Custom templates override lang defaults (ignore config) + for name, file in pairs(env.defaults.config_files) do + if name ~= "config" then + local template = util.read_file(writer.conf.config_dir .. "/" .. file) + if template ~= "" then lang[name] = template end + end + end end @@ -301,16 +309,15 @@ function writer.gen_atom_feed() -- Reverse insert log posts, newest first for e = #writer.posts, 1, -1 do feed_post = lang.atom_entry - -- Escape html entities in post contents. "%" is also a special character - -- for string.gsub() and similar functions, and will cause an error if not - -- escaped. - writer.posts[e]["content"] = - util.replace_html_entities(writer.posts[e]["content"]) + writer.posts[e]["content"] = util.replace_feed_entities( + writer.posts[e]["content"]) feed_post = util.replace_vars(feed_post, lang.tpl_vars.post, writer.posts[e]) feed_text = feed_text .. feed_post end feed_text = feed_text .. lang.atom_footer + feed_text = util.replace_feed_entities(feed_text, "post") + util.write_file(writer.conf.cap.gemlog_dir .. "/" .. writer.conf.cap.atom_feed, feed_text) end diff --git a/lang/en.lua b/lang/en.lua index 745f421..71222a2 100644 --- a/lang/en.lua +++ b/lang/en.lua @@ -28,13 +28,13 @@ en.tpl_vars = { en.atom_header = [[ - {{ log_url }} {{ log_title }} {{ log_subtitle }} {{ feed_date }} {{ log_author }} + {{ feed_url }} ]] diff --git a/readme.md b/readme.md index 45a2dfd..2c22147 100644 --- a/readme.md +++ b/readme.md @@ -30,7 +30,8 @@ version Print version info - Clone this repository and change into the directory. Run: ``` - luastatic gemwriter.lua env.lua util.lua lang/en.lua /usr/lib/liblua.so -I/usr/include -o gemwriter + luastatic gemwriter.lua env.lua util.lua lang/en.lua \ + /usr/lib/liblua.so -I/usr/include -o gemwriter ``` The paths to `liblua.so` and the development headers (i.e. diff --git a/util.lua b/util.lua index 4fae930..e4409a3 100644 --- a/util.lua +++ b/util.lua @@ -73,16 +73,24 @@ function util.replace_vars(str, vars, vals) end -function util.replace_html_entities(str) - local html_ents = { +function util.replace_feed_entities(str, mode) + -- Pre-processing before replacing feed variables + -- "%" is a special character for string.gsub() and similar functions, and + -- will cause an error if not escaped. + local ents = { percent = { "%%", "%" }, - less_than = { "<", "<" }, - greater_than = { ">", ">" }, - left_bracket = { "%[", "[" }, - right_bracket = { "%]", "]" }, } + -- Used post-processing of feed variables, remove empty log metadata tags + if mode == "post" then + ents = { + percent = { "%", "%%" }, + author = { " \n \n \n", "" }, + subtitle = { "\n", "" }, + title = { "\n", "" }, + } + end local text = str - for e, c in pairs(html_ents) do + for e, c in pairs(ents) do text = string.gsub(text, c[1], c[2]) end return text