Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33540f028f | |||
| 80a8119f6a | |||
| 8b43950cce | |||
| 21fcf6702c | |||
| f9d9f5b26a | |||
| 82ac8e0998 | |||
| 964e58456a | |||
| df50db67fe |
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"workspace": {
|
||||||
|
"library": [
|
||||||
|
"types"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
lua /home/murat/Projects/luago/luago.lua
|
||||||
@@ -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
|
||||||
@@ -49,11 +50,19 @@ for index, file in ipairs(markdownFiles) do
|
|||||||
fileOptions = fileOptions:sub(fileOptions:find("\n")+1, fileOptions:len())
|
fileOptions = fileOptions:sub(fileOptions:find("\n")+1, fileOptions:len())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- fill options table
|
||||||
for i, value in ipairs(lines) do
|
for i, value in ipairs(lines) do
|
||||||
if value:sub(value:len(), value:len()) == "\n" then
|
if value:sub(value:len(), value:len()) == "\n" then
|
||||||
value = value:sub(1, value:find("\n")-1)
|
value = value:sub(1, value:find("\n")-1)
|
||||||
end
|
end
|
||||||
markdownFiles[index].options[i] = value
|
local colonPos = value:find(":")
|
||||||
|
if colonPos then
|
||||||
|
local key = value:sub(1, colonPos - 1):match("^%s*(.-)%s*$")
|
||||||
|
local val = value:sub(colonPos + 1):match("^%s*(.-)%s*$")
|
||||||
|
if key and key ~= "" then
|
||||||
|
markdownFiles[index].options[key] = val
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return print(file.filePath .. " file doesn't have a options section!")
|
return print(file.filePath .. " file doesn't have a options section!")
|
||||||
@@ -63,19 +72,34 @@ for index, file in ipairs(markdownFiles) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- replace markdownFiles.content with md file content
|
||||||
for index, value in ipairs(markdownFiles) do
|
for index, value in ipairs(markdownFiles) do
|
||||||
|
local f = io.open(markdownFiles[index].filePath)
|
||||||
|
if f then
|
||||||
|
local content = f:read("*a")
|
||||||
|
f:close()
|
||||||
|
|
||||||
|
-- delete options section
|
||||||
|
content = content:sub(5, content:len())
|
||||||
|
content = content:sub(content:find("---\n")+4, content:len())
|
||||||
|
|
||||||
|
markdownFiles[index].content = content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for index, value in ipairs(markdownFiles) do
|
||||||
|
print("---------------")
|
||||||
-- print file path with index
|
-- print file path with index
|
||||||
print(index .. ': ' .. markdownFiles[index].filePath)
|
print(index .. ': ' .. markdownFiles[index].filePath)
|
||||||
local f = io.open(markdownFiles[index].filePath, 'r')
|
local f = io.open(markdownFiles[index].filePath, 'r')
|
||||||
if f then
|
if f then
|
||||||
local content = f:read("*all")
|
|
||||||
f:close()
|
f:close()
|
||||||
-- print file content
|
-- print file content
|
||||||
print(content)
|
print(markdownFiles[index].content)
|
||||||
-- print file options
|
-- print file options
|
||||||
print("--- OPTIONS ---")
|
print("--- OPTIONS ---")
|
||||||
for i, value in ipairs(markdownFiles[index].options) do
|
for key, val in pairs(markdownFiles[index].options) do
|
||||||
print(markdownFiles[index].options[i])
|
print(key .. ": " .. val)
|
||||||
end
|
end
|
||||||
print("---------------")
|
print("---------------")
|
||||||
else
|
else
|
||||||
@@ -83,3 +107,41 @@ for index, value in ipairs(markdownFiles) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- get index.html content
|
||||||
|
local indexFile = io.open("index.html"):read("*all")
|
||||||
|
local siteName
|
||||||
|
local siteTitle
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
local start_idx, end_idx = content:find("<!-- sitecontents -->", 1, true)
|
||||||
|
if start_idx and end_idx then
|
||||||
|
local first = content:sub(1, start_idx - 1)
|
||||||
|
local second = content:sub(end_idx + 1)
|
||||||
|
content = first .. markdownFiles[index].content .. second
|
||||||
|
end
|
||||||
|
while content:find("<!-- title -->", 1, true) do
|
||||||
|
start_idx, end_idx = content:find("<!-- title -->", 1, true)
|
||||||
|
if start_idx and end_idx then
|
||||||
|
local first = content:sub(1, start_idx - 1)
|
||||||
|
local second = content:sub(end_idx + 1)
|
||||||
|
content = first .. markdownFiles[index].options["title"] .. second
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
htmlFile:write(content)
|
||||||
|
htmlFile:close()
|
||||||
|
else
|
||||||
|
print("Error: Cannot create html file for " .. markdownFiles[index].filePath)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
---@meta
|
||||||
|
---@class lfs
|
||||||
|
local lfs = {}
|
||||||
|
|
||||||
|
---@param filepath string
|
||||||
|
---@param aname? string|table
|
||||||
|
---@return table|string|nil result
|
||||||
|
---@return string? error_msg
|
||||||
|
function lfs.attributes(filepath, aname) end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@return boolean success
|
||||||
|
---@return string? error_msg
|
||||||
|
function lfs.chdir(path) end
|
||||||
|
|
||||||
|
---@return string path
|
||||||
|
function lfs.currentdir() end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@return fun():string iter
|
||||||
|
---@return table dir_obj
|
||||||
|
function lfs.dir(path) end
|
||||||
|
|
||||||
|
---@param dirname string
|
||||||
|
---@return boolean success
|
||||||
|
---@return string? error_msg
|
||||||
|
function lfs.mkdir(dirname) end
|
||||||
|
|
||||||
|
---@param dirname string
|
||||||
|
---@return boolean success
|
||||||
|
---@return string? error_msg
|
||||||
|
function lfs.rmdir(dirname) end
|
||||||
|
|
||||||
|
---@param filepath string
|
||||||
|
---@param atime? number
|
||||||
|
---@param mtime? number
|
||||||
|
---@return boolean success
|
||||||
|
---@return string? error_msg
|
||||||
|
function lfs.touch(filepath, atime, mtime) end
|
||||||
|
|
||||||
|
return lfs
|
||||||
Reference in New Issue
Block a user