diff --git a/README.md b/README.md index a016b4f..e5ee410 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ [![Build Status](https://secure.travis-ci.org/guyht/Glog.png)](http://travis-ci.org/guyht/Glog) +### Upgrading to version 2x +As of version 2, Glog is using the [node-config](https://github.com/lorenwest/node-config) module to handle configuration. While this is a step forward for Glog, allowing you to easily fine tune configuration for your environments, it means that the name and location of the config file has changed. See the configuration section below. + The Glog Blog ============= @@ -79,7 +82,9 @@ The entire blog content is parsed and loaded into memory. Whenever a new articl # Configuration options -These options should be placed in glog_cofig.json and should be valid JSON +Glog has recently switched to using [node-config](https://github.com/lorenwest/node-config). This new library makes handling different configuration for different environments a breze. To get you up and running, the following instructions are all you need, but if you would like to setup different configurations for different environments, take a peek at the node-config documentation. + +These options should be placed in config/default.json (the default configuration file) and should be valid JSON blog_repository - The url of the blog repository (e.g. git@github.com:guyht/Guido.git) author - The default blog author (will be used if author is not specified in an individual post) diff --git a/glog_config.sample.json b/config/default.sample.json similarity index 100% rename from glog_config.sample.json rename to config/default.sample.json diff --git a/lib/glog.js b/lib/glog.js index 25a6c40..9358996 100644 --- a/lib/glog.js +++ b/lib/glog.js @@ -7,7 +7,8 @@ var path = require('path'), jade = require('jade'), exec = require('child_process').exec, rss = require('rss'), - async = require('async'); + async = require('async'), + config = require('config'); /* @@ -40,35 +41,29 @@ Glog.prototype.load_configs = function(cb) { fn = this, key; - fs.readFile(path.join('glog_config.json'), 'UTF-8', function(err, data) { - if(err) { - fn.handle_error('Could not load configuration file. This should be named glog_config.json. Err: ' + err); - } - - var configs = JSON.parse(data); + // Check mandatory configs + if(!config.port) { + fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on'); + process.exit(); + } - // Check mandatory configs - if(!configs.port) { - fn.handle_error('port is not defined in glog_config.json. This should be set to the port number you wish the blog to run on'); - process.exit(); - } + if(!config.blog_repository) { + fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content'); + process.exit(); + } - if(!configs.blog_repository) { - fn.handle_error('blog_repository is not defined in glog_config.json. This should point to the git repository of the blog content'); - process.exit(); - } + if(!config.author) { + fn.handle_error('author is not defined in glog_config.json. This should be the default blog author'); + process.exit(); + } - if(!configs.author) { - fn.handle_error('author is not defined in glog_config.json. This should be the default blog author'); - process.exit(); - } + for(key in config) { + options[key] = config[key]; + } - for(key in configs) { - options[key] = configs[key]; - } + console.log(JSON.stringify(options)); cb(options); - }); } diff --git a/package.json b/package.json index 866505b..7894716 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,18 @@ { - "name" : "Glog", - "version" : "1.3.0", - "author" : "Guy Halford-Thompson", - "repository" : "git://github.com/guyht/Glog", - "dependencies" : { - "express":"~2", - "marked" : ">= 0.1.4", - "jade" : ">= 0.19.0", - "mocha": ">= 0.8.2", - "rss": ">= 0.0.3", - "async" : ">= 0.1.22" - }, - "scripts": { - "test": "make test" - } + "name": "Glog", + "version": "2.0.0", + "author": "Guy Halford-Thompson", + "repository": "git://github.com/guyht/Glog", + "dependencies": { + "express": "~2", + "marked": ">= 0.1.4", + "jade": ">= 0.19.0", + "mocha": ">= 0.8.2", + "rss": ">= 0.0.3", + "async": ">= 0.1.22", + "config": "~0.4.17" + }, + "scripts": { + "test": "make test" + } }