Fix post list limit
This commit is contained in:
parent
a78da1b386
commit
e8f62680da
75
site.moon
75
site.moon
@ -63,9 +63,9 @@ titleize_slug = (slug="") ->
|
||||
|
||||
template = [[
|
||||
<section>
|
||||
<h3><a href="$target">$title</a></h3>
|
||||
<h3><a href="$url">$title</a></h3>
|
||||
<time>$publish_date</time> — $blurb
|
||||
<a class="read-post-link" href="$target">Read post →</a>
|
||||
<a class="read-post-link" href="$url">Read post →</a>
|
||||
</section>
|
||||
]]
|
||||
|
||||
@ -74,28 +74,38 @@ template = [[
|
||||
-- or like this
|
||||
-- $each{list_posts(), "post"}[[$post]]
|
||||
list_posts = (args={}) =>
|
||||
posts = @site\query_pages { is_a: "post" }
|
||||
table.sort posts, (a, b) -> a.source > b.source
|
||||
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]
|
||||
-- overwrite with our extension-less targets so that urls generated with
|
||||
-- page\url_for! omit the file extension
|
||||
page.target = page.meta.target
|
||||
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
|
||||
|
||||
return for { meta: meta, source: source } in *posts[1, args.limit or #posts]
|
||||
common.fill_ignoring_pre template,
|
||||
target: meta.target
|
||||
title: meta.title or titleize_slug meta.id
|
||||
publish_date: publish_date source
|
||||
blurb: meta.blurb
|
||||
title: title or titleize_slug id
|
||||
publish_date: date
|
||||
blurb: blurb
|
||||
url: page\url_for!
|
||||
|
||||
-- call like this from a template: $(get_posts())[[<p>$target</p>]]
|
||||
-- or like this: $(get_posts({limit = 5}))[[<p>$target</p>]]
|
||||
-- call like this from a template: $(get_posts())[[<p>$title</p>]]
|
||||
-- or like this: $(get_posts({limit = 5}))[[<p>$title</p>]]
|
||||
get_posts = (args={}) =>
|
||||
posts = @site\query_pages { is_a: "post" }
|
||||
table.sort posts, (a, b) -> a.source > b.source
|
||||
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]
|
||||
page.target = page.meta.target
|
||||
{ title: title, id: id, publish_date: date, blurb: blurb } = page.meta
|
||||
|
||||
return for { meta: meta, source: source } in *posts[1, args.limit or #posts]
|
||||
{
|
||||
target: meta.target
|
||||
post_title: meta.title or titleize_slug meta.id
|
||||
publish_date: publish_date source
|
||||
blurb: meta.blurb
|
||||
title: title or titleize_slug id
|
||||
publish_date: date
|
||||
blurb: blurb
|
||||
url: page\url_for!
|
||||
}
|
||||
|
||||
-- replace '$if' helper function with cosmo's 'cif'
|
||||
@ -114,23 +124,20 @@ sitegen.create =>
|
||||
@list_posts = list_posts
|
||||
@get_posts = get_posts
|
||||
|
||||
add "index.html", title: "Catalin Mititiuc", blah: {{say: "wan"},{say: "tuu"}}
|
||||
add_all = (name="", files) ->
|
||||
for path, target in pairs files
|
||||
id = extract_id path
|
||||
|
||||
add path,
|
||||
target: Path.join Path.basepath(target), id -- TODO reformat target
|
||||
template: name
|
||||
is_a: name
|
||||
publish_date: publish_date path
|
||||
id: id
|
||||
|
||||
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
|
||||
|
||||
for path, target in pairs documents "docs"
|
||||
id = extract_id path
|
||||
|
||||
add path,
|
||||
target: Path.join Path.basepath(target), id
|
||||
template: "post"
|
||||
is_a: "post"
|
||||
publish_date: publish_date path
|
||||
id: id
|
||||
add_all "post", documents "docs"
|
||||
|
||||
-- replace post markdown yaml headers with moonscript headers
|
||||
filter "docs", (body) =>
|
||||
|
Loading…
x
Reference in New Issue
Block a user