Comparing version 0.9.7 to 0.9.8-1
178
lib/reed.js
@@ -85,3 +85,3 @@ var fs = require("fs"), | ||
function redisPageDelete(title, callback) { | ||
var key = toKey(title); | ||
var key = toPagesKey(title); | ||
@@ -137,2 +137,4 @@ client.del(key, function(err) { | ||
fs.readFile(filename, function(err, data) { | ||
if (err) return callback(err); | ||
if (typeof(data) === "undefined") { | ||
@@ -151,2 +153,3 @@ if (typeof callback !== "undefined") callback(err); | ||
redisInsert(filename, postDate, metadata, post, function() { | ||
metadata.lastModified = new Date(metadata.lastModified); | ||
if (watched[filename] !== true) { | ||
@@ -166,2 +169,4 @@ reed.emit("add", metadata, post); | ||
fs.readFile(filename, function(err, data) { | ||
if (err) return callback(err); | ||
if (typeof(data) === "undefined") { | ||
@@ -180,6 +185,3 @@ if (typeof callback !== "undefined") callback(err); | ||
redisPageInsert(filename, postDate, metadata, post, function() { | ||
if (watched[filename] !== true) { | ||
reed.emit("addPage", metadata, post); | ||
} | ||
metadata.lastModified = new Date(metadata.lastModified); | ||
watchPage(filename); | ||
@@ -239,5 +241,2 @@ | ||
} | ||
else { | ||
reed.emit("updatePage", metadata, htmlContent); | ||
} | ||
}); | ||
@@ -253,7 +252,4 @@ } | ||
} | ||
else { | ||
reed.emit("removePage", filename); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
@@ -344,3 +340,3 @@ } | ||
function toPagesKey(title) { | ||
var filename = toFilename(title); | ||
var filename = toPagesFilename(title); | ||
return "page:" + filename; | ||
@@ -381,2 +377,54 @@ } | ||
function openRedis(callback) { | ||
//already open? | ||
if (typeof client !== 'undefined') { | ||
process.nextTick(function() { | ||
callback(false); | ||
}); | ||
} | ||
//declare all props that we want for redis | ||
var redisConf = { | ||
host: '127.0.0.1', | ||
port: 6379, | ||
password: null | ||
}; | ||
if (cfg) { | ||
//only take the props we are interested in | ||
//this way the user can specify only | ||
//host or only port leaving the rest | ||
// as defaults | ||
for (prop in redisConf) { | ||
if (cfg[prop]) { | ||
redisConf[prop] = cfg[prop]; | ||
} | ||
} | ||
} | ||
client = redis.createClient(redisConf.port, redisConf.host); | ||
//authentication may cause redis to fail | ||
//this ensures we see the problem if it occurs | ||
client.on('error', function(errMsg) { | ||
reed.emit('error', errMsg); | ||
}); | ||
if (redisConf.password) { | ||
//if we are to auth we need to wait on callback before | ||
//starting to do work against redis | ||
client.auth(redisConf.password, function (err) { | ||
if (err) return reed.emit('error', err); | ||
callback(true); | ||
}); | ||
} | ||
else { | ||
//no auth, just start | ||
process.nextTick(function() { | ||
callback(true); | ||
}); | ||
} | ||
} | ||
reed.getMetadata = function(title, callback) { | ||
@@ -426,2 +474,6 @@ //convert to key/filename | ||
} | ||
if (typeof metadata.lastModified !== 'undefined') { | ||
metadata.lastModified = new Date(metadata.lastModified); | ||
} | ||
callback(null, metadata, hash.post); | ||
@@ -622,30 +674,3 @@ } | ||
//declare all props that we want for redis | ||
var redisConf = { | ||
host: '127.0.0.1', | ||
port: 6379, | ||
password: null | ||
}; | ||
if (cfg) { | ||
//only take the props we are interested in | ||
//this way the user can specify only | ||
//host or only port leaving the rest | ||
// as defaults | ||
for (prop in redisConf) { | ||
if (cfg[prop]) { | ||
redisConf[prop] = cfg[prop]; | ||
} | ||
} | ||
} | ||
client = redis.createClient(redisConf.port, redisConf.host); | ||
// authentication may cause redis to fail | ||
// this ensures we see the problem if it occurs | ||
client.on('error', function(errMsg) { | ||
reed.emit('error', errMsg); | ||
}); | ||
var doOpen = function() { | ||
openRedis(function() { | ||
fs.watchFile(dir, function(curr, prev) { | ||
@@ -660,22 +685,10 @@ findNewFiles(); | ||
}); | ||
}; | ||
if (redisConf.password) { | ||
//if we are to auth we need to wait on callback before | ||
//starting to do work against redis | ||
client.auth(redisConf.password, function (err) { | ||
if (err) return reed.emit('error', err); | ||
doOpen(); | ||
}); | ||
} | ||
else { | ||
//no auth, just start | ||
doOpen(); | ||
} | ||
}); | ||
} | ||
reed.close = function() { | ||
client.quit(); | ||
//only quit if pages is not in use. | ||
if (!pagesReady) { | ||
client.quit(); | ||
} | ||
@@ -696,3 +709,3 @@ for (file in watched) { | ||
reed.pages = {}; | ||
reed.pages.open = function(directory) { | ||
reed.pages.open = function(directory, callback) { | ||
if (pagesOpen === true || pagesReady === true) { | ||
@@ -709,5 +722,10 @@ throw new Error("reed already open on " + dir); | ||
} | ||
pagesDir = directory; | ||
reed.emit("pagesReady"); | ||
openRedis(function() { | ||
pagesDir = directory; | ||
reed.emit("pagesReady"); | ||
if (typeof callback == 'function') { | ||
callback(); | ||
} | ||
}); | ||
} | ||
@@ -734,2 +752,6 @@ | ||
} | ||
if (typeof metadata.lastModified !== 'undefined') { | ||
metadata.lastModified = new Date(metadata.lastModified); | ||
} | ||
callback(null, metadata, hash.post); | ||
@@ -745,4 +767,36 @@ } | ||
reed.pages.remove = function remove(title, callback) { | ||
if (!pagesReadyCheck(remove, arguments)) return; | ||
var key = toPagesKey(title); | ||
var filename = toPagesFilename(title); | ||
fs.unlink(filename, function(unlinkErr) { | ||
if (unlinkErr) return callback(unlinkErr); | ||
redisPageDelete(key, function(err) { | ||
if (err) return callback(err); | ||
callback(null); | ||
}); | ||
}); | ||
} | ||
reed.pages.close = function() { | ||
//only quit if blog part is not in use. | ||
if (!ready) { | ||
client.quit(); | ||
} | ||
for (file in watchedPages) { | ||
if (watchedPages[file] === true) { | ||
fs.unwatchFile(file); | ||
} | ||
} | ||
watchedPages = {}; | ||
pagesOpen = false; | ||
pagesReady = false; | ||
} | ||
//Export an event emitting object that also has the various control methods | ||
//on it. | ||
module.exports = reed; |
@@ -7,3 +7,3 @@ { | ||
"tags": [ "redis", "blog" ], | ||
"version": "0.9.7", | ||
"version": "0.9.8-1", | ||
"homepage": "http://www.agnos.is/", | ||
@@ -26,3 +26,5 @@ "repository": { | ||
}, | ||
"devDependencies": {} | ||
"devDependencies": { | ||
"vows": "" | ||
} | ||
} |
@@ -206,9 +206,7 @@ reed | ||
--------- | ||
*Note*: There is a known issue that prevents Pages from working if the blog | ||
portion of reed is not opened first. This will be fixed soon. | ||
Reed 0.9 introduces pages functionality. This operates similarly to the blog | ||
functionality. Each page is a markdown file in a specified directory, and | ||
all pages are automatically watched for updates. The main difference is that | ||
reed does not care about when a page was last updated. | ||
functionality. Each page is a markdown file in a specified directory. The main | ||
difference is that the pages API is not indexed like blog posts are. There | ||
are no events exposed by the pages API, and there is no way to get a list of | ||
all pages in the system. | ||
@@ -236,15 +234,13 @@ This functionality is useful for static pages on a website. A simple example, | ||
* `pages.open(dir)`: Opens the given path for reed pages. This directory should | ||
be separate from the blog directory. Calling open() more than once will cause | ||
it to throw an error. | ||
* `pages.get(title)`: Attempts to find the page with the given title. The | ||
callback receives `error`, `metadata`, and `htmlContent`, as in the regular | ||
`get` method. | ||
* `pages.open(dir, callback)`: Opens the given path for reed pages. This | ||
directory should be separate from the blog directory. Calling open() | ||
more than once will cause it to throw an error. The callback is called once | ||
the page system is running. | ||
* `pages.get(title, callback)`: Attempts to find the page with the given title. | ||
The callback receives `error`, `metadata`, and `htmlContent`, as in the | ||
regular `get` method. | ||
* `pages.remove(title, callback)`: Removes the specified page, deleting it from | ||
Redis and the filesystem. | ||
* `pages.close()`: Closes the pages portion of reed. | ||
The pages API exposes the following events: | ||
* `pagesReady`: Fired when the `open` call has completed. | ||
* `addPage`: Fired when a new page is added to Redis. | ||
* `updatePage`: Fired when a page is updated. | ||
Contributors | ||
@@ -251,0 +247,0 @@ ============ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
790
33276
1
254
2