Early work on background agent for search

This commit is contained in:
NGPixel
2016-09-04 01:12:42 -04:00
parent 576ba7fde2
commit 528fab6c87
9 changed files with 189 additions and 68 deletions

View File

@@ -27,8 +27,8 @@ module.exports = {
let self = this;
self._repoPath = appconfig.datadir.repo;
self._cachePath = path.join(appconfig.datadir.db, 'cache');
self._repoPath = path.resolve(ROOTPATH, appconfig.datadir.repo);
self._cachePath = path.resolve(ROOTPATH, appconfig.datadir.db, 'cache');
return self;
@@ -177,6 +177,32 @@ module.exports = {
},
/**
* Fetches a text version of a Markdown-formatted document
*
* @param {String} entryPath The entry path
* @return {String} Text-only version
*/
fetchTextVersion(entryPath) {
let self = this;
return self.fetchOriginal(entryPath, {
parseMarkdown: false,
parseMeta: true,
parseTree: false,
includeMarkdown: true,
includeParentInfo: false,
cache: false
}).then((pageData) => {
return {
meta: pageData.meta,
text: mark.removeMarkdown(pageData.markdown)
};
});
},
/**
* Parse raw url path and make it safe
*
@@ -341,6 +367,8 @@ module.exports = {
},
/**
* Generate a starter page content based on the entry path
*
@@ -356,35 +384,6 @@ module.exports = {
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);
}
};