Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

docpad-plugin-cleanurls

Package Overview
Dependencies
Maintainers
5
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

docpad-plugin-cleanurls - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

HISTORY.md

12

LICENSE.md

@@ -6,6 +6,12 @@

Copyright &copy; 2012+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
<br/>Copyright &copy; 2011 Benjamin Lupton <b@lupton.cc> (http://balupton.com)
Unless stated otherwise all works are:
## The MIT License
- Copyright &copy; 2012+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
- Copyright &copy; 2011 Benjamin Lupton <b@lupton.cc> (http://balupton.com)
and licensed under:
- The incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://opensource.org/licenses/mit-license.php)
## MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@@ -12,0 +18,0 @@

@@ -1,15 +0,15 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.3
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__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; };
var bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
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; };
module.exports = function(BasePlugin) {
var CleanUrlsPlugin;
return CleanUrlsPlugin = (function(_super) {
__extends(CleanUrlsPlugin, _super);
return CleanUrlsPlugin = (function(superClass) {
extend(CleanUrlsPlugin, superClass);
function CleanUrlsPlugin() {
this.cleanUrlsForDocument = __bind(this.cleanUrlsForDocument, this);
this.cleanUrlsForDocument = bind(this.cleanUrlsForDocument, this);
return CleanUrlsPlugin.__super__.constructor.apply(this, arguments);

@@ -21,5 +21,19 @@ }

CleanUrlsPlugin.prototype.config = {
getRedirectTemplate: function(document) {
return "<!DOCTYPE html>\n<html>\n <head>\n <title>" + (document.get('title') || 'Redirect') + "</title>\n <meta http-equiv=\"REFRESH\" content=\"0;url=" + (document.get('url')) + "\">\n <link rel=\"canonical\" href=\"" + (document.get('url')) + "\" />\n </head>\n <body>\n This page has moved. You will be automatically redirected to its new location. If you aren't forwarded to the new page, <a href=\"" + (document.get('url')) + "\">click here</a>.\n </body>\n</html>";
redirectTemplateEncoding: 'utf8',
getRedirectScript: function(advancedRedirects) {
var pattern, replacement, serializedRedirects;
serializedRedirects = '[' + ((function() {
var i, len, ref, results;
results = [];
for (i = 0, len = advancedRedirects.length; i < len; i++) {
ref = advancedRedirects[i], pattern = ref[0], replacement = ref[1];
results.push('[' + (typeof pattern === 'string' ? '"' + pattern + '"' : pattern.toString()) + ', "' + replacement + '"]');
}
return results;
})()).join(', ') + ']';
return "(function(){\n var advancedRedirects = " + serializedRedirects + ";\n var relativeURL = location.pathname + (location.search || '');\n var absoluteURL = location.href;\n advancedRedirects.forEach(function(value){\n var pattern = value[0], replacement = value[1], sourceURL, targetURL;\n if ( typeof pattern === 'string' ) {\n if ( pattern === relativeURL || pattern === absoluteURL ) {\n document.location.href = replacement;\n }\n }\n else {\n if ( pattern.test(sourceURL = relativeURL) || pattern.test(sourceURL = absoluteURL) ) {\n targetURL = sourceURL.replace(pattern, replacement);\n document.location.href = targetURL;\n }\n }\n })\n})()";
},
getRedirectTemplate: function(url, title) {
return "<!DOCTYPE html>\n<html>\n <head>\n <title>" + (title || 'Redirect') + "</title>\n <meta http-equiv=\"REFRESH\" content=\"0; url=" + url + "\">\n <link rel=\"canonical\" href=\"" + url + "\" />\n </head>\n <body>\n This page has moved. You will be automatically redirected to its new location. If you aren't forwarded to the new page, <a href=\"" + url + "\">click here</a>.\n <script>document.location.href = \"" + url + "\"</script>\n </body>\n</html>";
},
trailingSlashes: false,

@@ -32,3 +46,5 @@ collectionName: 'html',

}
}
},
simpleRedirects: null,
advancedRedirects: null
};

@@ -66,9 +82,29 @@

CleanUrlsPlugin.prototype.docpadReady = function(opts, next) {
var config, err, ref, sourceURL, targetURL;
config = this.getConfig();
if (config.simpleRedirects) {
ref = config.simpleRedirects;
for (sourceURL in ref) {
if (!hasProp.call(ref, sourceURL)) continue;
targetURL = ref[sourceURL];
if (sourceURL.indexOf('://') !== -1) {
err = new Error("Simple redirections via the Clean URLs plugin requires the source URLs to be relative URLs.\nYou must change [" + sourceURL + "] into a relative URL to continue.\nThis can be done via your DocPad configuration file under the cleanurls plugin section.");
return next(err);
}
}
}
next();
return this;
};
CleanUrlsPlugin.prototype.writeAfter = function(opts, next) {
var TaskGroup, addWriteTask, collection, config, docpad, docpadConfig, getCleanOutPathFromUrl, pathUtil, safefs, tasks;
config = this.config;
var TaskGroup, addWriteTask, collection, config, destinationFullUrl, destinationURL, docpad, docpadConfig, getCleanOutPathFromUrl, pathUtil, plugin, redirectContent, ref, ref1, safefs, siteURL, sourceURL, sourceURLPath, tasks;
plugin = this;
docpad = this.docpad;
config = this.getConfig();
docpadConfig = docpad.getConfig();
siteURL = ((ref = docpadConfig.site) != null ? ref.url : void 0) || '';
collection = docpad.getCollection(config.collectionName);
TaskGroup = require('taskgroup').TaskGroup;
TaskGroup = require('taskgroup');
safefs = require('safefs');

@@ -88,14 +124,28 @@ pathUtil = require('path');

concurrency: 0
}).once('complete', function(err) {
}).done(function(err) {
docpad.log('debug', 'Wrote static clean url files');
return next(err);
});
addWriteTask = function(outPath, outContent, encoding) {
addWriteTask = function(outPath, outContent) {
return tasks.addTask(function(complete) {
return safefs.writeFile(outPath, outContent, encoding, complete);
return safefs.writeFile(outPath, outContent, config.redirectTemplateEncoding, complete);
});
};
if (config.simpleRedirects) {
ref1 = config.simpleRedirects;
for (sourceURL in ref1) {
if (!hasProp.call(ref1, sourceURL)) continue;
destinationURL = ref1[sourceURL];
sourceURLPath = getCleanOutPathFromUrl(sourceURL);
destinationFullUrl = destinationURL;
if (destinationURL[0] = '/') {
destinationFullUrl = siteURL + destinationURL;
}
redirectContent = config.getRedirectTemplate.call(plugin, destinationFullUrl);
addWriteTask(sourceURLPath, redirectContent);
}
}
collection.forEach(function(document) {
var encoding, primaryOutPath, primaryUrl, primaryUrlOutPath, redirectContent, redirectOutPath, redirectOutPaths, url, urls, _i, _j, _len, _len1, _results;
if (document.get('write') === false || document.get('ignore') === true || document.get('render') === false) {
var encoding, i, j, len, len1, primaryOutPath, primaryUrl, primaryUrlOutPath, redirectOutPath, redirectOutPaths, results, url, urls;
if (document.get('write') === false || document.get('ignore') === true || document.get('render') === false || document.get('filename') === '404.html') {
return;

@@ -108,3 +158,4 @@ }

urls = document.get('urls');
redirectContent = config.getRedirectTemplate(document);
destinationFullUrl = siteURL + document.get('url');
redirectContent = config.getRedirectTemplate.call(plugin, destinationFullUrl, document.get('title'));
redirectOutPaths = [];

@@ -115,15 +166,15 @@ if (primaryUrlOutPath !== primaryOutPath) {

}
for (_i = 0, _len = urls.length; _i < _len; _i++) {
url = urls[_i];
for (i = 0, len = urls.length; i < len; i++) {
url = urls[i];
redirectOutPath = getCleanOutPathFromUrl(url);
if ((__indexOf.call(redirectOutPaths, redirectOutPath) >= 0) === false && redirectOutPath !== primaryUrlOutPath) {
if ((indexOf.call(redirectOutPaths, redirectOutPath) >= 0) === false && redirectOutPath !== primaryUrlOutPath) {
redirectOutPaths.push(redirectOutPath);
}
}
_results = [];
for (_j = 0, _len1 = redirectOutPaths.length; _j < _len1; _j++) {
redirectOutPath = redirectOutPaths[_j];
_results.push(addWriteTask(redirectOutPath, redirectContent, encoding));
results = [];
for (j = 0, len1 = redirectOutPaths.length; j < len1; j++) {
redirectOutPath = redirectOutPaths[j];
results.push(addWriteTask(redirectOutPath, redirectContent, encoding));
}
return _results;
return results;
});

@@ -137,2 +188,54 @@ tasks.run();

CleanUrlsPlugin.prototype.populateCollections = function(opts) {
var config, docpad;
docpad = this.docpad;
config = this.getConfig();
if (config["static"] === true && config.advancedRedirects) {
docpad.log('info', 'Adding clean URLs regex redirect script block');
docpad.getBlock('scripts').add(this.config.getRedirectScript.call(this, config.advancedRedirects), {
defer: false
});
}
return this;
};
CleanUrlsPlugin.prototype.serverExtend = function(opts) {
var codeRedirectPermanent;
codeRedirectPermanent = 301;
opts.server.use((function(_this) {
return function(req, res, next) {
var config, destinationURL, docpadConfig, i, len, pattern, ref, ref1, ref2, ref3, replacement, siteURL, sourceURL;
config = _this.getConfig();
if (config["static"] === false) {
docpadConfig = _this.docpad.getConfig();
siteURL = ((ref = docpadConfig.site) != null ? ref.url : void 0) || '';
if (destinationURL = (ref1 = config.simpleRedirects) != null ? ref1[req.url] : void 0) {
res.redirect(codeRedirectPermanent, destinationURL);
return _this;
}
if (config.advancedRedirects) {
ref2 = config.advancedRedirects;
for (i = 0, len = ref2.length; i < len; i++) {
ref3 = ref2[i], pattern = ref3[0], replacement = ref3[1];
if (typeof pattern === 'string') {
if (pattern === req.url || pattern === siteURL + req.url) {
res.redirect(codeRedirectPermanent, replacement);
return _this;
}
} else {
if (pattern.test(sourceURL = req.url) || pattern.test(sourceURL = siteURL + req.url)) {
destinationURL = sourceURL.replace(pattern, replacement);
res.redirect(codeRedirectPermanent, destinationURL);
return _this;
}
}
}
}
}
return next();
};
})(this));
return this;
};
return CleanUrlsPlugin;

@@ -139,0 +242,0 @@

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.3
(function() {

@@ -6,12 +6,11 @@ require('docpad').require('testers').test({

pluginPath: __dirname + '/..',
testPath: __dirname + '/../test/development',
autoExit: 'safe'
removeWhitespace: true
}, {
env: 'development'
}).test({
testerName: 'cleanurls development environment',
testerName: 'cleanurls development environment with trailing slashes',
pluginPath: __dirname + '/..',
testPath: __dirname + '/../test/development',
autoExit: 'safe'
removeWhitespace: true
}, {
env: 'development',
plugins: {

@@ -25,3 +24,4 @@ cleanurls: {

pluginPath: __dirname + '/..',
testPath: __dirname + '/../test/static'
outExpectedPath: __dirname + '/../test/out-expected-static',
removeWhitespace: true
}, {

@@ -28,0 +28,0 @@ env: 'static'

@@ -1,12 +0,12 @@

// Generated by CoffeeScript 1.7.1
// Generated by CoffeeScript 1.9.3
(function() {
var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty;
module.exports = function(testers) {
var MyTester, expect, request;
expect = require('chai').expect;
var MyTester, assertDeepEqual, assertEqual, ref, request;
ref = require('assert-helpers'), assertEqual = ref.assertEqual, assertDeepEqual = ref.assertDeepEqual;
request = require('request');
return MyTester = (function(_super) {
__extends(MyTester, _super);
return MyTester = (function(superClass) {
extend(MyTester, superClass);

@@ -24,30 +24,83 @@ function MyTester() {

return this.suite('cleanurls', function(suite, test) {
var baseUrl, fileUrl, outExpectedPath;
baseUrl = "http://localhost:" + tester.docpad.config.port;
var outExpectedPath, plugin, pluginConfig, siteURL;
siteURL = "http://localhost:" + tester.docpad.config.port;
outExpectedPath = tester.config.outExpectedPath;
fileUrl = "" + baseUrl + "/welcome/";
test('server should serve URLs without an extension', function(done) {
return request(fileUrl, function(err, response, actual) {
var actualStr, expectedStr;
if (err) {
return done(err);
plugin = tester.docpad.getPlugin('cleanurls');
pluginConfig = plugin.getConfig();
suite('cleanurls for documents suite', function(suite, test) {
test('server should serve URLs without an extension', function(done) {
var fullURL;
fullURL = siteURL + '/welcome/';
return request(fullURL, function(err, response, actual) {
var actualStr, expectedStr;
if (err) {
return done(err);
}
actualStr = actual.toString();
expectedStr = 'Welcome Page!';
assertEqual(actualStr, expectedStr, 'result from welcome URL contains expected content');
return done();
});
});
return test('documents should have urls without extensions', function(done) {
var actualUrls, expectedUrls;
actualUrls = tester.docpad.getCollection('documents').map(function(doc) {
return doc.get('url');
});
if (pluginConfig.trailingSlashes) {
expectedUrls = ['/', '/404/', '/hi', '/welcome/'];
} else {
expectedUrls = ['/', '/404', '/hi', '/welcome'];
}
actualStr = actual.toString();
expectedStr = 'Welcome';
expect(actualStr).to.equal(expectedStr);
assertDeepEqual(actualUrls.sort(), expectedUrls, 'URLs are as expected');
return done();
});
});
return test('documents should have urls without extensions', function(done) {
var actualUrls, expectedUrls;
actualUrls = tester.docpad.getCollection('documents').map(function(doc) {
return doc.get('url');
});
if (tester.docpad.getPlugin('cleanurls').getConfig().trailingSlashes) {
expectedUrls = ['/', '/hi', '/welcome/'];
} else {
expectedUrls = ['/', '/hi', '/welcome'];
return suite('redirect configuration suite', function(suite, test) {
if (tester.docpadConfig.environment === 'development') {
test('test redirect middleware', function(done) {
var fullURL;
fullURL = siteURL + '/open';
return request(fullURL, function(err, response, actual) {
var actualStr, expectedStr;
if (err) {
return done(err);
}
actualStr = actual.toString();
expectedStr = pluginConfig.getRedirectTemplate('/sesame');
assertEqual(actualStr, expectedStr, 'result from a simple redirect URL contains the expected content');
return done();
});
});
test('test advanced redirect middleware', function(done) {
var fullURL;
fullURL = siteURL + '/gh/website';
return request(fullURL, function(err, response, actual) {
var actualStr, expectedStr;
if (err) {
return done(err);
}
actualStr = actual.toString();
expectedStr = pluginConfig.getRedirectTemplate('https://github.com/bevry/website');
assertEqual(actualStr, expectedStr, 'result from an advanced redirect URL contains the expected content');
return done();
});
});
}
expect(actualUrls.sort()).to.deep.equal(expectedUrls);
return done();
if (tester.docpadConfig.environment === 'static') {
return test('test redirect file', function(done) {
var fullURL;
fullURL = siteURL + '/open' + '/index.html';
return request(fullURL, function(err, response, actual) {
var actualStr, expectedStr;
if (err) {
return done(err);
}
actualStr = actual.toString();
expectedStr = pluginConfig.getRedirectTemplate('/sesame');
assertEqual(actualStr, expectedStr, 'result from a simple redirect URL contains the expected content');
return done();
});
});
}
});

@@ -54,0 +107,0 @@ });

{
"name": "docpad-plugin-cleanurls",
"version": "2.7.0",
"version": "2.8.0",
"description": "Adds support for clean urls to DocPad",

@@ -12,5 +12,6 @@ "homepage": "http://docpad.org/plugin/cleanurls",

"npm": true,
"npmdownloads": true,
"david": true,
"daviddev": true,
"gittip": "docpad",
"gratipay": "docpad",
"flattr": "344188/balupton-on-Flattr",

@@ -34,5 +35,9 @@ "paypal": "QB8GQPZAH84N6",

"hurrymaplelad (https://github.com/hurrymaplelad)",
"iSpyCreativity (https://github.com/iSpyCreativity)",
"misterdai (https://github.com/misterdai)",
"RobLoach (https://github.com/RobLoach)",
"stongo (https://github.com/stongo)",
"StormPooper (https://github.com/StormPooper)",
"StudioLE (https://github.com/StudioLE)",
"vsopvsop (https://github.com/vsopvsop)",
"zenorocha (https://github.com/zenorocha)"

@@ -54,11 +59,12 @@ ],

"dependencies": {
"safefs": "~3.1.0",
"taskgroup": "~3.3.6"
"safefs": "^3.1.0",
"taskgroup": "^4.3.0"
},
"devDependencies": {
"assert-helpers": "^1.0.2",
"chai": "~1.9.0",
"coffee-script": "^1.9.1",
"docpad": ">=6.3 <7",
"coffee-script": "~1.7.1",
"chai": "~1.9.0",
"request": "~2.33.0",
"projectz": "~0.3.10"
"projectz": "^0.5.0",
"request": "^2.60.0"
},

@@ -68,3 +74,6 @@ "main": "./out/cleanurls.plugin.js",

"test": "node ./out/cleanurls.test.js"
},
"cakeConfiguration": {
"COFFEE_SRC_PATH": "src"
}
}
}

@@ -5,11 +5,12 @@ # Clean URLs Plugin for [DocPad](https://docpad.org)

[![Build Status](http://img.shields.io/travis-ci/docpad/docpad-plugin-cleanurls.png?branch=master)](http://travis-ci.org/docpad/docpad-plugin-cleanurls "Check this project's build status on TravisCI")
[![NPM version](http://badge.fury.io/js/docpad-plugin-cleanurls.png)](https://npmjs.org/package/docpad-plugin-cleanurls "View this project on NPM")
[![Dependency Status](https://david-dm.org/docpad/docpad-plugin-cleanurls.png?theme=shields.io)](https://david-dm.org/docpad/docpad-plugin-cleanurls)
[![Development Dependency Status](https://david-dm.org/docpad/docpad-plugin-cleanurls/dev-status.png?theme=shields.io)](https://david-dm.org/docpad/docpad-plugin-cleanurls#info=devDependencies)<br/>
[![Gittip donate button](http://img.shields.io/gittip/docpad.png)](https://www.gittip.com/docpad/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")
[![Wishlist browse button](http://img.shields.io/wishlist/browse.png?color=yellow)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us")
[![Build Status](https://img.shields.io/travis/docpad/docpad-plugin-cleanurls/master.svg)](http://travis-ci.org/docpad/docpad-plugin-cleanurls "Check this project's build status on TravisCI")
[![NPM version](https://img.shields.io/npm/v/docpad-plugin-cleanurls.svg)](https://npmjs.org/package/docpad-plugin-cleanurls "View this project on NPM")
[![NPM downloads](https://img.shields.io/npm/dm/docpad-plugin-cleanurls.svg)](https://npmjs.org/package/docpad-plugin-cleanurls "View this project on NPM")
[![Dependency Status](https://img.shields.io/david/docpad/docpad-plugin-cleanurls.svg)](https://david-dm.org/docpad/docpad-plugin-cleanurls)
[![Dev Dependency Status](https://img.shields.io/david/dev/docpad/docpad-plugin-cleanurls.svg)](https://david-dm.org/docpad/docpad-plugin-cleanurls#info=devDependencies)<br/>
[![Gratipay donate button](https://img.shields.io/gratipay/docpad.svg)](https://www.gratipay.com/docpad/ "Donate weekly to this project using Gratipay")
[![Flattr donate button](https://img.shields.io/badge/flattr-donate-yellow.svg)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")
[![Wishlist browse button](https://img.shields.io/badge/wishlist-donate-yellow.svg)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us")

@@ -36,5 +37,5 @@ <!-- /BADGES -->

For the `static` environment (i.e. when running docpad with the `--env static` flag, e.g. running `docpad generate --env static`) we will set the `static` plugin configuration option to `true`. This will in addition to performing redirections via the built-in dynamic server within DocPad for speed, we will also write special static redirection HTML files to the output directory, that will redirect the user to the new clean location (e.g. the document `pages/welcome.html` will not we outputted to `pages/welcome/index.html`, with `pages/welcome.html` now being a special HTML redirect document to the clean location).
For the `static` environment (i.e. when running DocPad with the `--env static` flag, e.g. running `docpad generate --env static`) we will set the `static` plugin configuration option to `true`. This will in addition to performing redirections via the built-in dynamic server within DocPad for speed, we will also write special static redirection HTML files to the output directory, that will redirect the user to the new clean location (e.g. the document `pages/welcome.html` will now be outputted to `pages/welcome/index.html`, with `pages/welcome.html` now being a special HTML redirect document to the clean location).
If you would like to always use the static mode, you can set the `static` plugin configuration option to true by doing:
If you would like to always use the static mode, you can set the `static` plugin configuration option to true with:

@@ -47,3 +48,3 @@ ``` coffee

If you would like to disable the static mode for the static environment, you can do so by doing:
If you would like to disable the static mode for the static environment, you can do so with:

@@ -58,3 +59,14 @@ ``` coffee

If you would like to disable clean urls completely (not just the static mode) in the static environment, you can do so with:
``` coffee
environments:
static:
plugins:
cleanurls:
enabled: false
```
### `trailingSlashes`

@@ -65,5 +77,5 @@ Enable this plugin configuration option to generate `document.url`s like `'/beep/'` instead of `/beep`. Defaults to `false`.

### `collectionName`
You can use this plugin configuration option (defaults to `html`) to tell the cleanurls plugin to use your own custom collection for which documents to apply cleanurls to.
You can use this plugin configuration option (defaults to `html`) to tell the cleanurls plugin to use your own custom collection for which documents to apply clean URLs to.
For insstance, if you are wanting to remove all cleanurls for all documents that have `cleanurls: false` in the meta data, then you could do the following in your docpad configuration file:
For instance, if you are wanting to remove all clean URLs for all documents that have `cleanurls: false` in the meta data, then you could do the following in your DocPad configuration file:

@@ -83,2 +95,83 @@ ``` coffee

### `getRedirectTemplate`
You can customise the HTML template that is used for the redirect pages by specifying the `getRedirectTemplate` option which is a function that accepts `url` argument and an option `title` argument and returns a string.
### `simpleRedirects`
Simple redirects work via routes in dynamic environments, and on static environments work via generating redirect HTML pages at the location of the source relative URL. They can be defined like so:
``` coffee
plguins:
cleanurls:
simpleRedirects:
'/relative-url': '/somewhere-else'
'/other-relative-url': 'http://somehere.else'
```
### `advancedRedirects`
Advanced redirects work via routes in dynamic environments, and on static environments work via a client-side javascript injection into the Script Block on your 404 Page document. They can be defined like so:
``` coffee
plguins:
cleanurls:
advancedRedirects: [
# Regular expressions redirects are possible too
[/^\/github\/?(.*)$/, 'https://github.com/docpad/$1']
[/^\/plugin\/(.+)$/, 'https://github.com/docpad/docpad-plugin-$1']
# Absolute URL redirects are even possible
['http://production.com/favourite-website', 'http://wikipedia.org']
['http://localhost:9778/favourite-website', 'http://facebook.com']
]
```
To ensure they work, you must make sure that your 404 Page document calls `@getBlock('scripts').toHTML()` to output the Script Block, which we inject the client-side javascript into. Here is an example of such a document using eco and location at `src/documents/404.html.eco`:
``` html
<!DOCTYPE html>
<html>
<head>
<!-- Standard Meta -->
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Site Properties -->
<title>404 Page Not Found</title>
<!-- DocPad Meta -->
<%- @getBlock('meta').toHTML() %>
<!-- DocPad Styles -->
<%- @getBlock('styles').add('/vendor/404.css').toHTML() %>
</head>
<body>
<!-- 404 Page Content -->
<div class="container">
<h1>Not Found 😲</h1>
<p>Sorry, but the page you were trying to view does not exist.</p>
<p>It looks like this was the result of either:</p>
<ul>
<li>a mistyped address</li>
<li>an out-of-date link</li>
</ul>
<script>
var GOOG_FIXURL_LANG = (navigator.language || '').slice(0,2),GOOG_FIXURL_SITE = location.host;
</script>
<script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
</div>
<!-- DocPad Scripts -->
<%- @getBlock('scripts').toHTML() %>
</body>
</html>
```
You can modify the client-side javascript by providing the option getRedirectScript` which is a function that accepts the advancedRedirects value as the first and only argument and returns a string which is the script to be injected.
<!-- HISTORY/ -->

@@ -115,7 +208,7 @@

[![Gittip donate button](http://img.shields.io/gittip/docpad.png)](https://www.gittip.com/docpad/ "Donate weekly to this project using Gittip")
[![Flattr donate button](http://img.shields.io/flattr/donate.png?color=yellow)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](http://img.shields.io/paypal/donate.png?color=yellow)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](http://img.shields.io/bitcoin/donate.png?color=yellow)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")
[![Wishlist browse button](http://img.shields.io/wishlist/browse.png?color=yellow)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us")
[![Gratipay donate button](https://img.shields.io/gratipay/docpad.svg)](https://www.gratipay.com/docpad/ "Donate weekly to this project using Gratipay")
[![Flattr donate button](https://img.shields.io/badge/flattr-donate-yellow.svg)](http://flattr.com/thing/344188/balupton-on-Flattr "Donate monthly to this project using Flattr")
[![PayPayl donate button](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QB8GQPZAH84N6 "Donate once-off to this project using Paypal")
[![BitCoin donate button](https://img.shields.io/badge/bitcoin-donate-yellow.svg)](https://coinbase.com/checkouts/9ef59f5479eec1d97d63382c9ebcb93a "Donate once-off to this project using BitCoin")
[![Wishlist browse button](https://img.shields.io/badge/wishlist-donate-yellow.svg)](http://amzn.com/w/2F8TXKSNAFG4V "Buy an item on our wishlist for us")

@@ -128,5 +221,9 @@ ### Contributors

- [hurrymaplelad](https://github.com/hurrymaplelad) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=hurrymaplelad)
- [iSpyCreativity](https://github.com/iSpyCreativity) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=iSpyCreativity)
- [misterdai](https://github.com/misterdai) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=misterdai)
- [RobLoach](https://github.com/RobLoach) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=RobLoach)
- [stongo](https://github.com/stongo) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=stongo)
- [StormPooper](https://github.com/StormPooper) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=StormPooper)
- [StudioLE](https://github.com/StudioLE) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=StudioLE)
- [vsopvsop](https://github.com/vsopvsop) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=vsopvsop)
- [zenorocha](https://github.com/zenorocha) — [view contributions](https://github.com/docpad/docpad-plugin-cleanurls/commits?author=zenorocha)

@@ -143,9 +240,13 @@

Licensed under the incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT license](http://creativecommons.org/licenses/MIT/)
Unless stated otherwise all works are:
Copyright &copy; 2012+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
<br/>Copyright &copy; 2011 Benjamin Lupton <b@lupton.cc> (http://balupton.com)
- Copyright &copy; 2012+ Bevry Pty Ltd <us@bevry.me> (http://bevry.me)
- Copyright &copy; 2011 Benjamin Lupton <b@lupton.cc> (http://balupton.com)
and licensed under:
- The incredibly [permissive](http://en.wikipedia.org/wiki/Permissive_free_software_licence) [MIT License](http://opensource.org/licenses/mit-license.php)
<!-- /LICENSE -->

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc