Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3f2380e6a2 | |||
| 28a973991f | |||
| 9ae0960750 |
@@ -1,2 +1,22 @@
|
||||
# luago
|
||||
Static website generator written in Lua
|
||||
> Still in development
|
||||
> Please don't use for production yet
|
||||
> There are a lot of work to do
|
||||
|
||||
## what it does
|
||||
- reads .md files in that directory and create html files
|
||||
- transforms basic markdown syntax to html styling
|
||||
|
||||
### features
|
||||
- read all md files
|
||||
- check if index.md and index.html files are exists (if not stop with error)
|
||||
- read options section on every md file
|
||||
- clear public/ directory and create if not exists
|
||||
- create html files using same name template html file
|
||||
- if there are no html file for that md file, use index.html
|
||||
- {{pageContent}}, {{pageTitle}} and {{list:}}-{{:list}} shortcodes
|
||||
- list.item.<option> shortcode inside list shortcode
|
||||
|
||||
luago name
|
||||
: **lua** + **hugo** (can't thing of anything better)
|
||||
|
||||
@@ -260,19 +260,56 @@ for index, _ in ipairs(markdownFiles) do
|
||||
end
|
||||
markdownFiles[index].content = styling(markdownFiles[index].content)
|
||||
|
||||
-- replace <!-- sitecontents --> with markdown file content
|
||||
local start_idx, end_idx = content:find("<!-- sitecontents -->", 1, true)
|
||||
-- start_idx, end_idx = c
|
||||
-- {{pageContent}} shortcode
|
||||
content = content:gsub("{{pageContent}}", markdownFiles[index].content)
|
||||
-- {{pageTitle}} shortcode
|
||||
content = content:gsub("{{pageTitle}}", markdownFiles[index].options["title"])
|
||||
|
||||
local start_idx, end_idx
|
||||
-- list shortcodes
|
||||
while content:find("{{list:}}", 1, true) do
|
||||
start_idx, end_idx = content:find("{{list:}}")
|
||||
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
|
||||
if second:find("{{:list}}", 1, true) then
|
||||
start_idx, end_idx = second:find("{{:list}}")
|
||||
if start_idx and end_idx then
|
||||
local shortcode = second:sub(1, start_idx - 1)
|
||||
local third = second:sub(end_idx + 1)
|
||||
local function formatShortcode(element)
|
||||
local dir = markdownFiles[index].filePath:match("(.*)/[^/]+%.md$")
|
||||
local results = {}
|
||||
|
||||
for mdfile in lfs.dir(dir) do
|
||||
if mdfile:match("%.md$") and mdfile ~= markdownFiles[index].fileName .. ".md" then
|
||||
local fileName = mdfile:match("(.-)%.md$")
|
||||
|
||||
for i, _ in ipairs(markdownFiles) do
|
||||
if markdownFiles[i].fileName == fileName then
|
||||
local copy = element
|
||||
|
||||
-- replace items starting with list.item.
|
||||
for option in copy:gmatch("{{list%.item%.(.-)}}") do
|
||||
local value = markdownFiles[i].options[option]
|
||||
if value then
|
||||
copy = copy:gsub("{{list%.item%." .. option .. "}}", value)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(results, copy)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(results, "\n")
|
||||
end
|
||||
shortcode = formatShortcode(shortcode)
|
||||
content = first .. shortcode .. third
|
||||
end
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user