Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a98460360c | |||
| 5fbe2da916 |
@@ -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
|
||||
@@ -110,8 +122,12 @@ end
|
||||
-- get index.html content
|
||||
local indexFile = io.open("index.html"):read("*all")
|
||||
|
||||
-- remove and create "public/" directory
|
||||
lfs.rmdir("public")
|
||||
-- delete html files and create "public/" directory
|
||||
for file in lfs.dir(currentDir .. "/public") do
|
||||
if file:match("%.html$") then
|
||||
os.remove(currentDir .. "/public/" .. file)
|
||||
end
|
||||
end
|
||||
lfs.mkdir("public")
|
||||
|
||||
for index, _ in ipairs(markdownFiles) do
|
||||
@@ -121,6 +137,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)
|
||||
@@ -264,5 +281,5 @@ for index, _ in ipairs(markdownFiles) do
|
||||
else
|
||||
print("Error: Cannot create html file for " .. markdownFiles[index].filePath)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user