Refactor posts function to reduce line length
This commit is contained in:
parent
08f67c9be3
commit
d334aaf003
16
site.moon
16
site.moon
@ -5,22 +5,16 @@ rootname = (str) ->
|
|||||||
result = string.gsub str, "%..+", ""
|
result = string.gsub str, "%..+", ""
|
||||||
result
|
result
|
||||||
|
|
||||||
last = (list) -> list[#list]
|
|
||||||
|
|
||||||
split = (str, delimiter="/") ->
|
split = (str, delimiter="/") ->
|
||||||
[capture for capture in string.gmatch str, "[^#{delimiter}]+"]
|
[capture for capture in string.gmatch str, "[^#{delimiter}]+"]
|
||||||
|
|
||||||
join = (first, last, delimiter="/") -> table.concat({first, last}, delimiter)
|
last = (list) -> list[#list]
|
||||||
target = (path, prefix) -> join(prefix, rootname(last(split path)))
|
join = (first, last, delimiter="/") -> table.concat {first, last}, delimiter
|
||||||
|
target = (path, prefix) -> join prefix, rootname(last(split path))
|
||||||
-- posts = (path=".") ->
|
|
||||||
-- {join(path, file), target(file, "/posts") for file in lfs.dir path when file != "." and file != ".."}
|
|
||||||
|
|
||||||
posts = (path=".") ->
|
posts = (path=".") ->
|
||||||
files = [file for file in lfs.dir(path) when file != "." and file != ".."]
|
files = [file for file in lfs.dir path when file != "." and file != ".."]
|
||||||
tuples = for _, file in ipairs files
|
{join(path, file), target(file, "/posts") for _, file in ipairs files}
|
||||||
{join(path, file), target(file, "/posts")}
|
|
||||||
{unpack tup for tup in *tuples}
|
|
||||||
|
|
||||||
sitegen.create =>
|
sitegen.create =>
|
||||||
@title = "Hello World"
|
@title = "Hello World"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user