Created
September 11, 2017 21:19
-
-
Save maikelthedev/2dcf1bac28e90b7238be19d093a38845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is what I use for SEO for each skill | |
app.get('/skills/:skilltitle', function (req, res, next) { | |
if (req.isSpider()) { | |
//if (true) { | |
const theURL = req.url; | |
//console.log(req.params.pagetitle); | |
const theTitle = req.params.skilltitle; | |
var results = 'http://www.maikel.uk:3000/images/logos/neverstop.jpg'; | |
const descBase = 'A Content Management System to empower self-directed learning.'; | |
db.skills.findOne({'title': theTitle}, | |
function (err, skills) { | |
if ((err) || skills === null) { | |
res.render('../seo.handlebars', { | |
address: 'https://www.maikel.uk' + theURL, | |
title: theTitle, | |
description: descBase, | |
imgINSECURE: 'http://www.maikel.uk:3000/images/logos/neverstop.jpg', | |
imgSECURE: 'https://www.maikel.uk/images/logos/neverstop.jpg', | |
}); | |
} else { | |
results = skills.logoURL; | |
console.log(results); | |
res.render('../seo.handlebars', { | |
address: 'https://www.maikel.uk' + theURL, | |
title: theTitle, | |
description: skills.descriptHTML.substring(0, 300).replace(/<(?:.|\n)*?>/gm, ' ').replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '').replace(/quot/g, ' ') | |
.replace(/39;/g, '\'').replace(/nbsp;/g, '\.').replace(/;/g, '"') + "...", | |
imgSECURE: skills.logoURL, | |
imgINSECURE: 'http://www.maikel.uk:3000/' + skills.logoURL.substring(22) | |
}); | |
} | |
}); | |
} else { | |
next(); | |
} | |
}); | |
// This is what I use for SEO for each page | |
app.get('/skills/:skilltitle/:pageTitle', function (req, res, next) { | |
if (req.isSpider()) { | |
//if (true) { | |
const theURL = req.url; | |
const theSkillTitle = req.params.skilltitle; | |
const thePageTitle = req.params.pageTitle; | |
var results = 'http://www.maikel.uk:3000/images/logos/neverstop.jpg'; | |
const descBase = 'A Content Management System to empower self-directed learning.'; | |
db2.pages.findOne({'title': thePageTitle}, | |
function (err, page) { | |
if ((err) || page === null) { | |
res.render('../seo.handlebars', { | |
address: 'https://www.maikel.uk' + theURL, | |
title: thePageTitle, | |
description: descBase, | |
imgINSECURE: 'http://www.maikel.uk:3000/images/logos/neverstop.jpg', | |
imgSECURE: 'https://www.maikel.uk/images/logos/neverstop.jpg', | |
}); | |
} else { | |
results = page; | |
res.render('../seo.handlebars', { | |
address: 'https://www.maikel.uk' + theURL, | |
title: thePageTitle, | |
description: page.content.substring(0, 300).replace(/<(?:.|\n)*?>/gm, ' ').replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '').replace(/quot/g, ' ') | |
.replace(/39;/g, '\'').replace(/nbsp;/g, '\.').replace(/;/g, '"') + "...", | |
//For now I'll use the standard pic, I'll change my mind if I decide to give a SEO image to each page. | |
imgINSECURE: 'http://www.maikel.uk:3000/images/logos/neverstop.jpg', | |
imgSECURE: 'https://www.maikel.uk/images/logos/neverstop.jpg', | |
}); | |
} | |
}); | |
} else { | |
next(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment