Skip to content

Commit

Permalink
Don't crash on missing data
Browse files Browse the repository at this point in the history
  • Loading branch information
robogeek committed Jul 6, 2016
1 parent 7a3a6cc commit 1b452fc
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions index.js
Expand Up @@ -33,7 +33,7 @@ module.exports = class BasePlugin extends akasha.Plugin {
constructor() {
super("akashacms-base");
}

configure(config) {
this._config = config;
config.addPartialsDir(path.join(__dirname, 'partials'));
Expand Down Expand Up @@ -120,7 +120,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var metas = [];
$('ak-header-metatags').each((i, elem) => { metas.push(elem); });
Expand All @@ -145,7 +145,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var elements = [];
$('ak-header-linkreltags').each((i, elem) => { elements.push(elem); });
Expand Down Expand Up @@ -178,7 +178,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var elements = [];
$('ak-header-canonical-url').each((i, elem) => { elements.push(elem); });
Expand Down Expand Up @@ -209,7 +209,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var elements = [];
$('ak-siteverification').each((i, elem) => { elements.push(elem); });
Expand Down Expand Up @@ -238,15 +238,15 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var elements = [];
$('ak-google-analytics').each((i, elem) => { elements.push(elem); });
if (elements.length <= 0) return done();
log('ak-google-analytics');
async.eachSeries(elements,
(element, next) => {
if (typeof config.google.analyticsAccount !== "undefined" && typeof config.google.analyticsDomain !== "undefined") {
if (typeof metadata.config.google !== "undefined" && typeof metadata.config.google.analyticsAccount !== "undefined" && typeof metadata.config.google.analyticsDomain !== "undefined") {
akasha.partial(metadata.config, "ak_googleAnalytics.html.ejs", {
googleAnalyticsAccount: config.google.analyticsAccount,
googleAnalyticsDomain: config.google.analyticsDomain
Expand All @@ -269,7 +269,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
var elements = [];
$('ak-sitemapxml').each(function(i, elem) { elements.push(elem); });
Expand All @@ -291,7 +291,7 @@ module.exports.mahabhuta = [
} else done();
});
},

function($, metadata, dirty, done) {
if ($('html head').get(0)) {
var rssheadermeta = [];
Expand All @@ -315,7 +315,7 @@ module.exports.mahabhuta = [
});
} else done();
},

function($, metadata, dirty, done) {
var elements = [];
$('publication-date').each(function(i, elem) { elements.push(elem); });
Expand All @@ -339,7 +339,7 @@ module.exports.mahabhuta = [
else { done(); }
});
},

function($, metadata, dirty, done) {
if (metadata.config.authorship) {
var auname;
Expand Down Expand Up @@ -383,7 +383,7 @@ module.exports.mahabhuta = [
} else done();
} else done();
},

/**
* These next two tags / functions are a two-step process for extracting image
* references and listing them as meta og:image tags.
Expand Down Expand Up @@ -422,7 +422,7 @@ module.exports.mahabhuta = [
$(img).addClass('metaog-promote');
}
next2();

}, function(err) {
if (err) next(err);
else next();
Expand All @@ -432,7 +432,7 @@ module.exports.mahabhuta = [
else { done(); }
});
},

/** Handle phase 2 of promoting image href's as og:image meta tags. */
function($, metadata, dirty, done) {
if ($('html head').get(0)) {
Expand Down Expand Up @@ -478,7 +478,7 @@ module.exports.mahabhuta = [
} else done();
},
function($, metadata, dirty, done) {

var links = [];
$('html body a').each((i, elem) => { links.push(elem); });
if (links.length <= 0) return done();
Expand All @@ -487,22 +487,22 @@ module.exports.mahabhuta = [
(link, next) => {
setImmediate(function() {
var href = $(link).attr('href');

// The potential exists to manipulate links to local documents
// Such as what's done with the linkto tag above.
// Such as checking for valid links
// Also need to consider links to //hostname/path/to/object
// Potential for complete link checking service right here

if (href && href !== '#') {
var uHref = url.parse(href, true, true);

if (uHref.protocol || uHref.slashes) {
// It's a link to somewhere else
// look at domain in whitelist and blacklist

var donofollow = false;

if (metadata.config.nofollow && metadata.config.nofollow.blacklist) {
metadata.config.nofollow.blacklist.forEach(function(re) {
if (uHref.hostname.match(re)) {
Expand All @@ -517,17 +517,17 @@ module.exports.mahabhuta = [
}
});
}

if (donofollow && !$(link).attr('rel')) {
$(link).attr('rel', 'nofollow');
}

/* TODO
if (! metadata.config.builtin.suppress.extlink
&& $(link).find("img.ak-extlink-icon").length <= 0) {
$(link).append('<img class="ak-extlink-icon" src="/img/extlink.png"/>');
} */

next();
} else {
// This is where we would handle local links
Expand Down

0 comments on commit 1b452fc

Please sign in to comment.