Lint site.moon
This commit is contained in:
parent
bb90a3eaa5
commit
40ed4736e1
@ -1,7 +1,9 @@
|
|||||||
return {
|
return {
|
||||||
whitelist_globals = {
|
whitelist_globals = {
|
||||||
["site.moon"] = {
|
["site.moon"] = {
|
||||||
"add"
|
"add",
|
||||||
|
"filter",
|
||||||
|
"copy"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
whitelist_globals: {
|
whitelist_globals: {
|
||||||
["site.moon"]: {
|
["site.moon"]: {
|
||||||
"add"
|
"add", "filter", "copy"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
44
site.moon
44
site.moon
@ -1,26 +1,26 @@
|
|||||||
sitegen = require "sitegen"
|
sitegen = require "sitegen"
|
||||||
tools = require "sitegen.tools"
|
Site = require "sitegen.site"
|
||||||
site = require "sitegen.site"
|
Path = require "sitegen.path"
|
||||||
path = require "sitegen.path"
|
|
||||||
html = require "sitegen.html"
|
html = require "sitegen.html"
|
||||||
|
import tag from html
|
||||||
-- import slugify from "sitegen.common"
|
-- import slugify from "sitegen.common"
|
||||||
|
|
||||||
lfs = require "lfs"
|
lfs = require "lfs"
|
||||||
date = require "date"
|
date = require "date"
|
||||||
|
|
||||||
-- Change output dir to what Openresty prefers
|
-- 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
|
-- 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
|
if v\find "pygments" then continue else v
|
||||||
|
|
||||||
-- Remove default markdown renderer
|
-- 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
|
if v\find "markdown" then continue else v
|
||||||
|
|
||||||
-- Add pandoc markdown renderer
|
-- Add pandoc markdown renderer
|
||||||
table.insert site.default_renderers, "renderers.markdown"
|
table.insert Site.default_renderers, "renderers.markdown"
|
||||||
|
|
||||||
rootname = (str) ->
|
rootname = (str) ->
|
||||||
result = string.gsub str, "%..+", ""
|
result = string.gsub str, "%..+", ""
|
||||||
@ -33,25 +33,41 @@ last = (list) -> list[#list]
|
|||||||
join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter
|
join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter
|
||||||
target = (path, prefix) -> join prefix, rootname(last(split path))
|
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=".") ->
|
posts = (path=".") ->
|
||||||
files = [file for file in lfs.dir path when file != "." and file != ".."]
|
files = [file for file in lfs.dir path when file != "." and file != ".."]
|
||||||
{join(path, file), target(file, "/posts") for _, file in ipairs files}
|
{join(path, file), target(file, "/posts") for _, file in ipairs files}
|
||||||
|
|
||||||
extract_id = (source) -> string.match path.filename(source), "%a[%w%-]+"
|
extract_id = (source) -> string.match Path.filename(source), "%a[%w%-]+"
|
||||||
extract_date = (source) -> string.match path.filename(source), "%d+%-%d%d%-%d%d"
|
extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d"
|
||||||
format_date = (str) -> date(str)\fmt "%b %d, %Y"
|
format_date = (str) -> date(str)\fmt "%b %d, %Y"
|
||||||
publish_date = (path) -> format_date extract_date path
|
publish_date = (path) -> format_date extract_date path
|
||||||
|
|
||||||
|
|
||||||
list_posts = (page, limit) ->
|
list_posts = (page, limit) ->
|
||||||
posts = page.site\query_pages { is_a: "post" }
|
posts = page.site\query_pages { is_a: "post" }
|
||||||
table.sort posts, (a, b) -> a.source > b.source
|
table.sort posts, (a, b) -> a.source > b.source
|
||||||
|
|
||||||
html.build ->
|
html.build ->
|
||||||
[section {
|
[tag.section {
|
||||||
h3 { a { href: meta.target .. ".html", meta.title or meta.id }}
|
tag.h3 { tag.a { href: meta.target .. ".html", meta.title or meta.id }}
|
||||||
time { publish_date source }
|
tag.time { publish_date source }
|
||||||
{ "—", if meta.blurb then text meta.blurb }
|
{ "—", if meta.blurb then html.builders.text! meta.blurb }
|
||||||
a { class: "read-post-link", href: meta.target .. ".html",
|
tag.a { class: "read-post-link", href: meta.target .. ".html",
|
||||||
"Read post →"
|
"Read post →"
|
||||||
}
|
}
|
||||||
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user