diff --git a/site.moon b/site.moon index bc12720..2792127 100644 --- a/site.moon +++ b/site.moon @@ -43,21 +43,20 @@ rootname = (str) -> result = string.gsub str, "%..+", "" result +last = (list) -> list[#list] +reverse = (list={}) -> [item for item in *list[#list, 1, -1]] + 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 -last = (list) -> list[#list] -join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter -reverse = (list={}) -> [item for item in *list[#list, 1, -1]] -target = (path, prefix=".") -> +sanitize = (filename) -> + filename\gsub "#{escape_patt(extract_date(filename) .. "-")}/?", "" - a = rootname(last(common.split path, "/")) - b = a\gsub "#{escape_patt(extract_date(a) .. "-")}/?", "" - p b - b - Path.join prefix, a\gsub("#{escape_patt(extract_date(a) .. "-")}/?", "") +target = (path, prefix=".") -> + filename = rootname(last(common.split path, "/")) + Path.join prefix, sanitize(filename) h = (word) -> word\sub(1, 1)\upper! t = (word) -> word\sub(2, -1)\lower! @@ -107,11 +106,7 @@ html_renderer.cosmo_helpers.if = (args, has_block) => cosmo.cif args, has_block html_renderer.cosmo_helpers.titleize = (slug) => titleize_slug slug documents = (path=".") -> - files = reverse get_files path - {join(path, file), target(file, "/posts") for file in *files} - -clean = (target) -> - target\gsub "#{escape_patt(extract_date(target) .. "-")}/?", "" + [Path.join path, file for file in *reverse get_files path] sitegen.create => @site_title = "WebDevCat.me" @@ -120,15 +115,13 @@ sitegen.create => @list_posts = list_posts @, template add_all = (name, files) -> - for path, _ in pairs files - id = extract_id path - + for path in *files add path, - target: clean(target(path, "/posts")) + target: target(path, "/posts") template: name is_a: name publish_date: publish_date path - id: id + id: extract_id path add "index.html", title: "Catalin Mititiuc" add "blog.html", title: "Posts", target: "posts/index", template: "blog"