hikaru-coffee
Version:
A static site generator that generates routes based on directories naturally.
96 lines (86 loc) • 2.1 kB
text/coffeescript
class Site
constructor: (workDir) ->
= {
"workDir": workDir,
"siteConfig": {},
"themeConfig": {},
"templates": {},
"assets": [],
"pages": [],
"subs": [],
"posts": [],
"files": [],
"categories": [],
# Flattend categories length.
"categoriesLength": 0,
"tags": [],
# Flattend tags length.
"tagsLength": 0
}
get: (key) =>
if typeof(key) isnt "string" or key not of
throw new TypeError("key must be a string in #{Object.keys(@_)}!")
return [key]
set: (key, value) =>
if typeof(key) isnt "string"
throw new TypeError("key must be a string!")
[key] = value
# Put a file into an array.
# If a file with the same docPath already in array, replace it.
# Else append it.
put: (key, file) =>
if not key? or not file?
return
for i in [0...[key].length]
if [key][i]["docPath"] is file["docPath"] and
[key][i]["docDir"] is file["docDir"]
if key is "posts"
console.log(file)
[key][i] = file
return
[key].push(file)
del: (key, file) =>
if not key? or not file?
return null
for i in [0...[key].length]
if [key][i]["srcPath"] is file["srcPath"] and
[key][i]["srcDir"] is file["srcDir"]
return [key].splice(i, 1)
return null
raw: () =>
return
class File
constructor: (docDir, srcDir, srcPath) ->
= docDir
= null
= srcDir
= srcPath
= null
= null
= null
= null
= null
= null
= null
= {}
= []
= []
= null
= null
= []
= null
class Category
constructor: (name, posts = [], subs = []) ->
= name
= posts
= subs
class Tag
constructor: (name, posts = []) ->
= name
= posts
module.exports = {
"Site": Site,
"File": File,
"Category": Category,
"Tag": Tag
}