miti.sh/site.moon

61 lines
1.9 KiB
Plaintext

sitegen = require "sitegen"
tools = require "sitegen.tools"
site = require "sitegen.site"
path = require "sitegen.path"
-- import slugify from "sitegen.common"
lfs = require "lfs"
date = require "date"
-- Change output dir to what Openresty prefers
site.config.out_dir = "html/"
-- Deactivate "pygments" plugin
site.default_plugins = for v in *site.default_plugins
if v\find "pygments" then continue else v
rootname = (str) ->
result = string.gsub str, "%..+", ""
result
split = (str, delimiter="/") ->
[capture for capture in string.gmatch str, "[^#{delimiter}]+"]
last = (list) -> list[#list]
join = (first, last, delimiter="/") -> table.concat {first, last}, delimiter
target = (path, prefix) -> join prefix, rootname(last(split path))
posts = (path=".") ->
files = [file for file in lfs.dir path when file != "." and file != ".."]
{join(path, file), target(file, "/posts") for _, file in ipairs files}
extract_id = (source) -> string.match path.filename(source), "%a[%w%-]+"
extract_date = (source) -> string.match path.filename(source), "%d+%-%d%d%-%d%d"
format_date = (str) -> date(str)\fmt "%b %d, %Y"
publish_date = (path) -> format_date extract_date path
-- monkey-patch sitegen to use pandoc for markdown conversion
os.execute "moonc -t \\
/usr/local/openresty/luajit/share/lua/5.1/sitegen/renderers/ markdown.moon"
sitegen.create =>
@site_title = "WebDevCat.me · Catalin Mititiuc"
@app_name = "stasis"
@version = "0.2.12"
add "index.html"
add "blog.html", target: "posts/index", template: "blog"
add path, target: out, template: "post", is_a: "post", post: {
publish_date: publish_date(path)
}, id: extract_id(path) for path, out in pairs posts "docs"
-- replace yaml headers with moonscript headers
filter "docs", (body) =>
body\gsub "^%s*%-%-%-.-%.%.%.", (yaml_header) ->
moonscript_header = yaml_header\gsub "%-%-%-", "{"
result = moonscript_header\gsub "%.%.%.", "}"
result
copy "app.css"