Fix custom templates not being loaded

- Fix custom templates not being loaded
- Remove some empty metadata feed tags
main
mio 6 months ago
parent baead4e5f1
commit a05ee4bd65
  1. 2
      env.lua
  2. 19
      gemwriter.lua
  3. 2
      lang/en.lua
  4. 3
      readme.md
  5. 22
      util.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",
}

@ -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

@ -28,13 +28,13 @@ en.tpl_vars = {
en.atom_header = [[<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>{{ log_url }}</id>
<title>{{ log_title }}</title>
<subtitle>{{ log_subtitle }}</subtitle>
<updated>{{ feed_date }}</updated>
<author>
<name>{{ log_author }}</name>
</author>
<id>{{ feed_url }}</id>
<link href="{{ log_url }}" rel="alternate"/>
<link href="{{ feed_url }}" rel="self" type="application/atom+xml"/>
]]

@ -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.

@ -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 = { "%%", "&#37;" },
less_than = { "<", "&#60;" },
greater_than = { ">", "&#62;" },
left_bracket = { "%[", "&#91;" },
right_bracket = { "%]", "&#93;" },
}
-- Used post-processing of feed variables, remove empty log metadata tags
if mode == "post" then
ents = {
percent = { "&#37;", "%%" },
author = { " <author>\n <name></name>\n </author>\n", "" },
subtitle = { "<subtitle></subtitle>\n", "" },
title = { "<title></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

Loading…
Cancel
Save