Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- "0.11"
- "0.10"
script:
- make check
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
init:
npm install
check: init
./node_modules/.bin/jshint package.json nodemon.json camel.js
./node_modules/.bin/jscs package.json nodemon.json camel.js
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

[n]: http://nodejs.org/

[![Build Status][travis-badge]][travis-link]

[travis-badge]: https://travis-ci.org/cliss/camel.svg?branch=master
[travis-link]: https://travis-ci.org/cliss/camel

# Design Goals

More specifically, the design goals were:
Expand Down
29 changes: 14 additions & 15 deletions camel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var cacheResetTimeInMillis = 1800000;
var renderedPosts = {};
var renderedRss = {};
var allPostsSortedGrouped = {};
var headerSource = undefined;
var headerSource = null;
var footerSource = null;
var postHeaderTemplate = null;
var siteMetadata = {};
Expand Down Expand Up @@ -171,7 +171,7 @@ function getLinesFromPost(file) {
// Gets the metadata & rendered HTML for this file
function generateHtmlAndMetadataForFile(file) {
var retVal = fetchFromCache(file);
if (retVal == undefined) {
if (retVal === undefined) {
var lines = getLinesFromPost(file);
var metadata = parseMetadata(lines['metadata']);
metadata['relativeLink'] = externalFilenameForFile(file);
Expand Down Expand Up @@ -217,7 +217,7 @@ function externalFilenameForFile(file) {

// Gets the external absolute link for this file
function externalFilenameForFile(file, request) {
var hostname = request != undefined ? request.headers.host : '';
var hostname = request !== undefined ? request.headers.host : '';

var retVal = hostname.length ? ('http://' + hostname) : '';
retVal += file.at(0) == '/' && hostname.length > 0 ? '' : '/';
Expand All @@ -243,7 +243,7 @@ function externalFilenameForFile(file, request) {
// +-- ...
// `-- (Article Object)
function allPostsSortedAndGrouped(completion) {
if (Object.size(allPostsSortedGrouped) != 0) {
if (Object.size(allPostsSortedGrouped) !== 0) {
completion(allPostsSortedGrouped);
} else {
qfs.listTree(postsRoot, function (name, stat) {
Expand Down Expand Up @@ -349,14 +349,14 @@ function loadAndSendMarkdownFile(file, response) {
response.send(400, {error: 'Markdown file not found.'});
}
});
} else if (fetchFromCache(file) != null) {
} else if (fetchFromCache(file) !== null) {
// Send the cached version.
console.log('Sending cached file: ' + file);
response.send(200, fetchFromCache(file)['body']);
return;
} else {
// Fetch the real deal.
console.log('Sending file: ' + file)
console.log('Sending file: ' + file);
fs.exists(file + '.md', function (exists) {
if (!exists) {
response.send(404, {error: 'A post with that address is not found.'});
Expand Down Expand Up @@ -385,10 +385,10 @@ function sendYearListing(request, response) {
var nextMonth = Date.create(thisMonth).addMonths(1).addDays(2);

//console.log(thisMonth.short() + ' <-- ' + thisDay.short() + ' --> ' + nextMonth.short() + '? ' + (thisDay.isBetween(thisMonth, nextMonth) ? 'YES' : 'NO'));
if (currentMonth == null || !thisDay.isBetween(thisMonth, nextMonth)) {
if (currentMonth === null || !thisDay.isBetween(thisMonth, nextMonth)) {
// If we've started a month list, end it, because we're on a new month now.
if (currentMonth >= 0) {
retVal += '</ul>'
retVal += '</ul>';
}

currentMonth = thisDay.getMonth();
Expand All @@ -413,7 +413,7 @@ function sendYearListing(request, response) {
// generator: function to generate the raw HTML. Only parameter is a function that takes a completion handler that takes the raw HTML as its parameter.
// bestRouteHandler() --> generator() to build HTML --> completion() to add to cache and send
function baseRouteHandler(file, sender, generator) {
if (fetchFromCache(file) == null) {
if (fetchFromCache(file) === null) {
generator(function (postData) {
addRenderedPostToCache(file, {body: postData});
sender({body: postData});
Expand All @@ -432,7 +432,7 @@ app.get('/', function (request, response) {
// Determine which page we're on, and make that the filename
// so we cache by paginated page.
var page = 1;
if (request.query.p != undefined) {
if (request.query.p !== undefined) {
page = Number(request.query.p);
if (isNaN(page)) {
response.redirect('/');
Expand Down Expand Up @@ -491,7 +491,7 @@ app.get('/', function (request, response) {

app.get('/rss', function (request, response) {
response.type('application/rss+xml');
if (renderedRss['date'] == undefined || new Date().getTime() - renderedRss['date'].getTime() > 3600000) {
if (renderedRss['date'] === undefined || new Date().getTime() - renderedRss['date'].getTime() > 3600000) {
var feed = new rss({
title: siteMetadata['SiteTitle'],
description: 'Posts to ' + siteMetadata['SiteTitle'],
Expand Down Expand Up @@ -551,7 +551,7 @@ app.get('/:year/:month', function (request, response) {
var metadata = generateHtmlAndMetadataForFile(file)['metadata'];
var date = Date.create(metadata['Date']);
var dayOfMonth = date.getDate();
if (postsByDay[dayOfMonth] == undefined) {
if (postsByDay[dayOfMonth] === undefined) {
postsByDay[dayOfMonth] = [];
}

Expand Down Expand Up @@ -609,10 +609,9 @@ app.get('/:year/:month/:day', function (request, response) {

var header = headerSource.replace(metadataMarker + 'Title' + metadataMarker, day.format('{Weekday}, {Month} {d}'));
response.send(header + html + footerSource);
})
});
});


// Get a blog post, such as /2014/3/17/birthday
app.get('/:year/:month/:day/:slug', function (request, response) {
var file = postsRoot + request.params.year + '/' + request.params.month + '/' + request.params.day + '/' + request.params.slug;
Expand Down Expand Up @@ -644,5 +643,5 @@ app.get('/:slug', function (request, response) {
init();
var port = Number(process.env.PORT || 5000);
server.listen(port, function () {
console.log('Express server started on port %s', server.address().port);
console.log('Express server started on port %s', server.address().port);
});
46 changes: 44 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"author": {
"name": "Casey Liss",
"url": "http://www.caseyliss.com/"
"url": "http://www.caseyliss.com/",
"email": "casey@caseyliss.com"
},
"contributors": [
{
Expand All @@ -26,7 +27,6 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Casey Liss <casey@caseyliss.com>",
"license": "MIT",
"dependencies": {
"express": "^4.1.0",
Expand All @@ -38,7 +38,49 @@
"handlebars": "^2.0.0",
"compression": "^1.0.2"
},
"devDependencies": {
"jshint": "^2.5.0",
"jscs": "^1.4.3"
},
"engines": {
"node": "0.10.x"
},
"jshintConfig": {
"sub": true
},
"jscsConfig": {
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowMultipleVarDecl": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": true,
"disallowDanglingUnderscores": true,
"disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true,
"disallowImplicitTypeConversion": ["numeric", "boolean", "binary", "string"],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"validateLineBreaks": "LF",
"disallowTrailingWhitespace": true,
"disallowTrailingComma": true,
"disallowKeywordsOnNewLine": ["else"],
"requireLineFeedAtFileEnd": true,
"disallowYodaConditions": true
}
}