hikaru-coffee
Version:
A static site generator that generates routes based on directories naturally.
133 lines (117 loc) • 3.16 kB
JavaScript
// Generated by CoffeeScript 2.3.1
(function() {
var Category, File, Site, Tag;
Site = class Site {
constructor(workDir) {
this.get = this.get.bind(this);
this.set = this.set.bind(this);
// Put a file into an array.
// If a file with the same docPath already in array, replace it.
// Else append it.
this.put = this.put.bind(this);
this.del = this.del.bind(this);
this.raw = this.raw.bind(this);
this._ = {
"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 !== "string" || !(key in this._)) {
throw new TypeError(`key must be a string in ${Object.keys(this._)}!`);
}
return this._[key];
}
set(key, value) {
if (typeof key !== "string") {
throw new TypeError("key must be a string!");
}
return this._[key] = value;
}
put(key, file) {
var i, j, ref;
if ((key == null) || (file == null)) {
return;
}
for (i = j = 0, ref = this._[key].length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
if (this._[key][i]["docPath"] === file["docPath"] && this._[key][i]["docDir"] === file["docDir"]) {
if (key === "posts") {
console.log(file);
}
this._[key][i] = file;
return;
}
}
return this._[key].push(file);
}
del(key, file) {
var i, j, ref;
if ((key == null) || (file == null)) {
return null;
}
for (i = j = 0, ref = this._[key].length; (0 <= ref ? j < ref : j > ref); i = 0 <= ref ? ++j : --j) {
if (this._[key][i]["srcPath"] === file["srcPath"] && this._[key][i]["srcDir"] === file["srcDir"]) {
return this._[key].splice(i, 1);
}
}
return null;
}
raw() {
return this._;
}
};
File = class File {
constructor(docDir, srcDir, srcPath) {
this.docDir = docDir;
this.docPath = null;
this.srcDir = srcDir;
this.srcPath = srcPath;
this.date = null;
this.title = null;
this.name = null;
this.raw = null;
this.text = null;
this.content = null;
this.type = null;
this.frontMatter = {};
this.categories = [];
this.tags = [];
this.excerpt = null;
this.more = null;
this.pageArray = [];
this.pageIndex = null;
}
};
Category = class Category {
constructor(name, posts = [], subs = []) {
this.name = name;
this.posts = posts;
this.subs = subs;
}
};
Tag = class Tag {
constructor(name, posts = []) {
this.name = name;
this.posts = posts;
}
};
module.exports = {
"Site": Site,
"File": File,
"Category": Category,
"Tag": Tag
};
}).call(this);