Skip to content

Commit

Permalink
Lints code with Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmerfield committed Sep 20, 2019
1 parent ccf59ce commit 6323225
Show file tree
Hide file tree
Showing 382 changed files with 8,212 additions and 8,355 deletions.
4 changes: 2 additions & 2 deletions app/blog/error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
8 changes: 6 additions & 2 deletions app/blog/render/load/augment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down
6 changes: 5 additions & 1 deletion app/blog/render/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions app/blog/render/retrieve/absoluteURLs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
3 changes: 2 additions & 1 deletion app/blog/render/retrieve/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
12 changes: 6 additions & 6 deletions app/blog/render/retrieve/encodeXML.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/blog/render/retrieve/script_url.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function (req, callback) {
module.exports = function(req, callback) {
return callback(null, req.blog.scriptURL);
}
};
3 changes: 2 additions & 1 deletion app/blog/render/retrieve/tests/absoluteURLs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions app/blog/render/retrieve/tests/encodeXML.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/blog/tests/vhosts.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 15 additions & 3 deletions app/blog/vhosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions app/brochure/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
21 changes: 10 additions & 11 deletions app/brochure/routes/developers.js
Original file line number Diff line number Diff line change
@@ -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();
});

Expand All @@ -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;
1 change: 0 additions & 1 deletion app/brochure/routes/featured/candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 7 additions & 8 deletions app/brochure/routes/featured/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
};
2 changes: 1 addition & 1 deletion app/brochure/routes/log-in/checkPassword.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
1 change: 0 additions & 1 deletion app/brochure/routes/news.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ function loadDone(req, res, next) {
)
return;


// Ignores commits to todo file since there are so many of them
if (
message
Expand Down
2 changes: 1 addition & 1 deletion app/brochure/routes/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var folders = {
magazine: "magazine",
photos: "bjorn",
portfolio: "bjorn",
rosa: "bjorn"
rosa: "bjorn"
};

templates.use(function(req, res, next) {
Expand Down
2 changes: 1 addition & 1 deletion app/brochure/routes/tools/breadcrumbs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = function Breadcrumbs() {
var list = {items: []};
var list = { items: [] };

list.add = function(label, slug) {
var base = "/";
Expand Down
20 changes: 7 additions & 13 deletions app/brochure/routes/tools/dates.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -22,5 +16,5 @@ module.exports = function (req, res, next) {
};
};

next();
};
next();
};
6 changes: 3 additions & 3 deletions app/brochure/routes/tools/inline-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion app/brochure/routes/tools/minify-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
4 changes: 3 additions & 1 deletion app/brochure/routes/tools/tex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/brochure/routes/tools/typeset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down
Loading

0 comments on commit 6323225

Please sign in to comment.