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
|
-- ignore "." and ".." files
|
||||||
if not(file:sub(1,2) == ".." or file:sub(1,1) == '.') then
|
if not(file:sub(1,2) == ".." or file:sub(1,1) == '.') then
|
||||||
local filePath = currentDir .. '/' .. file
|
local filePath = currentDir .. '/' .. file
|
||||||
-- match file names ending with ".md"
|
|
||||||
if file:match("index.md") then haveIndexmd = true end
|
if file:match("index.md") then haveIndexmd = true end
|
||||||
if file:match("index.html") then haveIndexhtml = true end
|
if file:match("index.html") then haveIndexhtml = true end
|
||||||
|
-- match file names ending with ".md"
|
||||||
if file:match("%.md$") then
|
if file:match("%.md$") then
|
||||||
markdownFileCount = markdownFileCount + 1
|
markdownFileCount = markdownFileCount + 1
|
||||||
markdownFiles[markdownFileCount] = {
|
markdownFiles[markdownFileCount] = {
|
||||||
options = {},
|
options = {},
|
||||||
filePath = filePath,
|
filePath = filePath,
|
||||||
fileName = file:sub(1, file:len()-3),
|
fileName = file:sub(1, file:len()-3),
|
||||||
content = ""
|
content = "",
|
||||||
|
hasHtml = false
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
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
|
-- 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
|
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')
|
local htmlFile = io.open(workDir .. "/public/" .. markdownFiles[index].fileName .. ".html", 'w')
|
||||||
if htmlFile then
|
if htmlFile then
|
||||||
local content = indexFile
|
local content = indexFile
|
||||||
|
if markdownFiles[index].hasHtml then content = io.open(markdownFiles[index].fileName .. ".html"):read("*all") end
|
||||||
|
|
||||||
-- STYLING
|
-- STYLING
|
||||||
local function styleLists(s)
|
local function styleLists(s)
|
||||||
|
|||||||
Reference in New Issue
Block a user