Render posts with a function so we can change the count

This commit is contained in:
2025-06-16 20:18:04 -07:00
parent 2e5cdac3e3
commit 41c0dcdca0
5 changed files with 22 additions and 42 deletions

View File

@@ -2,6 +2,7 @@ sitegen = require "sitegen"
tools = require "sitegen.tools"
site = require "sitegen.site"
path = require "sitegen.path"
html = require "sitegen.html"
-- import slugify from "sitegen.common"
lfs = require "lfs"
@@ -10,7 +11,7 @@ date = require "date"
-- Change output dir to what Openresty prefers
site.config.out_dir = "html/"
-- Deactivate "pygments" plugin
-- Deactivate "pygments" plugin because it conflicts with pandoc highlighting
site.default_plugins = for v in *site.default_plugins
if v\find "pygments" then continue else v
@@ -43,16 +44,31 @@ sitegen.create =>
@app_name = "stasis"
@version = "0.2.12"
add "index.html"
@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",
"Read post →"
}
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
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
add "index.html"
-- replace post markdown yaml headers with moonscript headers
filter "docs", (body) =>
body\gsub "^%s*%-%-%-.-%.%.%.", (yaml_header) ->
body\gsub "^%-%-%-.-%.%.%.", (yaml_header) ->
moonscript_header = yaml_header\gsub "%-%-%-", "{"
result = moonscript_header\gsub "%.%.%.", "}"
result