diff --git a/docs/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.md b/docs/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.md index dc0d96b..5d5d1ce 100644 --- a/docs/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.md +++ b/docs/2023-08-03-recursively-list-all-files-in-a-directory-with-elixir.md @@ -129,4 +129,4 @@ hello/test/support/conn_case.ex ## Conclusion -Trying to do this without recursion made it difficult to sort directories first. \ No newline at end of file +Trying to do this without recursion made it difficult to sort directories first. diff --git a/lint_config.lua b/lint_config.lua index 685627c..d40353a 100644 --- a/lint_config.lua +++ b/lint_config.lua @@ -1,7 +1,9 @@ return { whitelist_globals = { ["site.moon"] = { - "add" + "add", + "filter", + "copy" } } } diff --git a/lint_config.moon b/lint_config.moon index 1dd5ac0..323a8eb 100644 --- a/lint_config.moon +++ b/lint_config.moon @@ -1,7 +1,7 @@ { whitelist_globals: { ["site.moon"]: { - "add" + "add", "filter", "copy" } } } diff --git a/site.moon b/site.moon index 8ab533f..b835ccf 100644 --- a/site.moon +++ b/site.moon @@ -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]]