Skip to content

Commit

Permalink
Skip ads on meta pages
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed May 2, 2018
1 parent 2e6ff00 commit cfedd77
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
24 changes: 23 additions & 1 deletion index.js
Expand Up @@ -281,6 +281,24 @@ Site.prototype.setupLocals = function () {
'73.151.205.54'
]

// Never show ads on urls that start with the following patterns
var ignoreUrls = [
'/about/',
'/advertise/',
'/contact/',
'/essay-review/',
'/login/',
'/open-source/',
'/photo-credits/',
'/plagiarism/',
'/privacy/',
'/pro/',
'/signup/',
'/stats/',
'/terms/',
'/testimonials/'
]

self.app.use(function (req, res, next) {
var agent = useragent.lookup(req.headers['user-agent'])
req.agent = agent.family.replace(/ /g, '-').toLowerCase()
Expand All @@ -292,7 +310,11 @@ Site.prototype.setupLocals = function () {

res.locals.req = req
res.locals.csrf = req.csrfToken()
res.locals.ads = Boolean(req.query.ads) || adBlock.indexOf(req.ip) === -1

var isIgnoreUrl = ignoreUrls.some(ignoreUrl => req.url.startsWith(ignoreUrl))
res.locals.ads = Boolean(req.query.ads) ||
(adBlock.indexOf(req.ip) === -1 && !isIgnoreUrl)

next()
})
}
Expand Down
3 changes: 2 additions & 1 deletion views/layouts/base.pug
Expand Up @@ -6,7 +6,8 @@ html(class=`studynotes ${layout} ${cls}`, lang='en')

link(rel='preconnect', href='https://cdn.apstudynotes.org')
link(rel='preconnect', href='https://use.typekit.net')
link(rel='preconnect', href='https://pagead2.googlesyndication.com')
if config.isProd && ads
link(rel='preconnect', href='https://pagead2.googlesyndication.com')

block preconnect

Expand Down

0 comments on commit cfedd77

Please sign in to comment.