Lint site.moon

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 20:18:05 -07:00
parent bb90a3eaa5
commit 40ed4736e1
4 changed files with 35 additions and 17 deletions

View File

@ -129,4 +129,4 @@ hello/test/support/conn_case.ex
## Conclusion
Trying to do this without recursion made it difficult to sort directories first.
Trying to do this without recursion made it difficult to sort directories first.

View File

@ -1,7 +1,9 @@
return {
whitelist_globals = {
["site.moon"] = {
"add"
"add",
"filter",
"copy"
}
}
}

View File

@ -1,7 +1,7 @@
{
whitelist_globals: {
["site.moon"]: {
"add"
"add", "filter", "copy"
}
}
}

View File

@ -1,26 +1,26 @@
sitegen = require "sitegen"
tools = require "sitegen.tools"
site = require "sitegen.site"
path = require "sitegen.path"
Site = require "sitegen.site"
Path = require "sitegen.path"
html = require "sitegen.html"
import tag from html
-- import slugify from "sitegen.common"
lfs = require "lfs"
date = require "date"
-- Change output dir to what Openresty prefers
site.config.out_dir = "html/"
Site.config.out_dir = "html/"
-- Deactivate "pygments" plugin because it conflicts with pandoc highlighting
site.default_plugins = for v in *site.default_plugins
Site.default_plugins = for v in *Site.default_plugins
if v\find "pygments" then continue else v
-- Remove default markdown renderer
site.default_renderers = for v in *site.default_renderers
Site.default_renderers = for v in *Site.default_renderers
if v\find "markdown" then continue else v
-- Add pandoc markdown renderer
table.insert site.default_renderers, "renderers.markdown"
table.insert Site.default_renderers, "renderers.markdown"
rootname = (str) ->
result = string.gsub str, "%..+", ""
@ -33,25 +33,41 @@ last = (list) -> list[#list]
join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter
target = (path, prefix) -> join prefix, rootname(last(split path))
import escape_patt from require "sitegen.common"
get_files = (path, prefix=path) ->
files = Path.read_exec "find", path, "-type", "f"
files = [f for f in files\gmatch "[^\n]+"]
if prefix
files = for file in *files
file\gsub "^#{escape_patt prefix}/?", ""
table.sort files
files
-- require("moon").p get_files("docs")
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"
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
list_posts = (page, limit) ->
posts = page.site\query_pages { is_a: "post" }
table.sort posts, (a, b) -> a.source > b.source
html.build ->
[section {
h3 { a { href: meta.target .. ".html", meta.title or meta.id }}
time { publish_date source }
{ "—", if meta.blurb then text meta.blurb }
a { class: "read-post-link", href: meta.target .. ".html",
[tag.section {
tag.h3 { tag.a { href: meta.target .. ".html", meta.title or meta.id }}
tag.time { publish_date source }
{ "—", if meta.blurb then html.builders.text! meta.blurb }
tag.a { class: "read-post-link", href: meta.target .. ".html",
"Read post →"
}
} for { meta: meta, source: source } in *posts[1, limit or #posts]]