diff --git a/index.html b/index.html index e679bf0..cde2100 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,11 @@ $render{"templates/wares"}

Posts

+$(list_posts1({limit = 2}))[[

$title

]] +$each{list_posts2({limit = 2}), "post"}[[$post]] + +
+ $each{list_posts({limit = 5}), "post"}[[$post]]

diff --git a/site.moon b/site.moon index 6b695f7..5e8ffad 100644 --- a/site.moon +++ b/site.moon @@ -78,7 +78,15 @@ template = [[ -- in -- $(list_posts({limit = 2}, true))[[

$title

]] -- $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}))[[

$title

]] +-- to pass in a template, use like this +-- @list_posts = list_posts @, [[

$title

]] +-- $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())[[

$title

]] -- or like this: $(get_posts({limit = 5}))[[

$title

]] @@ -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