Skip to content
Permalink
Browse files

Lints code with Prettier

  • Loading branch information...
davidmerfield committed Sep 20, 2019
1 parent ccf59ce commit 6323225e5a2519353601e5d67f1fe443970bcdf2
Showing 382 changed files with 8,212 additions and 8,355 deletions.
@@ -56,10 +56,10 @@ module.exports = function(server) {
// to attempt to restart Blot's node Blot. If you remove
// this, change monit.rc too. This middleware must come
// before the blog middleware, since there is no blog with
// the host 'localhost' and hence returns a 404, bad!
// the host 'localhost' and hence returns a 404, bad!
if (err.code === "ENOENT" && req.hostname === "localhost") {
return next();
}
}

// Blog does not exist...
if (err.code === "ENOENT") {
@@ -13,9 +13,13 @@ module.exports = function(req, res) {
var dateDisplay = blog.dateDisplay;

return function(entry) {

entry.formatDate = FormatDate(entry.dateStamp, req.blog.timeZone);
entry.absoluteURL = req.blog.locals.blogURL + entry.url.split('/').map(encodeURIComponent).join('/');
entry.absoluteURL =
req.blog.locals.blogURL +
entry.url
.split("/")
.map(encodeURIComponent)
.join("/");

var tags = [];
var tagged = {};
@@ -97,7 +97,11 @@ module.exports = function(req, res, _next) {

// Only cache JavaScript and CSS if the request is not to a preview
// subdomain and Blot's caching is turned on.
if (CACHE && !req.preview && (viewType === STYLE || viewType === JS)) {
if (
CACHE &&
!req.preview &&
(viewType === STYLE || viewType === JS)
) {
res.header(CACHE_CONTROL, cacheDuration);
}

@@ -48,7 +48,7 @@ function absoluteURLs(base, html) {
return html;
}

module.exports = function (req, callback) {
module.exports = function(req, callback) {
return callback(null, function() {
return function(text, render) {
var base = req.protocol + "://" + req.get("host");
@@ -63,4 +63,4 @@ module.exports = function (req, callback) {

// We also want to use this function in encodeXML
// so we export it without the callback wrapper.
module.exports.absoluteURLs = absoluteURLs;
module.exports.absoluteURLs = absoluteURLs;
@@ -11,7 +11,8 @@ module.exports = function(req, callback) {

if (!starts_with("/")) text = "/" + text;

if (extension) text = text + "?cache={{cacheID}}&extension=" + extension;
if (extension)
text = text + "?cache={{cacheID}}&extension=" + extension;

return render(text);
};
@@ -1,9 +1,9 @@
// This function accepts some HTML makes it suitable for
// This function accepts some HTML makes it suitable for
// inclusion in a CDATA-fenced description tag for an RSS
// feed item. It resolves relative URLs to make the result
// more portable. It should help produce valid feeds.

var absoluteURLs = require('./absoluteURLs').absoluteURLs;
var absoluteURLs = require("./absoluteURLs").absoluteURLs;

// Removes everything forbidden by XML 1.0 specifications,
// plus the unicode replacement character U+FFFD
@@ -12,19 +12,19 @@ function removeXMLInvalidChars(string) {
return string.replace(regex, "");
}

module.exports = function (req, callback) {
module.exports = function(req, callback) {
return callback(null, function() {
return function(text, render) {
var xml;

text = render(text);

try {
xml = absoluteURLs(req.protocol + "://" + req.get("host"), text);
xml = removeXMLInvalidChars(xml);
xml = removeXMLInvalidChars(xml);
} catch (e) {
console.log(e);
// do nothing if we can't
// do nothing if we can't
}

return xml || text;
@@ -1,3 +1,3 @@
module.exports = function (req, callback) {
module.exports = function(req, callback) {
return callback(null, req.blog.scriptURL);
}
};
@@ -42,7 +42,8 @@ describe("absoluteURLs", function() {
it("leaves fully qualified links and images as-is", function(done) {
var result;
var locals = {};
var html = '<a href="http://example.com/foo"><img src="http://example.com/bar.jpg"></a>';
var html =
'<a href="http://example.com/foo"><img src="http://example.com/bar.jpg"></a>';
var template = "{{#absoluteURLs}}" + html + "{{/absoluteURLs}}";

absoluteURLs(this.request, function(err, lambda) {
@@ -29,12 +29,12 @@ describe("encodeXML", function() {
it("removes invalid characters", function(done) {
var result;
var locals = {};
var html = '& foo &#xFF08;&#x4FBF;&#x5229;';
var html = "& foo &#xFF08;&#x4FBF;&#x5229;";
var template = "{{#encodeXML}}" + html + "{{/encodeXML}}";

encodeXML(this.request, function(err, lambda) {
result = mustache.render(template, { encodeXML: lambda });
expect(result).toEqual('&amp; foo &#xFF08;&#x4FBF;&#x5229;');
expect(result).toEqual("&amp; foo &#xFF08;&#x4FBF;&#x5229;");
done();
});
});
@@ -1,7 +1,7 @@
describe("blog server vhosts", function() {
var vhosts = require("../vhosts");
var config = require("config");

it("extracts a blot domain", function(done) {
var ctx = this;
var host = this.blog.handle + "." + config.host;
@@ -52,12 +52,24 @@ module.exports = function(req, res, next) {
// Redirect old handle
if (identifier.handle && blog.handle !== identifier.handle)
redirect =
req.protocol + "://" + blog.handle + "." + config.host + req.originalUrl;
req.protocol +
"://" +
blog.handle +
"." +
config.host +
req.originalUrl;

// Redirect Blot subdomain to custom domain we use
// 302 temporary since the domain might break in future
if (identifier.handle && blog.domain && blog.redirectSubdomain && !previewTemplate)
return res.status(302).redirect(req.protocol + "://" + blog.domain + req.originalUrl);
if (
identifier.handle &&
blog.domain &&
blog.redirectSubdomain &&
!previewTemplate
)
return res
.status(302)
.redirect(req.protocol + "://" + blog.domain + req.originalUrl);

// Redirect HTTP to HTTPS. Preview subdomains are not currently
// available over HTTPS but when they are, remove this.
@@ -23,10 +23,10 @@ if (config.cache === false) {
cache.flush(config.host, function(err) {
if (err) console.warn(err);
setTimeout(function() {
console.log('Warming cache...');
console.log("Warming cache...");
warmCache(config.protocol + config.host, function(err) {
if (err) console.warn(err);
console.log('Warmed cache');
console.log("Warmed cache");
});
}, 10 * 1000);
});
@@ -1,20 +1,20 @@
var Express = require("express");
var developers = new Express.Router();

developers.use(function(req, res, next){
res.locals.base = '/developers';
res.locals.layout = 'developers/layout';
developers.use(function(req, res, next) {
res.locals.base = "/developers";
res.locals.layout = "developers/layout";
res.locals.selected = {};
next();
});

developers.param('section', function(req, res, next){
res.locals.selected[req.params.section] = 'selected';
developers.param("section", function(req, res, next) {
res.locals.selected[req.params.section] = "selected";
next();
});

developers.param('subsection', function(req, res, next){
res.locals.selected[req.params.subsection] = 'selected';
developers.param("subsection", function(req, res, next) {
res.locals.selected[req.params.subsection] = "selected";
next();
});

@@ -27,9 +27,8 @@ developers.get("/:section", function(req, res) {
res.render("developers/" + req.params.section);
});

developers.get('/:section/:subsection', function(req, res){
res.render("developers/" + req.params.section + '/' + req.params.subsection);
developers.get("/:section/:subsection", function(req, res) {
res.render("developers/" + req.params.section + "/" + req.params.subsection);
});


module.exports = developers;
module.exports = developers;
@@ -36,7 +36,6 @@ var featured = require("./featured").map(function(site) {

function main(callback) {
Blog.getAllIDs(function(err, ids) {

async.map(
ids,
function(id, next) {
@@ -15,8 +15,8 @@ var cache = new Cache(config.cache_directory);
var featured = require("./featured.json");

// Check the list of featured sites a few seconds after the server starts
// We wait a somewhat arbritary 5 seconds since Blot often fails to serve
// the site immediately and then the filter thinks the domain has moved
// We wait a somewhat arbritary 5 seconds since Blot often fails to serve
// the site immediately and then the filter thinks the domain has moved
// elsewhere. I need to add zero-downtime deploy. Once I do, remove delay.
setTimeout(check, 1000 * 5);

@@ -48,20 +48,19 @@ function check() {
}

module.exports = function(req, res, next) {

// Strip the 'www' from the host property for aesthetics
res.locals.featured = featured.slice().map(function(site){
res.locals.featured = featured.slice().map(function(site) {
site.host = site.host.split("www.").join("");
site.template = site.template || {};
site.template.label = site.template.label || 'Default';
site.template.label = site.template.label || "Default";
return site;
});

res.locals.featured.sort(function(a,b){
return Math.round(Math.random()*2) - 1;
res.locals.featured.sort(function(a, b) {
return Math.round(Math.random() * 2) - 1;
});

res.locals.featured = res.locals.featured.slice(0,16);
res.locals.featured = res.locals.featured.slice(0, 16);

next();
};
@@ -1,5 +1,5 @@
var User = require("user");
var LogInError = require('./logInError');
var LogInError = require("./logInError");
var authenticate = require("./authenticate");

module.exports = function checkPassword(req, res, next) {
@@ -245,7 +245,6 @@ function loadDone(req, res, next) {
)
return;


// Ignores commits to todo file since there are so many of them
if (
message
@@ -11,7 +11,7 @@ var folders = {
magazine: "magazine",
photos: "bjorn",
portfolio: "bjorn",
rosa: "bjorn"
rosa: "bjorn"
};

templates.use(function(req, res, next) {
@@ -1,5 +1,5 @@
module.exports = function Breadcrumbs() {
var list = {items: []};
var list = { items: [] };

list.add = function(label, slug) {
var base = "/";
@@ -1,19 +1,13 @@
var moment = require('moment');

module.exports = function (req, res, next) {

res.locals.date = function () {

return function (text, render) {
var moment = require("moment");

module.exports = function(req, res, next) {
res.locals.date = function() {
return function(text, render) {
try {

text = text.trim();
text = moment.utc(Date.now()).format(text);

} catch (e) {

text = '';
text = "";
}

if (render) return render(text);
@@ -22,5 +16,5 @@ module.exports = function (req, res, next) {
};
};

next();
};
next();
};
@@ -4,7 +4,7 @@ var parseCSS = require("css");
var CleanCSS = require("clean-css");
var minimize = new CleanCSS();

module.exports = function (req, res, next) {
module.exports = function(req, res, next) {
var send = res.send;

res.send = function(string) {
@@ -62,8 +62,8 @@ module.exports = function (req, res, next) {

// I use some complex selectors to style these elements
// which do not match although they should when I run
// the document query below.
if (selector.indexOf('details') > - 1) return true;
// the document query below.
if (selector.indexOf("details") > -1) return true;

selector = selector
.split(":focus")
@@ -47,7 +47,7 @@ module.exports = function render_tex(req, res, next) {
try {
send.call(this, minify(html, options));
} catch (e) {
console.error('Error: Failed to minify HTML for', req.originalUrl);
console.error("Error: Failed to minify HTML for", req.originalUrl);
send.call(this, html);
}
};
@@ -18,7 +18,9 @@ module.exports = function render_tex(req, res, next) {

// Inject stylesheet to render TeX
if (hadTex) {
$("head").append('<link rel="stylesheet" type="text/css" href="/css/tex.css">');
$("head").append(
'<link rel="stylesheet" type="text/css" href="/css/tex.css">'
);
}

// This text does not contain LaTeX
@@ -6,7 +6,7 @@ module.exports = function typeset(req, res, next) {
res.send = function(string) {
var html = string instanceof Buffer ? string.toString() : string;

html = Typeset(html, {disable: ['hyphenate']});
html = Typeset(html, { disable: ["hyphenate"] });

send.call(this, html);
};

0 comments on commit 6323225

Please sign in to comment.
You can’t perform that action at this time.