From 9f122483034d6fff9934a25c68fc2e6a2a39ac7f Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Thu, 15 May 2025 15:35:51 -0700 Subject: [PATCH] Render posts with a function so we can change the count --- README.md | 1 - blog.html | 2 +- index.html | 2 +- posts.moon | 35 ----------------------------------- site.moon | 24 ++++++++++++++++++++---- 5 files changed, 22 insertions(+), 42 deletions(-) delete mode 100644 posts.moon diff --git a/README.md b/README.md index 5d5105d..442d9e8 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ ## todo * titleize slugs -* limit number of posts on home page * treesitter highlighting for moonscript * penlight library diff --git a/blog.html b/blog.html index 97ae205..230e60e 100644 --- a/blog.html +++ b/blog.html @@ -1,4 +1,4 @@

Posts

-$render{"posts"} +$list_posts diff --git a/index.html b/index.html index f5c0bed..28590cb 100644 --- a/index.html +++ b/index.html @@ -10,7 +10,7 @@ $render{"templates/wares"}

Posts

-$render{"posts"} +$(list_posts(5))

View more posts diff --git a/posts.moon b/posts.moon deleted file mode 100644 index 2305e3e..0000000 --- a/posts.moon +++ /dev/null @@ -1,35 +0,0 @@ -date = require "date" -path = require "sitegen.path" --- import slugify from "sitegen.common" -common = require "sitegen.common" - -rootname = (str) -> - result = string.gsub str, "%..+", "" - result - -extract_id = (source) -> string.match path.filename(source), "%a[%w%-]+" -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 - -pages = site\query_pages { is_a: "post" } -table.sort pages, (a, b) -> a.source > b.source - -html -> - [tag["section"] { - tag["h3"] { - tag["a"] { - href: p.meta.target .. ".html", - p.meta.title or p.meta.id - } - } - - tag["time"] { publish_date p.source } - { "—", if p.meta.blurb then text p.meta.blurb } - - tag["a"] { - class: "read-post-link", - href: p.meta.target .. ".html", - "Read post →" - } - } for _, p in ipairs pages] diff --git a/site.moon b/site.moon index 8f07a78..f724c26 100644 --- a/site.moon +++ b/site.moon @@ -2,6 +2,7 @@ sitegen = require "sitegen" tools = require "sitegen.tools" site = require "sitegen.site" path = require "sitegen.path" +html = require "sitegen.html" -- import slugify from "sitegen.common" lfs = require "lfs" @@ -10,7 +11,7 @@ date = require "date" -- Change output dir to what Openresty prefers site.config.out_dir = "html/" --- Deactivate "pygments" plugin +-- Deactivate "pygments" plugin because it conflicts with pandoc highlighting site.default_plugins = for v in *site.default_plugins if v\find "pygments" then continue else v @@ -43,16 +44,31 @@ sitegen.create => @app_name = "stasis" @version = "0.2.12" - add "index.html" + @list_posts = (page, limit) -> + 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 path, target: out, template: "post", is_a: "post", post: { publish_date: publish_date(path) }, id: extract_id(path) for path, out in pairs posts "docs" - -- replace yaml headers with moonscript headers + add "index.html" + + -- replace post markdown yaml headers with moonscript headers filter "docs", (body) => - body\gsub "^%s*%-%-%-.-%.%.%.", (yaml_header) -> + body\gsub "^%-%-%-.-%.%.%.", (yaml_header) -> moonscript_header = yaml_header\gsub "%-%-%-", "{" result = moonscript_header\gsub "%.%.%.", "}" result