2 Commits

+47 -10
View File
@@ -260,19 +260,56 @@ for index, _ in ipairs(markdownFiles) do
end
markdownFiles[index].content = styling(markdownFiles[index].content)
-- replace <!-- sitecontents --> with markdown file content
local start_idx, end_idx = content:find("<!-- sitecontents -->", 1, true)
if start_idx and end_idx then
local first = content:sub(1, start_idx - 1)
local second = content:sub(end_idx + 1)
content = first .. markdownFiles[index].content .. second
end
while content:find("<!-- title -->", 1, true) do
start_idx, end_idx = content:find("<!-- title -->", 1, true)
-- start_idx, end_idx = c
-- {{pageContent}} shortcode
content = content:gsub("{{pageContent}}", markdownFiles[index].content)
-- {{pageTitle}} shortcode
content = content:gsub("{{pageTitle}}", markdownFiles[index].options["title"])
local start_idx, end_idx
-- list shortcodes
while content:find("{{list:}}", 1, true) do
start_idx, end_idx = content:find("{{list:}}")
if start_idx and end_idx then
local first = content:sub(1, start_idx - 1)
local second = content:sub(end_idx + 1)
content = first .. markdownFiles[index].options["title"] .. second
if second:find("{{:list}}", 1, true) then
start_idx, end_idx = second:find("{{:list}}")
if start_idx and end_idx then
local shortcode = second:sub(1, start_idx - 1)
local third = second:sub(end_idx + 1)
local function formatShortcode(element)
local dir = markdownFiles[index].filePath:match("(.*)/[^/]+%.md$")
local results = {}
for mdfile in lfs.dir(dir) do
if mdfile:match("%.md$") and mdfile ~= markdownFiles[index].fileName .. ".md" then
local fileName = mdfile:match("(.-)%.md$")
for i, _ in ipairs(markdownFiles) do
if markdownFiles[i].fileName == fileName then
local copy = element
-- replace items starting with list.item.
for option in copy:gmatch("{{list%.item%.(.-)}}") do
local value = markdownFiles[i].options[option]
if value then
copy = copy:gsub("{{list%.item%." .. option .. "}}", value)
end
end
table.insert(results, copy)
end
end
end
end
return table.concat(results, "\n")
end
shortcode = formatShortcode(shortcode)
content = first .. shortcode .. third
end
end
end
end