From e8f62680da2bb73fda9ac8a28871cdc8bf606ae0 Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Wed, 21 May 2025 14:57:14 -0700 Subject: [PATCH] Fix post list limit --- site.moon | 75 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/site.moon b/site.moon index a6b2dcb..19714eb 100644 --- a/site.moon +++ b/site.moon @@ -63,9 +63,9 @@ titleize_slug = (slug="") -> template = [[
-

$title

+

$title

— $blurb - Read post → + Read post →
]] @@ -74,28 +74,38 @@ template = [[ -- or like this -- $each{list_posts(), "post"}[[$post]] list_posts = (args={}) => - posts = @site\query_pages { is_a: "post" } - table.sort posts, (a, b) -> a.source > b.source + pages = @site\query_pages { is_a: "post" } + table.sort pages, (a, b) -> a.source > b.source + limit = math.min args.limit or #pages, #pages + + return for page in *pages[1, limit] + -- overwrite with our extension-less targets so that urls generated with + -- page\url_for! omit the file extension + page.target = page.meta.target + { title: title, id: id, publish_date: date, blurb: blurb } = page.meta - return for { meta: meta, source: source } in *posts[1, args.limit or #posts] common.fill_ignoring_pre template, - target: meta.target - title: meta.title or titleize_slug meta.id - publish_date: publish_date source - blurb: meta.blurb + title: title or titleize_slug id + publish_date: date + blurb: blurb + url: page\url_for! --- call like this from a template: $(get_posts())[[

$target

]] --- or like this: $(get_posts({limit = 5}))[[

$target

]] +-- call like this from a template: $(get_posts())[[

$title

]] +-- or like this: $(get_posts({limit = 5}))[[

$title

]] get_posts = (args={}) => - posts = @site\query_pages { is_a: "post" } - table.sort posts, (a, b) -> a.source > b.source + pages = @site\query_pages { is_a: "post" } + table.sort pages, (a, b) -> a.source > b.source + limit = math.min args.limit or #pages, #pages + + return for page in *pages[1, limit] + page.target = page.meta.target + { title: title, id: id, publish_date: date, blurb: blurb } = page.meta - return for { meta: meta, source: source } in *posts[1, args.limit or #posts] { - target: meta.target - post_title: meta.title or titleize_slug meta.id - publish_date: publish_date source - blurb: meta.blurb + title: title or titleize_slug id + publish_date: date + blurb: blurb + url: page\url_for! } -- replace '$if' helper function with cosmo's 'cif' @@ -114,23 +124,20 @@ sitegen.create => @list_posts = list_posts @get_posts = get_posts - add "index.html", title: "Catalin Mititiuc", blah: {{say: "wan"},{say: "tuu"}} + add_all = (name="", files) -> + for path, target in pairs files + id = extract_id path + + add path, + target: Path.join Path.basepath(target), id -- TODO reformat target + template: name + is_a: name + publish_date: publish_date path + id: id + + add "index.html", title: "Catalin Mititiuc" add "blog.html", title: "Posts", target: "posts/index", template: "blog" - - -- add "about.html", some: { - -- { one: "alpha", two: "beta" }, - -- { one: "A", two: "B" } - -- }, cif: cosmo.cif, math: math, x: 2 - - for path, target in pairs documents "docs" - id = extract_id path - - add path, - target: Path.join Path.basepath(target), id - template: "post" - is_a: "post" - publish_date: publish_date path - id: id + add_all "post", documents "docs" -- replace post markdown yaml headers with moonscript headers filter "docs", (body) =>