Use function with or without template
This commit is contained in:
parent
405e19aa72
commit
1803433ae2
15
site.moon
15
site.moon
@ -73,7 +73,12 @@ template = [[
|
||||
-- $each{list_posts({limit = 5}), "post"}[[$post]]
|
||||
-- or like this
|
||||
-- $each{list_posts(), "post"}[[$post]]
|
||||
list_posts = (args={}) =>
|
||||
|
||||
-- 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]]
|
||||
list_posts = (args={}, has_block=false) =>
|
||||
pages = @site\query_pages { is_a: "post" }
|
||||
table.sort pages, (a, b) -> a.source > b.source
|
||||
limit = math.min args.limit or #pages, #pages
|
||||
@ -81,11 +86,15 @@ list_posts = (args={}) =>
|
||||
return for page in *pages[1, limit]
|
||||
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
|
||||
|
||||
common.fill_ignoring_pre template,
|
||||
vars = {
|
||||
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
|
||||
|
||||
-- call like this from a template: $(get_posts())[[<p>$title</p>]]
|
||||
-- or like this: $(get_posts({limit = 5}))[[<p>$title</p>]]
|
||||
@ -95,7 +104,6 @@ get_posts = (args={}) =>
|
||||
limit = math.min args.limit or #pages, #pages
|
||||
|
||||
return for page in *pages[1, limit]
|
||||
page.target = page.meta.target
|
||||
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
|
||||
|
||||
{
|
||||
@ -120,6 +128,7 @@ sitegen.create =>
|
||||
@version = "0.2.12"
|
||||
@list_posts = list_posts
|
||||
@get_posts = get_posts
|
||||
-- @list_posts = (template) -> get_posts -- pass in template here!
|
||||
|
||||
add_all = (name="", files) ->
|
||||
for path, target in pairs files
|
||||
|
Loading…
x
Reference in New Issue
Block a user