create html files for md files inside the public/ directory

This commit is contained in:
2026-06-04 01:03:07 +03:00
parent df50db67fe
commit 964e58456a
+23
View File
@@ -20,6 +20,7 @@ for file in lfs.dir(currentDir) do
markdownFiles[markdownFileCount] = { markdownFiles[markdownFileCount] = {
options = {}, options = {},
filePath = filePath, filePath = filePath,
fileName = file:sub(1, file:len()-3),
content = "" content = ""
} }
end end
@@ -83,3 +84,25 @@ for index, value in ipairs(markdownFiles) do
end end
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 <!-- sitecontents --> with markdown file content
htmlFile:write(content)
htmlFile:close()
else
print("Error: Cannot create html file for " .. markdownFiles[index].filePath)
end
end