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

docpad-plugin-cleanurls

Package Overview
Dependencies
Maintainers
1
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.3.0 to 2.4.0

5

History.md
## History
- v2.4.0 January 6, 2013
- Clean URLs for the static environment now operates more gracefully
- No longer modifies the out path and corresponding attributes
- Now work by outputting redirect file to the secondary url paths, and the result file to the primary url path
- v2.3.0 January 4, 2013

@@ -4,0 +9,0 @@ - Now supports static environments by changing the document's `outPath` to that of a directory with an `index.html` file inside.

109

out/cleanurls.plugin.js

@@ -20,39 +20,24 @@ // Generated by CoffeeScript 1.4.0

CleanUrlsPlugin.prototype.pathToUrl = function(path) {
var slashRegex;
slashRegex = /\\/g;
return path.replace(slashRegex, '/');
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 </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>";
}
};
CleanUrlsPlugin.prototype.cleanUrlsForDocument = function(document) {
var documentUrl, outDirPath, outFilename, outPath, pathUtil, relativeBaseUrl, relativeDirUrl, relativeOutDirPath, relativeOutPath, set;
var pathUtil, relativeBaseUrl, relativeDirUrl, url;
url = document.get('url');
pathUtil = require('path');
documentUrl = document.get('url');
if (__indexOf.call(this.docpad.getEnvironments(), 'static') >= 0 && document.get('outFilename') !== 'index.html' && document.get('outPath')) {
outFilename = 'index.html';
outPath = document.get('outPath').replace(/\.html$/, "/" + outFilename);
outDirPath = pathUtil.dirname(outPath);
relativeOutPath = document.get('relativeOutPath').replace(/\.html$/, "/" + outFilename);
relativeOutDirPath = pathUtil.dirname(relativeOutPath);
set = {
outFilename: outFilename,
outPath: outPath,
outDirPath: outDirPath,
relativeOutPath: relativeOutPath,
relativeOutDirPath: relativeOutDirPath
};
document.set(set);
}
if (/\.html$/i.test(documentUrl)) {
relativeBaseUrl = '/' + this.pathToUrl(document.get('relativeBase'));
if (/index\.html$/i.test(url)) {
relativeDirUrl = pathUtil.dirname(url);
document.setUrl(relativeDirUrl);
} else if (/\.html$/i.test(url)) {
relativeBaseUrl = url.replace(/\.html$/, '');
document.setUrl(relativeBaseUrl);
document.addUrl(relativeBaseUrl + '/');
}
if (/index\.html$/i.test(documentUrl)) {
relativeDirUrl = '/' + this.pathToUrl(document.get('relativeDirPath'));
document.setUrl(relativeDirUrl);
}
return document;
};
CleanUrlsPlugin.prototype.extendCollections = function(opts) {
CleanUrlsPlugin.prototype.renderBefore = function(opts) {
var database, docpad;

@@ -62,7 +47,71 @@ docpad = this.docpad;

docpad.log('debug', 'Applying clean urls');
database.on('add change', this.cleanUrlsForDocument);
database.forEach(this.cleanUrlsForDocument);
docpad.log('debug', 'Applied clean urls');
return true;
return this;
};
CleanUrlsPlugin.prototype.writeAfter = function(opts, next) {
var addWriteTask, balUtil, config, database, docpad, docpadConfig, getCleanOutPathFromUrl, pathUtil, tasks;
config = this.config;
docpad = this.docpad;
docpadConfig = docpad.getConfig();
database = docpad.getCollection('html');
balUtil = require('bal-util');
pathUtil = require('path');
getCleanOutPathFromUrl = function(url) {
url = url.replace(/\/+$/, '');
if (/index.html$/.test(url)) {
return pathUtil.join(docpadConfig.outPath, url);
} else {
return pathUtil.join(docpadConfig.outPath, url.replace(/\.html$/, '') + '/index.html');
}
};
if (__indexOf.call(docpad.getEnvironments(), 'static') >= 0) {
docpad.log('debug', 'Writing static clean url files');
tasks = new balUtil.Group(function(err) {
docpad.log('debug', 'Wrote static clean url files');
return next(err);
});
addWriteTask = function(outPath, outContent, encoding) {
return tasks.push(function(complete) {
return balUtil.writeFile(outPath, outContent, encoding, complete);
});
};
database.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) {
return;
}
encoding = document.get('encoding');
primaryUrl = document.get('url');
primaryUrlOutPath = getCleanOutPathFromUrl(primaryUrl);
primaryOutPath = document.get('outPath');
urls = document.get('urls');
redirectContent = config.getRedirectTemplate(document);
redirectOutPaths = [];
if (primaryUrlOutPath !== primaryOutPath) {
addWriteTask(primaryUrlOutPath, document.getOutContent(), encoding);
redirectOutPaths.push(primaryOutPath);
}
for (_i = 0, _len = urls.length; _i < _len; _i++) {
url = urls[_i];
redirectOutPath = getCleanOutPathFromUrl(url);
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));
}
return _results;
});
tasks.async();
} else {
next();
}
return this;
};
return CleanUrlsPlugin;

@@ -69,0 +118,0 @@

// Generated by CoffeeScript 1.4.0
require('docpad').require('testers').test({
pluginPath: __dirname + '/..'
testerName: 'cleanurls development environment',
pluginPath: __dirname + '/..',
testPath: __dirname + '/../test/development',
autoExit: 'safe'
}, {
env: 'development'
}).test({
testerName: 'cleanurls static environment',
pluginPath: __dirname + '/..',
testPath: __dirname + '/../test/static'
}, {
env: 'static'
});

@@ -25,10 +25,9 @@ // Generated by CoffeeScript 1.4.0

return this.suite('cleanurls', function(suite, test) {
var baseUrl, filePath, fileUrl, outExpectedPath;
var baseUrl, fileUrl, outExpectedPath;
baseUrl = "http://localhost:" + tester.docpad.config.port;
outExpectedPath = tester.config.outExpectedPath;
fileUrl = "" + baseUrl + "/welcome";
filePath = "" + outExpectedPath + "/welcome.html";
fileUrl = "" + baseUrl + "/welcome/";
return test('server should serve URLs without an extension', function(done) {
return request(fileUrl, function(err, response, actual) {
var actualStr;
var actualStr, expectedStr;
if (err) {

@@ -38,11 +37,5 @@ return done(err);

actualStr = actual.toString();
return fsUtil.readFile(filePath, function(err, expected) {
var expectedStr;
if (err) {
return done(err);
}
expectedStr = expected.toString();
expect(actualStr).to.equal(expectedStr);
return done();
});
expectedStr = 'Welcome';
expect(actualStr).to.equal(expectedStr);
return done();
});

@@ -49,0 +42,0 @@ });

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

@@ -30,3 +30,5 @@ "homepage": "http://docpad.org/plugin/cleanurls",

},
"dependencies": {},
"dependencies": {
"bal-util": "~1.15.3"
},
"devDependencies": {

@@ -33,0 +35,0 @@ "coffee-script": "1.4.x"

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