WIP: use cosmo.f to list posts?
This commit is contained in:
parent
861ec2c55c
commit
52342a77e5
@ -1,11 +1,11 @@
|
|||||||
<h2>Posts</h2>
|
<h2>Posts</h2>
|
||||||
|
|
||||||
$list_posts2{limit = 3}[[
|
$lp
|
||||||
|
|
||||||
|
$list_posts[[
|
||||||
<section>
|
<section>
|
||||||
<h3><a href="$target">$post_title</a></h3>
|
<h3><a href="$target">$post_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="$target">Read post →</a>
|
||||||
</section>
|
</section>
|
||||||
]]
|
]]
|
||||||
|
|
||||||
$list_posts
|
|
||||||
|
@ -6,7 +6,13 @@ $render{"templates/wares"}
|
|||||||
|
|
||||||
<h2>Posts</h2>
|
<h2>Posts</h2>
|
||||||
|
|
||||||
$(list_posts(5))
|
$list_posts{limit = 5}[[
|
||||||
|
<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>
|
||||||
|
]]
|
||||||
|
|
||||||
<h4 style="text-align: center;">
|
<h4 style="text-align: center;">
|
||||||
<a href="$root/posts">View more posts</a>
|
<a href="$root/posts">View more posts</a>
|
||||||
|
78
site.moon
78
site.moon
@ -2,6 +2,7 @@ sitegen = require "sitegen"
|
|||||||
Site = require "sitegen.site"
|
Site = require "sitegen.site"
|
||||||
Path = require "sitegen.path"
|
Path = require "sitegen.path"
|
||||||
html = require "sitegen.html"
|
html = require "sitegen.html"
|
||||||
|
cosmo = require "sitegen.cosmo"
|
||||||
date = require "date"
|
date = require "date"
|
||||||
|
|
||||||
import tag from html
|
import tag from html
|
||||||
@ -75,51 +76,52 @@ titleize = (word) -> h(word), t(word)
|
|||||||
|
|
||||||
titleize_slug = (slug) ->
|
titleize_slug = (slug) ->
|
||||||
words = [{ titleize word } for word in *common.split slug, "-"]
|
words = [{ titleize word } for word in *common.split slug, "-"]
|
||||||
[head .. tail for { head, tail } in *words]
|
table.concat [head .. tail for { head, tail } in *words]
|
||||||
|
|
||||||
|
template = [[
|
||||||
|
<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 = (page, limit) ->
|
list_posts = (page, limit) ->
|
||||||
posts = page.site\query_pages { is_a: "post" }
|
posts = page.site\query_pages { is_a: "post" }
|
||||||
table.sort posts, (a, b) -> a.source > b.source
|
table.sort posts, (a, b) -> a.source > b.source
|
||||||
|
|
||||||
html.build ->
|
table.concat [cosmo.f(template) {
|
||||||
import section, h3, a, time from tag
|
|
||||||
|
|
||||||
[section {
|
|
||||||
h3 { a { href: meta.target, meta.title or titleize_slug meta.id }}
|
|
||||||
time { publish_date source }
|
|
||||||
{ "—", if meta.blurb then html.builders.text! meta.blurb }
|
|
||||||
a { class: "read-post-link", href: meta.target,
|
|
||||||
"Read post →"
|
|
||||||
}
|
|
||||||
} 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
|
target: meta.target
|
||||||
post_title: meta.title or table.concat(titleize_slug(meta.id), " ")
|
post_title: meta.title or titleize_slug meta.id
|
||||||
publish_date: publish_date source
|
publish_date: publish_date source
|
||||||
blurb: meta.blurb
|
blurb: meta.blurb
|
||||||
} for { meta: meta, source: source } in *posts[1, arg.limit or #posts]]
|
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||||
|
-- html.build ->
|
||||||
|
-- import section, h3, a, time from tag
|
||||||
|
--
|
||||||
|
-- [section {
|
||||||
|
-- h3 { a { href: meta.target, meta.title or titleize_slug meta.id }}
|
||||||
|
-- time { publish_date source }
|
||||||
|
-- { "—", if meta.blurb then html.builders.text! meta.blurb }
|
||||||
|
-- a { class: "read-post-link", href: meta.target,
|
||||||
|
-- "Read post →"
|
||||||
|
-- }
|
||||||
|
-- } for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||||
|
|
||||||
for post in *list
|
|
||||||
cosmo.yield post
|
|
||||||
|
list_posts2 = (page, args={}) ->
|
||||||
|
pages = page.site\query_pages { is_a: "post" }
|
||||||
|
table.sort pages, (a, b) -> a.source > b.source
|
||||||
|
|
||||||
|
posts = [{
|
||||||
|
target: meta.target
|
||||||
|
post_title: meta.title or titleize_slug(meta.id)
|
||||||
|
publish_date: publish_date source
|
||||||
|
blurb: meta.blurb
|
||||||
|
} for { meta: meta, source: source } in *pages[1, args.limit or #pages]]
|
||||||
|
|
||||||
|
for post in *posts do cosmo.yield post
|
||||||
|
|
||||||
html_renderer = require "sitegen.renderers.html"
|
html_renderer = require "sitegen.renderers.html"
|
||||||
html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block
|
html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block
|
||||||
@ -130,8 +132,8 @@ sitegen.create =>
|
|||||||
@site_title = "WebDevCat.me"
|
@site_title = "WebDevCat.me"
|
||||||
@app_name = "stasis"
|
@app_name = "stasis"
|
||||||
@version = "0.2.12"
|
@version = "0.2.12"
|
||||||
@list_posts = list_posts
|
@list_posts = list_posts2
|
||||||
@list_posts2 = list_posts2
|
@lp = list_posts
|
||||||
|
|
||||||
add "index.html", title: "Catalin Mititiuc"
|
add "index.html", title: "Catalin Mititiuc"
|
||||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user