WIP: list posts function
This commit is contained in:
parent
c8a1632902
commit
bae7126189
@ -1,3 +1,11 @@
|
||||
<h2>Posts</h2>
|
||||
|
||||
$list_posts2{limit = 3}[[
|
||||
<section>
|
||||
<h3><a href="$target">$post_title</a></h3>
|
||||
<time>$publish_date</time> — $blurb
|
||||
<a class="read-post-link" href="$target">Read post →</a>
|
||||
</section>
|
||||
]]
|
||||
|
||||
$list_posts
|
||||
|
38
site.moon
38
site.moon
@ -58,6 +58,16 @@ extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d"
|
||||
format_date = (str) -> date(str)\fmt "%b %d, %Y"
|
||||
publish_date = (path) -> format_date extract_date path
|
||||
|
||||
posts2 = (path=".") ->
|
||||
files = reverse get_files path
|
||||
|
||||
[{
|
||||
path: join(path, file)
|
||||
target: Path.join Path.basepath(target(file, "/posts")), extract_id(join(path, file))
|
||||
post_id: extract_id join(path, file)
|
||||
publish_date: publish_date join(path, file)
|
||||
} for file in *files]
|
||||
|
||||
common = require("sitegen.common")
|
||||
h = (word) -> word\sub(1, 1)\upper!
|
||||
t = (word) -> word\sub(2, -1)\lower!
|
||||
@ -83,7 +93,34 @@ list_posts = (page, limit) ->
|
||||
}
|
||||
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||
|
||||
-- list_posts2 = (page) ->
|
||||
-- posts = page.site\query_pages { is_a: "post" }
|
||||
-- table.sort posts, (a, b) -> a.source > b.source
|
||||
--
|
||||
-- list = [{
|
||||
-- target: meta.target
|
||||
-- post_title: meta.title or table.concat(titleize_slug(meta.id), " ")
|
||||
-- publish_date: publish_date source
|
||||
-- } for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||
-- p list
|
||||
-- list
|
||||
|
||||
cosmo = require "sitegen.cosmo"
|
||||
|
||||
list_posts2 = (page, arg={}) ->
|
||||
posts = page.site\query_pages { is_a: "post" }
|
||||
table.sort posts, (a, b) -> a.source > b.source
|
||||
|
||||
list = [{
|
||||
target: meta.target
|
||||
post_title: meta.title or table.concat(titleize_slug(meta.id), " ")
|
||||
publish_date: publish_date source
|
||||
blurb: meta.blurb
|
||||
} for { meta: meta, source: source } in *posts[1, arg.limit or #posts]]
|
||||
|
||||
for post in *list
|
||||
cosmo.yield post
|
||||
|
||||
html_renderer = require "sitegen.renderers.html"
|
||||
html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block
|
||||
html_renderer.cosmo_helpers.titleize = (slug) => html.build ->
|
||||
@ -94,6 +131,7 @@ sitegen.create =>
|
||||
@app_name = "stasis"
|
||||
@version = "0.2.12"
|
||||
@list_posts = list_posts
|
||||
@list_posts2 = list_posts2
|
||||
|
||||
add "index.html", title: "Catalin Mititiuc"
|
||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||
|
Loading…
x
Reference in New Issue
Block a user