|
@@ -6,7 +6,8 @@ var Promise = require('bluebird'),
|
|
_ = require('lodash'),
|
|
_ = require('lodash'),
|
|
farmhash = require('farmhash'),
|
|
farmhash = require('farmhash'),
|
|
BSONModule = require('bson'),
|
|
BSONModule = require('bson'),
|
|
- BSON = new BSONModule.BSONPure.BSON();
|
|
|
|
|
|
+ BSON = new BSONModule.BSONPure.BSON(),
|
|
|
|
+ moment = require('moment');
|
|
|
|
|
|
/**
|
|
/**
|
|
* Entries Model
|
|
* Entries Model
|
|
@@ -259,6 +260,17 @@ module.exports = {
|
|
return path.join(this._cachePath, farmhash.fingerprint32(entryPath) + '.bson');
|
|
return path.join(this._cachePath, farmhash.fingerprint32(entryPath) + '.bson');
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Gets the entry path from full path.
|
|
|
|
+ *
|
|
|
|
+ * @param {String} fullPath The full path
|
|
|
|
+ * @return {String} The entry path
|
|
|
|
+ */
|
|
|
|
+ getEntryPathFromFullPath(fullPath) {
|
|
|
|
+ let absRepoPath = path.resolve(ROOTPATH, this._repoPath);
|
|
|
|
+ return _.chain(fullPath).replace(absRepoPath, '').replace('.md', '').replace(new RegExp('\\\\', 'g'),'/').value();
|
|
|
|
+ },
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Update an existing document
|
|
* Update an existing document
|
|
*
|
|
*
|
|
@@ -344,6 +356,35 @@ module.exports = {
|
|
return _.replace(contents, new RegExp('{TITLE}', 'g'), formattedTitle);
|
|
return _.replace(contents, new RegExp('{TITLE}', 'g'), formattedTitle);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ purgeStaleCache() {
|
|
|
|
+
|
|
|
|
+ let self = this;
|
|
|
|
+
|
|
|
|
+ let cacheJobs = [];
|
|
|
|
+
|
|
|
|
+ fs.walk(self._repoPath)
|
|
|
|
+ .on('data', function (item) {
|
|
|
|
+ if(path.extname(item.path) === '.md') {
|
|
|
|
+
|
|
|
|
+ let entryPath = self.parsePath(self.getEntryPathFromFullPath(item.path));
|
|
|
|
+ let cachePath = self.getCachePath(entryPath);
|
|
|
|
+
|
|
|
|
+ cacheJobs.push(fs.statAsync(cachePath).then((st) => {
|
|
|
|
+ if(moment(st.mtime).isBefore(item.stats.mtime)) {
|
|
|
|
+ return fs.unlinkAsync(cachePath);
|
|
|
|
+ } else {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ }).catch((err) => {
|
|
|
|
+ return (err.code !== 'EEXIST') ? err : true;
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ return Promise.all(cacheJobs);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
};
|
|
};
|