Allow implicit cover images
This commit is contained in:
parent
8686fd9bae
commit
63c38e3fec
1 changed files with 17 additions and 10 deletions
|
@ -7,11 +7,11 @@ local string = require 'stringplus'
|
||||||
|
|
||||||
local function parsedate(date)
|
local function parsedate(date)
|
||||||
local year, month, day = date:match("(%d+)%-(%d+)%-(%d+)")
|
local year, month, day = date:match("(%d+)%-(%d+)%-(%d+)")
|
||||||
return os.time {
|
return os.time {
|
||||||
year = tonumber(year) or error("Invalid date string: " .. date);
|
year = tonumber(year) or error("Invalid date string: " .. date);
|
||||||
month = tonumber(month) or error("Invalid date string: " .. date);
|
month = tonumber(month) or error("Invalid date string: " .. date);
|
||||||
day = tonumber(day) or error("Invalid date string: " .. date);
|
day = tonumber(day) or error("Invalid date string: " .. date);
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local validate_head do
|
local validate_head do
|
||||||
|
@ -27,11 +27,18 @@ end
|
||||||
|
|
||||||
local function read_post(file)
|
local function read_post(file)
|
||||||
local content = io.open(file):read("*a")
|
local content = io.open(file):read("*a")
|
||||||
local head, body = restia.utils.frontmatter(content)
|
local head_text, body_text = restia.utils.frontmatter(content)
|
||||||
return {
|
|
||||||
head = head and yaml.load(head) or {};
|
local head = head_text and yaml.load(head_text) or {}
|
||||||
body = cmark.render_html(cmark.parse_document(body, #body, cmark.OPT_DEFAULT), cmark.OPT_DEFAULT + cmark.OPT_UNSAFE);
|
local body = cmark.render_html(cmark.parse_document(body_text, #body_text, cmark.OPT_DEFAULT), cmark.OPT_DEFAULT + cmark.OPT_UNSAFE)
|
||||||
}
|
|
||||||
|
local cover_image = file:gsub("md$", "jpg")
|
||||||
|
if io.open(cover_image) then
|
||||||
|
head.cover_image = "/images/" .. cover_image:match("[^/]+$")
|
||||||
|
print(head.cover_image)
|
||||||
|
end
|
||||||
|
|
||||||
|
return { head = head, body = body }
|
||||||
end
|
end
|
||||||
|
|
||||||
local posts = {}
|
local posts = {}
|
||||||
|
|
Loading…
Reference in a new issue