Fix post list limit
This commit is contained in:
parent
868d984987
commit
052fc35670
67
site.moon
67
site.moon
@ -63,9 +63,9 @@ titleize_slug = (slug="") ->
|
|||||||
|
|
||||||
template = [[
|
template = [[
|
||||||
<section>
|
<section>
|
||||||
<h3><a href="$target">$title</a></h3>
|
<h3><a href="$url">$title</a></h3>
|
||||||
<time>$publish_date</time> — $blurb
|
<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>
|
</section>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
@ -74,28 +74,38 @@ template = [[
|
|||||||
-- or like this
|
-- or like this
|
||||||
-- $each{list_posts(), "post"}[[$post]]
|
-- $each{list_posts(), "post"}[[$post]]
|
||||||
list_posts = (args={}) =>
|
list_posts = (args={}) =>
|
||||||
posts = @site\query_pages { is_a: "post" }
|
pages = @site\query_pages { is_a: "post" }
|
||||||
table.sort posts, (a, b) -> a.source > b.source
|
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,
|
common.fill_ignoring_pre template,
|
||||||
target: meta.target
|
title: title or titleize_slug id
|
||||||
title: meta.title or titleize_slug meta.id
|
publish_date: date
|
||||||
publish_date: publish_date source
|
blurb: blurb
|
||||||
blurb: meta.blurb
|
url: page\url_for!
|
||||||
|
|
||||||
-- call like this from a template: $(get_posts())[[<p>$target</p>]]
|
-- call like this from a template: $(get_posts())[[<p>$title</p>]]
|
||||||
-- or like this: $(get_posts({limit = 5}))[[<p>$target</p>]]
|
-- or like this: $(get_posts({limit = 5}))[[<p>$title</p>]]
|
||||||
get_posts = (args={}) =>
|
get_posts = (args={}) =>
|
||||||
posts = @site\query_pages { is_a: "post" }
|
pages = @site\query_pages { is_a: "post" }
|
||||||
table.sort posts, (a, b) -> a.source > b.source
|
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
|
title: title or titleize_slug id
|
||||||
post_title: meta.title or titleize_slug meta.id
|
publish_date: date
|
||||||
publish_date: publish_date source
|
blurb: blurb
|
||||||
blurb: meta.blurb
|
url: page\url_for!
|
||||||
}
|
}
|
||||||
|
|
||||||
-- replace '$if' helper function with cosmo's 'cif'
|
-- replace '$if' helper function with cosmo's 'cif'
|
||||||
@ -114,24 +124,21 @@ sitegen.create =>
|
|||||||
@list_posts = list_posts
|
@list_posts = list_posts
|
||||||
@get_posts = get_posts
|
@get_posts = get_posts
|
||||||
|
|
||||||
add "index.html", title: "Catalin Mititiuc", blah: {{say: "wan"},{say: "tuu"}}
|
add_all = (name="", files) ->
|
||||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
for path, target in pairs files
|
||||||
|
|
||||||
-- 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
|
id = extract_id path
|
||||||
|
|
||||||
add path,
|
add path,
|
||||||
target: Path.join Path.basepath(target), id
|
target: Path.join Path.basepath(target), id -- TODO reformat target
|
||||||
template: "post"
|
template: name
|
||||||
is_a: "post"
|
is_a: name
|
||||||
publish_date: publish_date path
|
publish_date: publish_date path
|
||||||
id: id
|
id: id
|
||||||
|
|
||||||
|
add "index.html", title: "Catalin Mititiuc"
|
||||||
|
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||||
|
add_all "post", documents "docs"
|
||||||
|
|
||||||
-- replace post markdown yaml headers with moonscript headers
|
-- replace post markdown yaml headers with moonscript headers
|
||||||
filter "docs", (body) =>
|
filter "docs", (body) =>
|
||||||
body\gsub "^%-%-%-.-%.%.%.", (yaml_header) ->
|
body\gsub "^%-%-%-.-%.%.%.", (yaml_header) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user