diff --git a/README.md b/README.md index 1d5aa82..e071749 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,7 @@ ## todo -* titleize slugs +* page titles * treesitter highlighting for moonscript * penlight library -* sitegen plugins diff --git a/site.moon b/site.moon index d0582ac..ef909c6 100644 --- a/site.moon +++ b/site.moon @@ -57,6 +57,15 @@ 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 +common = require("sitegen.common") +h = (word) -> word\sub(1, 1)\upper! +t = (word) -> word\sub(2, -1)\lower! +titleize = (word) -> h(word), t(word) + +titleize_slug = (slug) -> + words = [{ titleize word } for word in *common.split slug, "-"] + [head .. tail for { head, tail } in *words] + list_posts = (page, limit) -> posts = page.site\query_pages { is_a: "post" } table.sort posts, (a, b) -> a.source > b.source @@ -65,7 +74,7 @@ list_posts = (page, limit) -> import section, h3, a, time from tag [section { - h3 { a { href: meta.target .. ".html", meta.title or meta.id }} + h3 { a { href: meta.target .. ".html", 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 .. ".html", @@ -73,7 +82,6 @@ list_posts = (page, limit) -> } } for { meta: meta, source: source } in *posts[1, limit or #posts]] - sitegen.create => @site_title = "WebDevCat.me · Catalin Mititiuc" @app_name = "stasis" @@ -90,6 +98,7 @@ sitegen.create => is_a: "post" publish_date: publish_date(path) id: extract_id(path) + to_title: (slug) -> table.concat titleize_slug(slug), " " -- replace post markdown yaml headers with moonscript headers filter "docs", (body) => diff --git a/templates/post.html b/templates/post.html index 702902b..62b97dd 100644 --- a/templates/post.html +++ b/templates/post.html @@ -3,7 +3,7 @@ $wrap{"blog"}
-

$(title or id)

+

$(title or to_title(id))