Make a titleized slug the default post title

This commit is contained in:
Catalin Constantin Mititiuc 2025-06-16 20:18:05 -07:00
parent 09918abe97
commit d1b37461e0
3 changed files with 13 additions and 5 deletions

View File

@ -64,8 +64,7 @@
## todo ## todo
* titleize slugs * page titles
* treesitter highlighting for moonscript * treesitter highlighting for moonscript
* penlight library * 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" 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
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) -> 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
@ -65,7 +74,7 @@ list_posts = (page, limit) ->
import section, h3, a, time from tag import section, h3, a, time from tag
[section { [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 } time { publish_date source }
{ "—", if meta.blurb then html.builders.text! meta.blurb } { "—", if meta.blurb then html.builders.text! meta.blurb }
a { class: "read-post-link", href: meta.target .. ".html", 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]] } 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"
@ -90,6 +98,7 @@ sitegen.create =>
is_a: "post" is_a: "post"
publish_date: publish_date(path) publish_date: publish_date(path)
id: extract_id(path) id: extract_id(path)
to_title: (slug) -> table.concat 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) =>

View File

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