This commit is contained in:
Catalin Constantin Mititiuc 2025-05-21 19:21:53 -07:00
parent 6b48db52f7
commit 52761ba06a
2 changed files with 11 additions and 59 deletions

View File

@ -6,16 +6,6 @@ $render{"templates/wares"}
<h2>Posts</h2>
$({{hi = "there"}})[[$hi]]
$(test1({limit = 2}))[[<p>inline template $title</p>]]
$each{test2({limit = 2}), "post"}[[$post]]
$(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

@ -69,23 +69,15 @@ template = [[
</section>
]]
-- use in templates like this
-- $each{list_posts({limit = 5}), "post"}[[$post]]
-- or like this
-- $each{list_posts(), "post"}[[$post]]
-- can call this two ways. One takes a template, the others uses a template passed
-- in
-- $(list_posts({limit = 2}, true))[[<p>$title</p>]]
-- $each{list_posts({limit = 2}), "post"}[[$post]]
-- 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]]
-- setup in create function:
--
-- sitegen.create =>
-- @list_posts = list_posts @, [template]
--
-- use in templates:
--
-- `list_posts @` expects $(list_posts({limit = 2}))[[<p>$title</p>]]
-- `list_posts @, template` expects $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
@ -103,27 +95,6 @@ list_posts = (template) => (args={}) =>
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>]]
get_posts = (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
return for page in *pages[1, limit]
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
{
title: title or titleize_slug id
publish_date: date
blurb: blurb
url: rootname page\url_for!
}
test = (args={}, template) =>
vals = { title: "yoayasdf" }
if template then common.fill_ignoring_pre template, vals else { vals }
-- 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
@ -133,22 +104,13 @@ documents = (path=".") ->
files = reverse get_files path
{join(path, file), target(file, "/posts") for file in *files}
test3 = (args, template) =>
p two
sitegen.create =>
@site_title = "WebDevCat.me"
@app_name = "stasis"
@version = "0.2.12"
@list_posts = list_posts @
@list_posts1 = list_posts @
@list_posts2 = list_posts @, template
@get_posts = get_posts
@test1 = (args) => test @, args
@test2 = (args) => test @, args, [[passed template $title]]
@test3 = test3
@list_posts = list_posts @, template
add_all = (name="", files) ->
add_all = (name, files) ->
for path, target in pairs files
id = extract_id path