Clean up target logic
This commit is contained in:
parent
9eb06e2789
commit
51717bd50c
31
site.moon
31
site.moon
@ -43,21 +43,20 @@ rootname = (str) ->
|
|||||||
result = string.gsub str, "%..+", ""
|
result = string.gsub str, "%..+", ""
|
||||||
result
|
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_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) -> format_date extract_date path
|
publish_date = (path) -> format_date extract_date path
|
||||||
|
|
||||||
last = (list) -> list[#list]
|
sanitize = (filename) ->
|
||||||
join = (first, last, delimiter="/") -> table.concat { first, last }, delimiter
|
filename\gsub "#{escape_patt(extract_date(filename) .. "-")}/?", ""
|
||||||
reverse = (list={}) -> [item for item in *list[#list, 1, -1]]
|
|
||||||
target = (path, prefix=".") ->
|
|
||||||
|
|
||||||
a = rootname(last(common.split path, "/"))
|
target = (path, prefix=".") ->
|
||||||
b = a\gsub "#{escape_patt(extract_date(a) .. "-")}/?", ""
|
filename = rootname(last(common.split path, "/"))
|
||||||
p b
|
Path.join prefix, sanitize(filename)
|
||||||
b
|
|
||||||
Path.join prefix, a\gsub("#{escape_patt(extract_date(a) .. "-")}/?", "")
|
|
||||||
|
|
||||||
h = (word) -> word\sub(1, 1)\upper!
|
h = (word) -> word\sub(1, 1)\upper!
|
||||||
t = (word) -> word\sub(2, -1)\lower!
|
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
|
html_renderer.cosmo_helpers.titleize = (slug) => titleize_slug slug
|
||||||
|
|
||||||
documents = (path=".") ->
|
documents = (path=".") ->
|
||||||
files = reverse get_files path
|
[Path.join path, file for file in *reverse get_files path]
|
||||||
{join(path, file), target(file, "/posts") for file in *files}
|
|
||||||
|
|
||||||
clean = (target) ->
|
|
||||||
target\gsub "#{escape_patt(extract_date(target) .. "-")}/?", ""
|
|
||||||
|
|
||||||
sitegen.create =>
|
sitegen.create =>
|
||||||
@site_title = "WebDevCat.me"
|
@site_title = "WebDevCat.me"
|
||||||
@ -120,15 +115,13 @@ sitegen.create =>
|
|||||||
@list_posts = list_posts @, template
|
@list_posts = list_posts @, template
|
||||||
|
|
||||||
add_all = (name, files) ->
|
add_all = (name, files) ->
|
||||||
for path, _ in pairs files
|
for path in *files
|
||||||
id = extract_id path
|
|
||||||
|
|
||||||
add path,
|
add path,
|
||||||
target: clean(target(path, "/posts"))
|
target: target(path, "/posts")
|
||||||
template: name
|
template: name
|
||||||
is_a: name
|
is_a: name
|
||||||
publish_date: publish_date path
|
publish_date: publish_date path
|
||||||
id: id
|
id: extract_id path
|
||||||
|
|
||||||
add "index.html", title: "Catalin Mititiuc"
|
add "index.html", title: "Catalin Mititiuc"
|
||||||
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
add "blog.html", title: "Posts", target: "posts/index", template: "blog"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user