Don't try to access globals

This commit is contained in:
Catalin Constantin Mititiuc 2025-05-23 16:39:17 -07:00
parent 98e219ac50
commit 60dfc1e033

View File

@ -6,7 +6,6 @@ common = require "sitegen.common"
cosmo = require "sitegen.cosmo" cosmo = require "sitegen.cosmo"
date = require "date" date = require "date"
html_renderer = require "sitegen.renderers.html"
import tag from html import tag from html
import escape_patt from require "sitegen.common" import escape_patt from require "sitegen.common"
import p from require "moon" -- debug import p from require "moon" -- debug
@ -51,13 +50,13 @@ extract_id = (source) -> string.match Path.filename(source), "%a[%w%-]+"
extract_date = (source) -> string.match Path.filename(source), "%d+%-%d%d%-%d%d" 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 using nil) ->
date = extract_date path
date, format_date date
strip_date = (filename) -> strip_date = (filename) ->
filename\gsub "#{escape_patt(extract_date(filename) .. "-")}/?", "" filename\gsub "#{escape_patt(extract_date(filename) .. "-")}/?", ""
publish_date = (path using extract_date, format_date) ->
date = extract_date path
date, format_date date
target = (path, prefix=".") -> target = (path, prefix=".") ->
filename = rootname last common.split path, "/" filename = rootname last common.split path, "/"
Path.join prefix, strip_date filename Path.join prefix, strip_date filename
@ -70,9 +69,6 @@ titleize_slug = (slug="") ->
words = [{ titleize word } for word in *common.split slug, "-"] words = [{ titleize word } for word in *common.split slug, "-"]
table.concat [head .. tail for { head, tail } in *words], " " table.concat [head .. tail for { head, tail } in *words], " "
-- replace '$if' helper function with cosmo's 'cif'
html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block
files_from = (path=".") -> files_from = (path=".") ->
[Path.join path, file for file in *reverse get_files path] [Path.join path, file for file in *reverse get_files path]
@ -86,7 +82,10 @@ sitegen.create =>
@site_title = "WebDevCat.me" @site_title = "WebDevCat.me"
@app_name = "stasis" @app_name = "stasis"
@version = "0.2.12" @version = "0.2.12"
-- helpers
@titleize = (slug) => titleize_slug slug @titleize = (slug) => titleize_slug slug
@cif = (args, has_block) => cosmo.cif args, has_block
@just_render_the_damn_list = (arg={}, _) => @just_render_the_damn_list = (arg={}, _) =>
posts = [post for post in *get_posts @, arg.limit] posts = [post for post in *get_posts @, arg.limit]
@ -97,7 +96,7 @@ sitegen.create =>
return for post in *posts return for post in *posts
{:title, :blurb, :id, publish_date: {iso, pretty}} = post.meta {:title, :blurb, :id, publish_date: {iso, pretty}} = post.meta
url = rootname post\url_for! url = rootname post\url_for!
blurb = html.builders.raw!(html.build -> blurb) if blurb if blurb then blurb = html.builders.raw! blurb
section { section {
h3 { a { title or titleize_slug(id), href: url }} h3 { a { title or titleize_slug(id), href: url }}