checking for options section in every .md file
This commit is contained in:
@@ -19,7 +19,8 @@ for file in lfs.dir(currentDir) do
|
|||||||
markdownFileCount = markdownFileCount + 1
|
markdownFileCount = markdownFileCount + 1
|
||||||
markdownFiles[markdownFileCount] = {
|
markdownFiles[markdownFileCount] = {
|
||||||
options = {},
|
options = {},
|
||||||
filePath = filePath
|
filePath = filePath,
|
||||||
|
content = ""
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -34,7 +35,27 @@ for index, file in ipairs(markdownFiles) do
|
|||||||
if f then
|
if f then
|
||||||
local content = f:read("*all")
|
local content = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
if content:sub(1,3) ~= "---" then
|
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!")
|
return print(file.filePath .. " file doesn't have a options section!")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -51,6 +72,12 @@ for index, value in ipairs(markdownFiles) do
|
|||||||
f:close()
|
f:close()
|
||||||
-- print file content
|
-- print file content
|
||||||
print(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
|
else
|
||||||
print("can't read the file " .. markdownFiles[index].filePath)
|
print("can't read the file " .. markdownFiles[index].filePath)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user