Skip to content

Commit

Permalink
New carbon ad code (#254)
Browse files Browse the repository at this point in the history
* new carbon ad code

* final fixes
  • Loading branch information
Peter Bengtsson committed May 15, 2018
1 parent 0b0cd64 commit 8654b93
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
2 changes: 2 additions & 0 deletions download-all-plogs.py
Expand Up @@ -8,6 +8,8 @@


def get_urls(base_url):
if base_url.endswith('/'):
base_url = base_url[:-1]
doc = PyQuery(base_url + '/plog/')
doc.make_links_absolute(base_url=base_url)
urls = []
Expand Down
110 changes: 110 additions & 0 deletions peterbecom/plog/jinja2/plog/post.html
Expand Up @@ -120,6 +120,71 @@
}
}
</style>

{# These are for the new BuySellAds Carbon campaign #}
<style>
.bsa-cpc #_default_ {
position: relative;
margin-bottom: 20px;
padding: 4px 14px 6px;
border: solid 1px #5a85c9;
background-color: #fafafa;
font-size: 14px;
line-height: 1.5;
}

.bsa-cpc .default-ad {
display: none;
}

.bsa-cpc ._default_ {
display: inline;
overflow: hidden;
line-height: 1;
}

.bsa-cpc ._default_ > * {
vertical-align: middle;
}

.bsa-cpc a {
text-decoration: none;
}

.bsa-cpc .default-image {
display: none;
}

.bsa-cpc .default-title:after {
content: " — ";
}

.bsa-cpc .default-title,
.bsa-cpc .default-description {
display: inline;
}

.bsa-cpc .default-title {
position: relative;
margin-left: 8px;
}

.bsa-cpc .default-title:before {
position: relative;
top: -1px;
left: -8px;
padding: 2px 5px;
border: solid 1px currentColor;
border-radius: 3px;
color: currentColor;
content: "Sponsor";
text-transform: uppercase;
font-weight: 600;
font-size: 10px;
font-family: Verdana, sans-serif;
line-height: 1;
}
</style>
{% endif %}

{% if request.path == '/plog/blogitem-040601-1' %}
Expand Down Expand Up @@ -156,6 +221,12 @@
<h4><a href="{{ post.url }}">{{ post.url }}</a></h4>
{% endif %}

{#
{% if request.path != '/plog/blogitem-040601-1' %}
<div class="bsa-cpc"></div>
{% endif %}
#}

{% endblock %}

{% block extrajs %}
Expand All @@ -165,10 +236,48 @@ <h4><a href="{{ post.url }}">{{ post.url }}</a></h4>
{% javascript 'plog:post' %}
{% endif %}

{#<script src="https://m.servedby-buysellads.com/monetization.js" async></script>#}
<script>
(function() {
var attempts = 0;
var loop = function() {
if (typeof _bsa !== 'undefined' && _bsa) {
_bsa.init('default', 'CKYD52JJ', 'placement:peterbecom', {
target: '.bsa-cpc',
align: 'horizontal',
disable_css: 'true',
});
} else {
attempts++;
if (attempts < 10) {
setTimeout(loop, 500);
}
}
};
var inject = function(cb) {
var script = document.createElement('script');
script.src = 'https://m.servedby-buysellads.com/monetization.js';
script.async = true;
script.onload = cb;
document.head.appendChild(script);
}
function isMobileDevice() {
return (typeof window.orientation !== "undefined") || (navigator.userAgent.indexOf('IEMobile') !== -1);
};
if (document.querySelector('div.bsa-cpc') && !isMobileDevice()) {
inject(loop);
}
})();
</script>

{% endblock %}

{% block content %}

{% if request.path != '/plog/blogitem-040601-1' %}
<div class="bsa-cpc"></div>
{% endif %}

{% if pub_date_years > 3 and request.path != '/plog/blogitem-040601-1' %}
<div class="ui {% if pub_date_years > 6 %}warning{% else %}info{% endif %} message"
style="margin-bottom:40px">
Expand All @@ -185,6 +294,7 @@ <h4><a href="{{ post.url }}">{{ post.url }}</a></h4>

{% include "plog/_post.html" %}


{% if show_buttons %}
<p>
<a href="https://twitter.com/peterbe" class="ui tiny twitter button"
Expand Down
21 changes: 21 additions & 0 deletions reload_and_clear_cache.py
@@ -0,0 +1,21 @@
#!/usr/bin/env python

import os
import shutil
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "peterbecom.settings")
application = get_wsgi_application()


cache_dir = 'peterbecom-static-content/_FSCACHE/plog'
if os.path.isdir(cache_dir):
shutil.rmtree(cache_dir)
print('Deleted', cache_dir)

from django.core.cache import cache # noqa
cache.clear()
with open('peterbecom/__init__.py') as f:
code = f.read()

with open('peterbecom/__init__.py', 'w') as f:
f.write(code)

0 comments on commit 8654b93

Please sign in to comment.