WIP:
This commit is contained in:
parent
630fa60191
commit
1154bd5f54
11
index.html
11
index.html
@ -6,7 +6,16 @@ $render{"templates/wares"}
|
|||||||
|
|
||||||
<h2>Posts</h2>
|
<h2>Posts</h2>
|
||||||
|
|
||||||
$list_posts{limit = 5}
|
$({{go = "yeah"}})[[<p>$go! I can't believe this thing works!</p>]]
|
||||||
|
$(blah)[[$say, ]]
|
||||||
|
$blah[[<p>$say</p>]]
|
||||||
|
$(get_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>
|
||||||
|
88
site.moon
88
site.moon
@ -2,13 +2,14 @@ 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"
|
||||||
|
common = require "sitegen.common"
|
||||||
cosmo = require "sitegen.cosmo"
|
cosmo = require "sitegen.cosmo"
|
||||||
date = require "date"
|
date = require "date"
|
||||||
|
|
||||||
html_renderer = require "sitegen.renderers.html"
|
html_renderer = require "sitegen.renderers.html"
|
||||||
import tag from html
|
import tag from html
|
||||||
import escape_patt from require "sitegen.common"
|
import escape_patt from require "sitegen.common"
|
||||||
import p from require "moon"
|
import p from require "moon" -- debug
|
||||||
|
|
||||||
-- Change output dir to what Openresty prefers
|
-- Change output dir to what Openresty prefers
|
||||||
Site.config.out_dir = "html/"
|
Site.config.out_dir = "html/"
|
||||||
@ -51,75 +52,89 @@ join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter
|
|||||||
reverse = (list={}) -> [item for item in *list[#list, 1, -1]]
|
reverse = (list={}) -> [item for item in *list[#list, 1, -1]]
|
||||||
target = (path, prefix) -> join prefix, rootname(last(split path))
|
target = (path, prefix) -> join prefix, rootname(last(split path))
|
||||||
|
|
||||||
posts = (path=".") ->
|
|
||||||
files = reverse get_files path
|
|
||||||
{join(path, file), target(file, "/posts") for file in *files}
|
|
||||||
|
|
||||||
extract_id = (source) -> string.match Path.filename(source), "%a[%w%-]+"
|
extract_id = (source) -> string.match Path.filename(source), "%a[%w%-]+"
|
||||||
extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d"
|
extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d"
|
||||||
format_date = (str) -> date(str)\fmt "%b %d, %Y"
|
format_date = (str) -> date(str)\fmt "%b %d, %Y"
|
||||||
publish_date = (path) -> format_date extract_date path
|
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!
|
h = (word) -> word\sub(1, 1)\upper!
|
||||||
t = (word) -> word\sub(2, -1)\lower!
|
t = (word) -> word\sub(2, -1)\lower!
|
||||||
titleize = (word) -> h(word), t(word)
|
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, "-"]
|
||||||
table.concat [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>
|
||||||
|
]]
|
||||||
|
|
||||||
|
-- limit the number with args {limit = 5}
|
||||||
list_posts = (page, args={}) ->
|
list_posts = (page, args={}) ->
|
||||||
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
|
||||||
|
|
||||||
table.concat [common.fill_ignoring_pre [[
|
a = table.concat [common.fill_ignoring_pre 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>
|
|
||||||
]], {
|
|
||||||
target: meta.target
|
target: meta.target
|
||||||
post_title: meta.title or 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, args.limit or #posts]]
|
} for { meta: meta, source: source } in *posts[1, args.limit or #posts]]
|
||||||
|
|
||||||
list_posts2 = (page, args={}) ->
|
p for { meta: meta, source: source } in *posts[1, args.limit or #posts]
|
||||||
pages = page.site\query_pages { is_a: "post" }
|
common.fill_ignoring_pre template, {
|
||||||
table.sort pages, (a, b) -> a.source > b.source
|
target: "target"
|
||||||
|
post_title: "post_title"
|
||||||
|
publish_date: "publish_date"
|
||||||
|
blurb: "blurb"
|
||||||
|
}
|
||||||
|
a
|
||||||
|
|
||||||
posts = [{
|
get_posts = (args={}) =>
|
||||||
|
posts = @site\query_pages { is_a: "post" }
|
||||||
|
table.sort posts, (a, b) -> a.source > b.source
|
||||||
|
for { meta: meta, source: source } in *posts[1, args.limit or #posts]
|
||||||
|
{
|
||||||
target: meta.target
|
target: meta.target
|
||||||
post_title: meta.title or 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 *pages[1, args.limit or #pages]]
|
}
|
||||||
|
|
||||||
for post in *posts do cosmo.yield post
|
|
||||||
|
|
||||||
|
-- replace '$if' helper function with cosmo's 'cif'
|
||||||
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
|
||||||
html_renderer.cosmo_helpers.titleize = (slug) => html.build ->
|
-- add a '$titleize' helper function
|
||||||
titleize_slug(slug) if slug
|
html_renderer.cosmo_helpers.titleize = (slug) => titleize_slug slug
|
||||||
|
|
||||||
|
documents = (path=".") ->
|
||||||
|
files = reverse get_files path
|
||||||
|
{join(path, file), target(file, "/posts") for file in *files}
|
||||||
|
|
||||||
|
-- get_some = () -> {{say: "this"}, {say: "that"}}
|
||||||
|
get_some = (args={}) =>
|
||||||
|
posts = @site\query_pages { is_a: "post" }
|
||||||
|
table.sort posts, (a, b) -> a.source > b.source
|
||||||
|
|
||||||
|
[{
|
||||||
|
target: post.meta.target
|
||||||
|
post_title: post.meta.title or titleize_slug post.meta.id
|
||||||
|
publish_date: publish_date post.source
|
||||||
|
blurb: post.meta.blurb
|
||||||
|
} for post in *posts[1, args.limit or #posts]]
|
||||||
|
|
||||||
sitegen.create =>
|
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_posts
|
||||||
|
@get_posts = get_posts
|
||||||
|
@get_some = get_some
|
||||||
|
|
||||||
add "index.html", title: "Catalin Mititiuc"
|
add "index.html", title: "Catalin Mititiuc", blah: {{say: "wan"},{say: "tuu"}}
|
||||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||||
|
|
||||||
-- add "about.html", some: {
|
-- add "about.html", some: {
|
||||||
@ -127,7 +142,7 @@ sitegen.create =>
|
|||||||
-- { one: "A", two: "B" }
|
-- { one: "A", two: "B" }
|
||||||
-- }, cif: cosmo.cif, math: math, x: 2
|
-- }, cif: cosmo.cif, math: math, x: 2
|
||||||
|
|
||||||
for path, target in pairs posts "docs"
|
for path, target in pairs documents "docs"
|
||||||
id = extract_id path
|
id = extract_id path
|
||||||
|
|
||||||
add path,
|
add path,
|
||||||
@ -136,7 +151,6 @@ sitegen.create =>
|
|||||||
is_a: "post"
|
is_a: "post"
|
||||||
publish_date: publish_date path
|
publish_date: publish_date path
|
||||||
id: id
|
id: id
|
||||||
-- titleize: (slug) -> html.build -> titleize_slug(slug)
|
|
||||||
|
|
||||||
-- replace post markdown yaml headers with moonscript headers
|
-- replace post markdown yaml headers with moonscript headers
|
||||||
filter "docs", (body) =>
|
filter "docs", (body) =>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user