From ce26dd35beb074ae96edce6e5264ba3598ad7c30 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Mon, 16 Jun 2025 20:18:05 -0700 Subject: [PATCH] WIP --- index.html | 4 +++- site.moon | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index dccb7dc..8e514e2 100644 --- a/index.html +++ b/index.html @@ -2,7 +2,9 @@ date: "Thu May 08 2025 19:41:30.000000000" } -$test{ limit = "is this?" }[[what $limit]][[second $limit]] +$list3{ limit = 2 }[[

$title

]] +
+$list3{ limit = 2 } $render{"templates/wares"} diff --git a/site.moon b/site.moon index c233f32..128f81a 100644 --- a/site.moon +++ b/site.moon @@ -112,7 +112,7 @@ html_renderer.cosmo_helpers.titleize = (slug) => titleize_slug slug files_from = (path=".") -> [Path.join path, file for file in *reverse get_files path] -test = (args, has_block) => +test = (args={}, has_block) => if has_block cosmo.yield(name: "yupyup") nil @@ -126,6 +126,25 @@ test = (args, has_block) => -- page.template_stack = common.Stack! -- html\render page, assert args[1] or template, "missing html string" +list3 = (args={}, has_block) => + pages = @site\query_pages { is_a: "post" } + table.sort pages, (a, b) -> a.source > b.source + limit_or_page_count = math.min args.limit or #pages, #pages + + result = for page in *pages[1, limit_or_page_count] + { :title, :id, publish_date: pub_date, :blurb } = page.meta + title = title or titleize_slug id + url = rootname page\url_for! + vals = { title: title, publish_date: pub_date, blurb: blurb, url: url } + + if has_block + cosmo.yield vals + nil + else + common.fill_ignoring_pre template, vals + + unless has_block then return table.concat result + -- use in templates -- $list2{[[

$title

]], limit = 2} -- $each{$list2({limit = 3}), "item"}[[$item]] @@ -155,6 +174,7 @@ sitegen.create => @list_posts = list_posts @, template @test = test @list2 = list2 + @list3 = list3 add_all = (files) -> for path in *files