feat: use the html file named same as the md file for template if exists
known bug: /public/ directory doesn't cleaned before recreating html files
This commit is contained in:
@@ -12,20 +12,32 @@ for file in lfs.dir(currentDir) do
|
||||
-- ignore "." and ".." files
|
||||
if not(file:sub(1,2) == ".." or file:sub(1,1) == '.') then
|
||||
local filePath = currentDir .. '/' .. file
|
||||
-- match file names ending with ".md"
|
||||
if file:match("index.md") then haveIndexmd = true end
|
||||
if file:match("index.html") then haveIndexhtml = true end
|
||||
-- match file names ending with ".md"
|
||||
if file:match("%.md$") then
|
||||
markdownFileCount = markdownFileCount + 1
|
||||
markdownFiles[markdownFileCount] = {
|
||||
options = {},
|
||||
filePath = filePath,
|
||||
fileName = file:sub(1, file:len()-3),
|
||||
content = ""
|
||||
content = "",
|
||||
hasHtml = false
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
-- check html files with same name as the md files
|
||||
for file in lfs.dir(currentDir) do
|
||||
if file:match("%.html$") then
|
||||
for index, value in ipairs(markdownFiles) do
|
||||
if file:match(value.fileName .. ".html") then
|
||||
markdownFiles[index].hasHtml = true
|
||||
print(value.fileName .. "file has a html template file.")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- stop the program if "index.html" or "index.md" doesn't exist
|
||||
if (not(haveIndexhtml) and not(haveIndexmd)) then return print("Can't find index.html or index.md!") end
|
||||
@@ -121,6 +133,7 @@ for index, _ in ipairs(markdownFiles) do
|
||||
local htmlFile = io.open(workDir .. "/public/" .. markdownFiles[index].fileName .. ".html", 'w')
|
||||
if htmlFile then
|
||||
local content = indexFile
|
||||
if markdownFiles[index].hasHtml then content = io.open(markdownFiles[index].fileName .. ".html"):read("*all") end
|
||||
|
||||
-- STYLING
|
||||
local function styleLists(s)
|
||||
|
||||
Reference in New Issue
Block a user