Fix custom templates not being loaded
- Fix custom templates not being loaded - Remove some empty metadata feed tagspull/1/head
parent
baead4e5f1
commit
a05ee4bd65
2
env.lua
2
env.lua
|
@ -4,7 +4,7 @@ local env = {}
|
||||||
env.app = {
|
env.app = {
|
||||||
name = "gemwriter",
|
name = "gemwriter",
|
||||||
exec_name = "gemwriter",
|
exec_name = "gemwriter",
|
||||||
version = "0.2",
|
version = "0.3",
|
||||||
last_updated = "2022-08-05",
|
last_updated = "2022-08-05",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
writer.docs.parse_config = [[
|
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)
|
function writer.parse_config(config_file)
|
||||||
local lines = util.split_lines(config_file)
|
local lines = util.split_lines(config_file)
|
||||||
|
@ -107,6 +107,14 @@ function writer.parse_config(config_file)
|
||||||
|
|
||||||
-- Set lang
|
-- Set lang
|
||||||
lang = require("lang." .. writer.conf.app_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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -301,16 +309,15 @@ function writer.gen_atom_feed()
|
||||||
-- Reverse insert log posts, newest first
|
-- Reverse insert log posts, newest first
|
||||||
for e = #writer.posts, 1, -1 do
|
for e = #writer.posts, 1, -1 do
|
||||||
feed_post = lang.atom_entry
|
feed_post = lang.atom_entry
|
||||||
-- Escape html entities in post contents. "%" is also a special character
|
writer.posts[e]["content"] = util.replace_feed_entities(
|
||||||
-- for string.gsub() and similar functions, and will cause an error if not
|
writer.posts[e]["content"])
|
||||||
-- escaped.
|
|
||||||
writer.posts[e]["content"] =
|
|
||||||
util.replace_html_entities(writer.posts[e]["content"])
|
|
||||||
feed_post = util.replace_vars(feed_post, lang.tpl_vars.post,
|
feed_post = util.replace_vars(feed_post, lang.tpl_vars.post,
|
||||||
writer.posts[e])
|
writer.posts[e])
|
||||||
feed_text = feed_text .. feed_post
|
feed_text = feed_text .. feed_post
|
||||||
end
|
end
|
||||||
feed_text = feed_text .. lang.atom_footer
|
feed_text = feed_text .. lang.atom_footer
|
||||||
|
feed_text = util.replace_feed_entities(feed_text, "post")
|
||||||
|
|
||||||
util.write_file(writer.conf.cap.gemlog_dir .. "/" ..
|
util.write_file(writer.conf.cap.gemlog_dir .. "/" ..
|
||||||
writer.conf.cap.atom_feed, feed_text)
|
writer.conf.cap.atom_feed, feed_text)
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,13 +28,13 @@ en.tpl_vars = {
|
||||||
|
|
||||||
en.atom_header = [[<?xml version="1.0" encoding="UTF-8"?>
|
en.atom_header = [[<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
<id>{{ log_url }}</id>
|
|
||||||
<title>{{ log_title }}</title>
|
<title>{{ log_title }}</title>
|
||||||
<subtitle>{{ log_subtitle }}</subtitle>
|
<subtitle>{{ log_subtitle }}</subtitle>
|
||||||
<updated>{{ feed_date }}</updated>
|
<updated>{{ feed_date }}</updated>
|
||||||
<author>
|
<author>
|
||||||
<name>{{ log_author }}</name>
|
<name>{{ log_author }}</name>
|
||||||
</author>
|
</author>
|
||||||
|
<id>{{ feed_url }}</id>
|
||||||
<link href="{{ log_url }}" rel="alternate"/>
|
<link href="{{ log_url }}" rel="alternate"/>
|
||||||
<link href="{{ feed_url }}" rel="self" type="application/atom+xml"/>
|
<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:
|
- 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.
|
The paths to `liblua.so` and the development headers (i.e.
|
||||||
|
|
22
util.lua
22
util.lua
|
@ -73,16 +73,24 @@ function util.replace_vars(str, vars, vals)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function util.replace_html_entities(str)
|
function util.replace_feed_entities(str, mode)
|
||||||
local html_ents = {
|
-- 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 = { "%%", "%" },
|
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 = { " <author>\n <name></name>\n </author>\n", "" },
|
||||||
|
subtitle = { "<subtitle></subtitle>\n", "" },
|
||||||
|
title = { "<title></title>\n", "" },
|
||||||
|
}
|
||||||
|
end
|
||||||
local text = str
|
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])
|
text = string.gsub(text, c[1], c[2])
|
||||||
end
|
end
|
||||||
return text
|
return text
|
||||||
|
|
Reference in New Issue