Make a titleized slug the default post title

This commit is contained in:
Catalin Constantin Mititiuc 2025-05-16 23:27:03 -07:00
parent 20477d99fb
commit 0bbf998ebb
3 changed files with 13 additions and 5 deletions

View File

@ -64,8 +64,7 @@
## todo
* titleize slugs
* page titles
* treesitter highlighting for moonscript
* penlight library
* sitegen plugins

View File

@ -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) =>

View File

@ -3,7 +3,7 @@ $wrap{"blog"}
<article>
<header>
<div>
<h2>$(title or id)</h2>
<h2>$(title or to_title(id))</h2>
<time>$publish_date</time>
</div>
</header>