From 5fbe2da91617d12af4cd95cd9e220b74ac9f5444 Mon Sep 17 00:00:00 2001 From: murat Date: Wed, 17 Jun 2026 16:38:25 +0300 Subject: [PATCH] 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 --- luago.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/luago.lua b/luago.lua index 4603440..46126d5 100644 --- a/luago.lua +++ b/luago.lua @@ -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)