summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/backbone/page.js20
-rw-r--r--lib/book.js6
-rw-r--r--lib/fs/index.js5
-rw-r--r--lib/fs/node.js5
4 files changed, 33 insertions, 3 deletions
diff --git a/lib/backbone/page.js b/lib/backbone/page.js
index 7872181..c75c434 100644
--- a/lib/backbone/page.js
+++ b/lib/backbone/page.js
@@ -16,10 +16,18 @@ function Page(book, filename) {
this.book = book;
this.log = this.book.log;
+ // Current content
this.content = '';
+
+ // Relative path to the page
this.path = filename;
+
+ // Absolute path to the page
this.rawPath = this.book.resolve(filename);
+ // Last modification date
+ this.mtime = 0;
+
// Can we parse it?
extension = path.extname(this.path);
this.parser = parsers.get(extension);
@@ -44,8 +52,14 @@ Page.prototype.update = function(content) {
// Read the page as a string
Page.prototype.read = function() {
- return this.book.readFile(this.path)
- .then(this.update);
+ var that = this;
+
+ return this.book.statFile(this.path)
+ .then(function(stat) {
+ that.mtime = stat.mtime;
+ return that.book.readFile(that.path);
+ })
+ .then(this.update);
};
// Parse the page and return its content
@@ -67,7 +81,7 @@ Page.prototype.parse = function() {
return that.book.template.renderString(that.content, {
file: {
path: that.path,
- mtime: 0 //todo: stat.mtime
+ mtime: that.mtime
}
}, {
file: that.path
diff --git a/lib/book.js b/lib/book.js
index e762ad9..f615833 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -239,6 +239,12 @@ Book.prototype.readFile = function(filename) {
return this.fs.readAsString(this.resolve(filename));
};
+// Get stat infos about a file
+Book.prototype.statFile = function(filename) {
+ if (this.isFileIgnored(filename)) return Promise.reject(new error.FileNotFoundError({ filename: filename }));
+ return this.fs.stat(this.resolve(filename));
+};
+
// Find a parsable file using a filename
Book.prototype.findParsableFile = function(filename) {
var that = this;
diff --git a/lib/fs/index.js b/lib/fs/index.js
index 7b8fc46..bcd9345 100644
--- a/lib/fs/index.js
+++ b/lib/fs/index.js
@@ -30,6 +30,11 @@ FS.prototype.read = function(filename) {
// To implement for each fs
};
+// Read stat infos about a file
+FS.prototype.stat = function(filename) {
+ // To implement for each fs
+};
+
// Write a file and returns a promise
FS.prototype.write = function(filename, buffer) {
// To implement for each fs
diff --git a/lib/fs/node.js b/lib/fs/node.js
index 5994c2e..f9a885d 100644
--- a/lib/fs/node.js
+++ b/lib/fs/node.js
@@ -28,6 +28,11 @@ NodeFS.prototype.read = function(filename) {
return Promise.nfcall(fs.readFile, filename);
};
+// Read stat infos about a file
+NodeFS.prototype.stat = function(filename) {
+ return Promise.nfcall(fs.stat, filename);
+};
+
// Write a file and returns a promise
NodeFS.prototype.write = function(filename, buffer) {
var folder = path.dirname(filename);