Refactor creation function
This commit is contained in:
parent
81e5bc4c69
commit
f6d8a1d7d8
44
site.moon
44
site.moon
@ -8,6 +8,10 @@ html = require "sitegen.html"
|
|||||||
lfs = require "lfs"
|
lfs = require "lfs"
|
||||||
date = require "date"
|
date = require "date"
|
||||||
|
|
||||||
|
-- Monkey-patch sitegen to use pandoc for markdown conversion
|
||||||
|
os.execute "moonc -t \\
|
||||||
|
/usr/local/openresty/luajit/share/lua/5.1/sitegen/renderers/ markdown.moon"
|
||||||
|
|
||||||
-- Change output dir to what Openresty prefers
|
-- Change output dir to what Openresty prefers
|
||||||
site.config.out_dir = "html/"
|
site.config.out_dir = "html/"
|
||||||
|
|
||||||
@ -35,42 +39,38 @@ 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
|
||||||
|
|
||||||
-- monkey-patch sitegen to use pandoc for markdown conversion
|
list_posts = (page, limit) ->
|
||||||
os.execute "moonc -t \\
|
posts = page.site\query_pages { is_a: "post" }
|
||||||
/usr/local/openresty/luajit/share/lua/5.1/sitegen/renderers/ markdown.moon"
|
table.sort posts, (a, b) -> a.source > b.source
|
||||||
|
|
||||||
|
html.build ->
|
||||||
|
[section {
|
||||||
|
h3 { a { href: meta.target .. ".html", meta.title or meta.id }}
|
||||||
|
time { publish_date source }
|
||||||
|
{ "—", if meta.blurb then text meta.blurb }
|
||||||
|
a { class: "read-post-link", href: meta.target .. ".html",
|
||||||
|
"Read post →"
|
||||||
|
}
|
||||||
|
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
||||||
|
|
||||||
sitegen.create =>
|
sitegen.create =>
|
||||||
@site_title = "WebDevCat.me · Catalin Mititiuc"
|
@site_title = "WebDevCat.me · Catalin Mititiuc"
|
||||||
@app_name = "stasis"
|
@app_name = "stasis"
|
||||||
@version = "0.2.12"
|
@version = "0.2.12"
|
||||||
|
@list_posts = list_posts
|
||||||
|
|
||||||
@list_posts = (page, limit) ->
|
add "index.html"
|
||||||
posts = page.site\query_pages { is_a: "post" }
|
|
||||||
table.sort posts, (a, b) -> a.source > b.source
|
|
||||||
|
|
||||||
html.build ->
|
|
||||||
[section {
|
|
||||||
h3 { a { href: meta.target .. ".html", meta.title or meta.id }}
|
|
||||||
time { publish_date source }
|
|
||||||
{ "—", if meta.blurb then text meta.blurb }
|
|
||||||
a { class: "read-post-link", href: meta.target .. ".html",
|
|
||||||
"Read post →"
|
|
||||||
}
|
|
||||||
} for { meta: meta, source: source } in *posts[1, limit or #posts]]
|
|
||||||
|
|
||||||
add "blog.html", target: "posts/index", template: "blog"
|
add "blog.html", target: "posts/index", template: "blog"
|
||||||
|
|
||||||
add path, target: out, template: "post", is_a: "post", post: {
|
add path, target: out, template: "post", is_a: "post", post: {
|
||||||
publish_date: publish_date(path)
|
publish_date: publish_date(path)
|
||||||
}, id: extract_id(path) for path, out in pairs posts "docs"
|
}, id: extract_id(path) for path, out in pairs posts "docs"
|
||||||
|
|
||||||
add "index.html"
|
|
||||||
|
|
||||||
-- 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) ->
|
||||||
moonscript_header = yaml_header\gsub "%-%-%-", "{"
|
header = yaml_header\gsub "%-%-%-", "{"
|
||||||
result = moonscript_header\gsub "%.%.%.", "}"
|
moonscript_header = header\gsub "%.%.%.", "}"
|
||||||
result
|
moonscript_header
|
||||||
|
|
||||||
copy "app.css"
|
copy "app.css"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user