Compare commits

..

3 Commits

Author SHA1 Message Date
murat 9cbccfbdf7 checking for options section in every .md file 2026-06-03 23:18:32 +03:00
murat fde8084b09 checking for index.md and index.html 2026-06-03 21:27:58 +03:00
murat 5b31f680be Initialize main file 2026-06-02 20:20:09 +03:00
+85
View File
@@ -0,0 +1,85 @@
local lfs = require("lfs")
-- list of markdown files in working directory
local markdownFiles = {}
local haveIndexmd = false
local haveIndexhtml = false
-- amount of markdown files in working directory
local markdownFileCount = 0
local currentDir = lfs.currentdir()
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
if file:match("%.md$") then
markdownFileCount = markdownFileCount + 1
markdownFiles[markdownFileCount] = {
options = {},
filePath = filePath,
content = ""
}
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
-- check for options section on every markdown file
for index, file in ipairs(markdownFiles) do
local f = io.open(file.filePath, 'r')
if f then
local content = f:read("*all")
f:close()
if content:sub(1,4) ~= "---\n" then
return print(file.filePath .. " file doesn't have a options section!")
end
local fileOptions = content:sub(5, content:len())
if fileOptions:find("---") then
fileOptions = fileOptions:sub(1, fileOptions:find("---\n")-1)
local lines = {}
local lineCount = 0
while fileOptions:find("\n") do
lineCount = lineCount + 1
lines[lineCount] = fileOptions:sub(1, fileOptions:find("\n"))
fileOptions = fileOptions:sub(fileOptions:find("\n")+1, fileOptions:len())
end
for i, value in ipairs(lines) do
if value:sub(value:len(), value:len()) == "\n" then
value = value:sub(1, value:find("\n")-1)
end
markdownFiles[index].options[i] = value
end
else
return print(file.filePath .. " file doesn't have a options section!")
end
else
print("can't read the file " .. file.filePath)
end
end
for index, value in ipairs(markdownFiles) do
-- print file path with index
print(index .. ': ' .. markdownFiles[index].filePath)
local f = io.open(markdownFiles[index].filePath, 'r')
if f then
local content = f:read("*all")
f:close()
-- print file content
print(content)
-- print file options
print("--- OPTIONS ---")
for i, value in ipairs(markdownFiles[index].options) do
print(markdownFiles[index].options[i])
end
print("---------------")
else
print("can't read the file " .. markdownFiles[index].filePath)
end
end