diff --git a/luago.lua b/luago.lua index 077e6c5..13fde96 100644 --- a/luago.lua +++ b/luago.lua @@ -20,6 +20,7 @@ for file in lfs.dir(currentDir) do markdownFiles[markdownFileCount] = { options = {}, filePath = filePath, + fileName = file:sub(1, file:len()-3), content = "" } end @@ -83,3 +84,25 @@ for index, value in ipairs(markdownFiles) do end end +-- get index.html content +local indexFile = io.open("index.html"):read("*all") + +-- remove and create "public/" directory +lfs.rmdir("public") +lfs.mkdir("public") + +for index, value in ipairs(markdownFiles) do + local workDir = lfs.currentdir() + -- create html file for that md file + local htmlFile = io.open(workDir .. "/public/" .. markdownFiles[index].fileName .. ".html", 'w') + if htmlFile then + local content = indexFile + -- replace with markdown file content + + htmlFile:write(content) + htmlFile:close() + else + print("Error: Cannot create html file for " .. markdownFiles[index].filePath) + end +end +