Permalink
Browse files

updating titles/keywords

  • Loading branch information...
1 parent e2a7291 commit 54dce916a930fc39d20306e83ad99d86184c128d @selfcontained committed Apr 14, 2012
View
@@ -1,5 +1,5 @@
var path = require('path'),
- authors = require('../config/authors.json'),
+ authors = require('./blog.json').authors,
ARTICLE_CONFIG = 'article.json',
ARTICLE_CONTENT = 'article.md',
ARTICLES_PATH = path.normalize(__dirname+'/../articles'),
View
@@ -1,6 +1,7 @@
var Blog = function() {
var app,
+ config = require('./blog.json'),
handlers = [
require('./handlers/assets.js'),
require('./handlers/error.js'),
@@ -17,7 +18,8 @@ var Blog = function() {
* Create and setup http server for serving blog dynamically
*/
createApp : function(config) {
- var express = require('express');
+ var express = require('express'),
+ self = this;
app = express.createServer();
app.configure(function(){
@@ -31,7 +33,7 @@ var Blog = function() {
app.use(app.router);
});
handlers.forEach(function(handler) {
- handler.register && handler.register(app);
+ handler.register && handler.register(self);
});
return this;
},
@@ -50,7 +52,8 @@ var Blog = function() {
* Create static version of blog in specified directory
*/
generate : function(dir) {
- var fs = require('fs');
+ var fs = require('fs'),
+ self = this;
if(require('path').existsSync(dir)) {
require('wrench').rmdirSyncRecursive(dir);
@@ -62,7 +65,7 @@ var Blog = function() {
}else {
console.log('create directory: ', dir);
handlers.forEach(function(handler) {
- handler.generate(dir);
+ handler.generate(self, dir);
});
}
});
@@ -75,6 +78,14 @@ var Blog = function() {
app.listen(port);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
return this;
+ },
+
+ config : function() {
+ return config;
+ },
+
+ app : function() {
+ return app;
}
};
View
@@ -0,0 +1,16 @@
+{
+ "title" : "selfcontained",
+ "description" : "Blog on software developlment by Brad Harris",
+ "keywords" : [
+ "software",
+ "web development",
+ "brad harris"
+ ],
+ "authors" : {
+ "bradharris" : {
+ "name" : "Brad Harris",
+ "gravatar" : "bmharris@gmail.com",
+ "github" : "bmharris"
+ }
+ }
+}
View
@@ -1,26 +1,29 @@
var handler = require('./handler.js'),
articleAPI = require('../article.js');
-function getTemplateData() {
+function getTemplateData(blog) {
+ var config = blog.config();
return {
recent_articles : articleAPI.getRecent(),
- articles : articleAPI.getAll()
+ articles : articleAPI.getAll(),
+ title : 'archive - ' + config.title,
+ keywords : config.keywords
};
}
module.exports = {
- register : function(app) {
- app.get('/archive/', function(req, res) {
- res.render('archive', getTemplateData());
+ register : function(blog) {
+ blog.app().get('/archive/', function(req, res) {
+ res.render('archive', getTemplateData(blog));
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
handler.createHtmlFile(
require('path').join(dir, 'archive', 'index.html'),
'archive',
- getTemplateData()
+ getTemplateData(blog)
);
}
View
@@ -6,14 +6,16 @@ var path = require('path'),
function getTemplateData(article) {
return {
recent_articles : articleAPI.getRecent(),
- article : article
+ article : article,
+ title : article.title,
+ keywords : article.tags.join()
};
}
module.exports = {
- register : function(app) {
- app.get(/^\/(\d){4}\/(\d){2}\/(\d){2}\/(.+)\/$/, function(req, res) {
+ register : function(blog) {
+ blog.app().get(/^\/(\d){4}\/(\d){2}\/(\d){2}\/(.+)\/$/, function(req, res) {
var article = articleAPI.get(req.params[3]);
if(article && article.publish) {
res.render('article', getTemplateData(article));
@@ -26,7 +28,7 @@ module.exports = {
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
articleAPI.getAll().forEach(function(article) {
if(article.publish) {
handler.createHtmlFile(
View
@@ -26,8 +26,8 @@ function compileCSS(filename, cb) {
module.exports = {
- register : function(app) {
- app.get('/css/:filename.css', function(req, res) {
+ register : function(blog) {
+ blog.app().get('/css/:filename.css', function(req, res) {
var filename = req.param('filename')+'.less';
compileCSS(filename, function(css) {
@@ -37,7 +37,7 @@ module.exports = {
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
compileCSS('blog.less', function(css) {
var cssDir = path.join(dir, 'css'),
cssFile = path.join(cssDir, 'blog.css');
View
@@ -2,19 +2,22 @@ var path = require('path'),
handler = require('./handler.js'),
articleAPI = require('../article.js');
-function getTemplateData() {
+function getTemplateData(blog) {
+ var config = blog.config();
return {
- recent_articles : articleAPI.getRecent()
+ recent_articles : articleAPI.getRecent(),
+ title : config.title,
+ keywords : config.keywords
};
}
module.exports = {
- generate : function(dir) {
+ generate : function(blog, dir) {
handler.createHtmlFile(
path.join(dir, '404.html'),
'404',
- getTemplateData()
+ getTemplateData(blog)
);
}
View
@@ -2,26 +2,27 @@ var path = require('path'),
handler = require('./handler.js'),
articleAPI = require('../article.js');
-function getTemplateData() {
+function getTemplateData(blog) {
return {
- articles : articleAPI.getAll()
+ articles : articleAPI.getAll(),
+ title : blog.config().title
};
}
module.exports = {
- register : function(app) {
- app.get('/feed/rss.xml', function(req, res) {
+ register : function(blog) {
+ blog.app().get('/feed/rss.xml', function(req, res) {
res.contentType('application/xml');
- res.render('feed', getTemplateData());
+ res.render('feed', getTemplateData(blog));
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
handler.createHtmlFile(
path.join(dir, 'feed', 'rss.xml'),
'feed',
- getTemplateData()
+ getTemplateData(blog)
);
}
View
@@ -7,10 +7,10 @@ module.exports = {
createHtmlFile : function(dest, template, data) {
var templateFile = path.join(__dirname, '/../../theme/templates/', template+'.jade'),
templateString = fs.readFileSync(templateFile, 'utf8'),
- template = require('jade').compile(templateString, {
+ renderer = require('jade').compile(templateString, {
filename : templateFile
}),
- html = template(data),
+ html = renderer(data),
destDir = '/'+(dest.split('/').slice(1, -1).join('/'));
if(!path.existsSync(destDir)) {
@@ -20,4 +20,4 @@ module.exports = {
console.log('created file: ', dest);
}
-}
+};
View
@@ -2,26 +2,29 @@ var path = require('path'),
handler = require('./handler.js'),
articleAPI = require('../article.js');
-function getTemplateData() {
+function getTemplateData(blog) {
+ var config = blog.config();
return {
articles : articleAPI.getRecent(10),
- recent_articles : articleAPI.getRecent()
+ recent_articles : articleAPI.getRecent(),
+ title : config.title,
+ keywords : config.keywords
};
}
module.exports = {
- register : function(app) {
- app.get('/', function(req, res) {
- res.render('homepage', getTemplateData());
+ register : function(blog) {
+ blog.app().get('/', function(req, res) {
+ res.render('homepage', getTemplateData(blog));
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
handler.createHtmlFile(
path.join(dir, 'index.html'),
'homepage',
- getTemplateData()
+ getTemplateData(blog)
);
}
View
@@ -2,28 +2,31 @@ var path = require('path'),
handler = require('./handler.js'),
articleAPI = require('../article.js');
-function getTemplateData(tag) {
+function getTemplateData(blog, tag) {
+ var config = blog.config();
return {
articles : articleAPI.getByTag(tag),
recent_articles : articleAPI.getRecent(),
- tag : tag
+ tag : tag,
+ title : tag + ' - ' + config.title,
+ keywords : config.keywords
};
}
module.exports = {
- register : function(app) {
- app.get('/tag/:tag/', function(req, res) {
- res.render('tag', getTemplateData(req.param('tag')));
+ register : function(blog) {
+ blog.app().get('/tag/:tag/', function(req, res) {
+ res.render('tag', getTemplateData(blog, req.param('tag')));
});
},
- generate : function(dir) {
+ generate : function(blog, dir) {
Object.keys(articleAPI.tags()).forEach(function(tag) {
handler.createHtmlFile(
path.join(dir, 'tag', tag, 'index.html'),
'tag',
- getTemplateData(tag)
+ getTemplateData(blog, tag)
);
});
}
View
@@ -1,7 +0,0 @@
-{
- "bradharris" : {
- "name" : "Brad Harris",
- "gravatar" : "bmharris@gmail.com",
- "github" : "bmharris"
- }
-}
@@ -2,7 +2,7 @@
!{xml}
rss(version="2.0")
channel
- title selfcontained
+ title #{title}
link(href="http://selfcontained.us")
author
name Brad Harris
@@ -1,5 +1,8 @@
extends layout
+block title
+ #{title}
+
block sidebar
include sidebar
@@ -1,9 +1,8 @@
!!! 5
html(lang="en")
head
- title Brad Harris
- meta(name="description", content="Blog on software developlment by Brad Harris")
- meta(name="keywords", content="software, web development, brad harris")
+ title #{title}
+ meta(name="keywords", content=keywords)
meta(name="author", content="Brad Harris")
meta(name="robots", content="index,follow")
meta(name="viewport", content="width=device-width,initial-scale=1")

0 comments on commit 54dce91

Please sign in to comment.