Skip to content

Instantly share code, notes, and snippets.

@edefiez
Last active May 9, 2016 14:46
Show Gist options
  • Save edefiez/10774158 to your computer and use it in GitHub Desktop.
Save edefiez/10774158 to your computer and use it in GitHub Desktop.
docpad.js instead of docpad.coffee
var docpadConfig,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
docpadConfig = {
templateData: {
site: {
url: "http://website.com",
oldUrls: ['www.website.com', 'website.herokuapp.com'],
title: "Your Website",
description: "When your website appears in search results in say Google, the text here will be shown underneath your website's title.",
keywords: "place, your, website, keywoards, here, keep, them, related, to, the, content, of, your, website",
author: "Your Name",
email: "your@email.com",
styles: ["/styles/twitter-bootstrap.css", "/styles/style.css"],
scripts: ["//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js", "//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js", "/vendor/twitter-bootstrap/dist/js/bootstrap.min.js", "/scripts/script.js"]
},
getPreparedTitle: function() {
if (this.document.title) {
return "" + this.document.title + " | " + this.site.title;
} else {
return this.site.title;
}
},
getPreparedDescription: function() {
return this.document.description || this.site.description;
},
getPreparedKeywords: function() {
return this.site.keywords.concat(this.document.keywords || []).join(', ');
}
},
collections: {
pages: function(database) {
return database.findAllLive({
pageOrder: {
$exists: true
}
}, [
{
pageOrder: 1,
title: 1
}
]);
},
posts: function(database) {
return database.findAllLive({
tags: {
$has: 'post'
}
}, [
{
date: -1
}
]);
}
},
plugins: {
downloader: {
downloads: [
{
name: 'Twitter Bootstrap',
path: 'src/files/vendor/twitter-bootstrap',
url: 'https://codeload.github.com/twbs/bootstrap/tar.gz/master',
tarExtractClean: true
}
]
}
},
events: {
serverExtend: function(opts) {
var docpad, latestConfig, newUrl, oldUrls, server;
server = opts.server;
docpad = this.docpad;
latestConfig = docpad.getConfig();
oldUrls = latestConfig.templateData.site.oldUrls || [];
newUrl = latestConfig.templateData.site.url;
return server.use(function(req, res, next) {
var _ref;
if (_ref = req.headers.host, __indexOf.call(oldUrls, _ref) >= 0) {
return res.redirect(newUrl + req.url, 301);
} else {
return next();
}
});
}
}
};
module.exports = docpadConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment