Skip to content

Instantly share code, notes, and snippets.

@kennyki
Created January 29, 2013 14:50
Show Gist options
  • Save kennyki/4664798 to your computer and use it in GitHub Desktop.
Save kennyki/4664798 to your computer and use it in GitHub Desktop.
docpad.js that throws “module” is undefined
/*
* Export our DocPad Configuration
*/
module.exports = {
// Change the port DocPad uses from the default 9778 to 8080
port: 8080,
/*
* Template Data
* =============
* These are variables that will be accessible via our templates
* To access one of these within our templates, refer to the FAQ: https://github.com/bevry/docpad/wiki/FAQ
*/
templateData: {
/*
* Specify some site properties
*/
site: {
// The production url of our website
url: "http://test.com",
// Here are some old site urls that you would like to redirect from
oldUrls: [],
// The default title of our website
title: "test",
// The website description (for SEO)
// When your website appears in search results in say Google, the text here will be shown underneath your website's title.
description: "test",
// The website keywords (for SEO) separated by commas
keywords: "test",
// The website author's name
author: "test",
// The website author's email
email: "[email protected]",
// Your company's name
copyright: "© test 2013"
},
/*
* Helper Functions
* ================
*/
// Get the prepared site/document title
// Often we would like to specify particular formatting to our page's title
// we can apply that formatting here
getPreparedTitle: function getPreparedTitle() {
return (this.document.title ? this.document.title + " | " : "") + this.site.title;
},
// Get the prepared site/document description
getPreparedDescription: function getPreparedDescription() {
return (this.document.description || this.site.description);
},
// Get the prepared site/document keywords
getPreparedKeywords: function getPreparedKeywords() {
// Merge the document keywords with the site keywords
return this.site.keywords.concat(this.document.keywords || []).join(", ");
}
},
/*
* Collections
* ================
* These are special collections that our website makes available to us
*/
collections: {
// For instance, this one will fetch in all documents that have pageOrder set within their meta data
pages: function pages(db) {
var pages = db.findAllLive({
pageOrder: {$exists: true}
},
[
{pageOrder: 1},
{title: 1}
]);
return pages;
},
// This one, will fetch in all documents that will be outputted to the posts directory
posts: function posts(db) {
var posts = db.findAllLive({
relativeOutDirPath: "posts"
},
[
{date: -1}
]);
return posts;
}
},
/*
* DocPad Events
* ================
* Here we can define handlers for events that DocPad fires
*/
events: {
// Used to add our own custom routes to the server before the docpad routes are added
serverExtend: function serverExtend(opts) {
var server = opts.server;
var docpad = this.docpad;
// As we are now running in an event,
// ensure we are using the latest copy of the docpad configuraiton
// and fetch our urls from it
var latestConfig = docpad.getConfig();
var oldUrls = (latestConfig.templateData.site.oldUrls || []);
var newUrl = latestConfig.templateData.site.url;
// Redirect any requests accessing one of our sites oldUrls to the new site url
server.use(function use(req, res, next) {
if (oldUrls.indexOf(req.headers.host) != -1) {
res.redirect(301, newUrl + req.url);
} else {
next();
}
});
}
}
};
@WolfgangKluge
Copy link

use docpad.cmd run instead of docpad run.
The latter will execute the file docpad.js with wsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment