WIP: i think i got it

This commit is contained in:
Catalin Constantin Mititiuc 2025-05-20 17:49:56 -07:00
parent 039461c581
commit 37958c8ad8
3 changed files with 10 additions and 37 deletions

View File

@ -1,11 +1,3 @@
<h2>Posts</h2>
$lp
$list_posts[[
<section>
<h3><a href="$target">$post_title</a></h3>
<time>$publish_date</time> — $blurb
<a class="read-post-link" href="$target">Read post →</a>
</section>
]]

View File

@ -6,13 +6,7 @@ $render{"templates/wares"}
<h2>Posts</h2>
$list_posts{limit = 5}[[
<section>
<h3><a href="$target">$post_title</a></h3>
<time>$publish_date</time> — $blurb
<a class="read-post-link" href="$target">Read post →</a>
</section>
]]
$lp{limit = 5}
<h4 style="text-align: center;">
<a href="$root/posts">View more posts</a>

View File

@ -5,6 +5,7 @@ html = require "sitegen.html"
cosmo = require "sitegen.cosmo"
date = require "date"
html_renderer = require "sitegen.renderers.html"
import tag from html
import escape_patt from require "sitegen.common"
import p from require "moon"
@ -76,7 +77,7 @@ titleize = (word) -> h(word), t(word)
titleize_slug = (slug) ->
words = [{ titleize word } for word in *common.split slug, "-"]
table.concat [head .. tail for { head, tail } in *words]
table.concat [head .. tail for { head, tail } in *words], " "
template = [[
<section>
@ -86,29 +87,16 @@ template = [[
</section>
]]
list_posts = (page, limit) ->
list_posts = (page, args={}) ->
posts = page.site\query_pages { is_a: "post" }
table.sort posts, (a, b) -> a.source > b.source
table.concat [cosmo.f(template) {
table.concat [common.fill_ignoring_pre template, {
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 *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 { meta: meta, source: source } in *posts[1, args.limit or #posts]]
list_posts2 = (page, args={}) ->
pages = page.site\query_pages { is_a: "post" }
@ -123,7 +111,6 @@ list_posts2 = (page, args={}) ->
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
html_renderer.cosmo_helpers.titleize = (slug) => html.build ->
titleize_slug(slug) if slug
@ -138,10 +125,10 @@ sitegen.create =>
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
-- add "about.html", some: {
-- { one: "alpha", two: "beta" },
-- { one: "A", two: "B" }
-- }, cif: cosmo.cif, math: math, x: 2
for path, target in pairs posts "docs"
id = extract_id path