This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 20:18:05 -07:00
parent 185d1b06b3
commit d1339160f0
2 changed files with 26 additions and 6 deletions

View File

@ -6,6 +6,11 @@ $render{"templates/wares"}
<h2>Posts</h2>
$(list_posts1({limit = 2}))[[<p>$title</p>]]
$each{list_posts2({limit = 2}), "post"}[[$post]]
<hr/>
$each{list_posts({limit = 5}), "post"}[[$post]]
<h4 style="text-align: center;">

View File

@ -78,7 +78,15 @@ template = [[
-- in
-- $(list_posts({limit = 2}, true))[[<p>$title</p>]]
-- $each{list_posts({limit = 2}), "post"}[[$post]]
list_posts = (args={}, has_block=false) =>
-- to inline a template, use like this
-- @list_posts = list_posts @
-- and then call from template like this
-- $(list_posts({limit = 2}))[[<p>$title</p>]]
-- to pass in a template, use like this
-- @list_posts = list_posts @, [[<p>$title</p>]]
-- $each{list_posts({limit = 2}), "post"}[[$post]]
list_posts = (template) => (args={}) =>
pages = @site\query_pages { is_a: "post" }
table.sort pages, (a, b) -> a.source > b.source
limit = math.min args.limit or #pages, #pages
@ -86,15 +94,14 @@ list_posts = (args={}, has_block=false) =>
return for page in *pages[1, limit]
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
vars = {
vals = {
title: title or titleize_slug id
publish_date: date
blurb: blurb
url: rootname page\url_for!
}
if has_block then vars else common.fill_ignoring_pre template, vars
-- common.fill_ignoring_pre template, vars
if template then common.fill_ignoring_pre template, vals else vals
-- call like this from a template: $(get_posts())[[<p>$title</p>]]
-- or like this: $(get_posts({limit = 5}))[[<p>$title</p>]]
@ -113,6 +120,11 @@ get_posts = (args={}) =>
url: rootname page\url_for!
}
test = (arg) =>
(a, b, c) =>
p arg
"hi"
-- replace '$if' helper function with cosmo's 'cif'
html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block
-- add a '$titleize' helper function
@ -126,9 +138,12 @@ sitegen.create =>
@site_title = "WebDevCat.me"
@app_name = "stasis"
@version = "0.2.12"
@list_posts = list_posts
@list_posts = list_posts @
@list_posts1 = list_posts @
@list_posts2 = list_posts @, template
@get_posts = get_posts
-- @list_posts = (template) -> get_posts -- pass in template here!
-- @list_posts1 = list_posts @, [[$title]]
-- @list_posts2 = list_posts @
add_all = (name="", files) ->
for path, target in pairs files