From 52342a77e5d2c26c6cc86ecf43db6dedd75190a9 Mon Sep 17 00:00:00 2001 From: Catalin Constantin Mititiuc Date: Mon, 16 Jun 2025 20:18:05 -0700 Subject: [PATCH] WIP: use cosmo.f to list posts? --- blog.html | 6 ++--- index.html | 8 +++++- site.moon | 78 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/blog.html b/blog.html index 17f73c8..f611c0c 100644 --- a/blog.html +++ b/blog.html @@ -1,11 +1,11 @@

Posts

-$list_posts2{limit = 3}[[ +$lp + +$list_posts[[

$post_title

— $blurb Read post →
]] - -$list_posts diff --git a/index.html b/index.html index 2e902ed..2dfefb1 100644 --- a/index.html +++ b/index.html @@ -6,7 +6,13 @@ $render{"templates/wares"}

Posts

-$(list_posts(5)) +$list_posts{limit = 5}[[ +
+

$post_title

+ — $blurb + Read post → +
+]]

View more posts diff --git a/site.moon b/site.moon index 5c6f29b..0de76f4 100644 --- a/site.moon +++ b/site.moon @@ -2,6 +2,7 @@ sitegen = require "sitegen" Site = require "sitegen.site" Path = require "sitegen.path" html = require "sitegen.html" +cosmo = require "sitegen.cosmo" date = require "date" import tag from html @@ -75,51 +76,52 @@ titleize = (word) -> h(word), t(word) titleize_slug = (slug) -> words = [{ titleize word } for word in *common.split slug, "-"] - [head .. tail for { head, tail } in *words] + table.concat [head .. tail for { head, tail } in *words] + +template = [[ +
+

$post_title

+ — $blurb + Read post → +
+]] list_posts = (page, limit) -> posts = page.site\query_pages { is_a: "post" } table.sort posts, (a, b) -> a.source > b.source - html.build -> - import section, h3, a, time from tag - - [section { - h3 { a { href: meta.target, meta.title or titleize_slug meta.id }} - time { publish_date source } - { "—", if meta.blurb then html.builders.text! meta.blurb } - a { class: "read-post-link", href: meta.target, - "Read post →" - } - } for { meta: meta, source: source } in *posts[1, limit or #posts]] - --- list_posts2 = (page) -> --- posts = page.site\query_pages { is_a: "post" } --- table.sort posts, (a, b) -> a.source > b.source --- --- list = [{ --- target: meta.target --- post_title: meta.title or table.concat(titleize_slug(meta.id), " ") --- publish_date: publish_date source --- } for { meta: meta, source: source } in *posts[1, limit or #posts]] --- p list --- list - -cosmo = require "sitegen.cosmo" - -list_posts2 = (page, arg={}) -> - posts = page.site\query_pages { is_a: "post" } - table.sort posts, (a, b) -> a.source > b.source - - list = [{ + table.concat [cosmo.f(template) { target: meta.target - post_title: meta.title or table.concat(titleize_slug(meta.id), " ") + post_title: meta.title or titleize_slug meta.id publish_date: publish_date source blurb: meta.blurb - } for { meta: meta, source: source } in *posts[1, arg.limit or #posts]] + } for { meta: meta, source: source } in *posts[1, limit or #posts]] + -- html.build -> + -- import section, h3, a, time from tag + -- + -- [section { + -- h3 { a { href: meta.target, meta.title or titleize_slug meta.id }} + -- time { publish_date source } + -- { "—", if meta.blurb then html.builders.text! meta.blurb } + -- a { class: "read-post-link", href: meta.target, + -- "Read post →" + -- } + -- } for { meta: meta, source: source } in *posts[1, limit or #posts]] - for post in *list - cosmo.yield post + + +list_posts2 = (page, args={}) -> + pages = page.site\query_pages { is_a: "post" } + table.sort pages, (a, b) -> a.source > b.source + + posts = [{ + target: meta.target + post_title: meta.title or titleize_slug(meta.id) + publish_date: publish_date source + blurb: meta.blurb + } for { meta: meta, source: source } in *pages[1, args.limit or #pages]] + + for post in *posts do cosmo.yield post html_renderer = require "sitegen.renderers.html" html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block @@ -130,8 +132,8 @@ sitegen.create => @site_title = "WebDevCat.me" @app_name = "stasis" @version = "0.2.12" - @list_posts = list_posts - @list_posts2 = list_posts2 + @list_posts = list_posts2 + @lp = list_posts add "index.html", title: "Catalin Mititiuc" add "blog.html", title: "Posts", target: "posts/index", template: "blog"