Skip to content

Commit

Permalink
Add Flattr button
Browse files Browse the repository at this point in the history
This is enabled if the FLATTR_USER configuration variable is set.

By default, all posts are in the "text" category. This can be changed by
setting "flattrcategory" in the post metadata. Valid values are "text",
"images", "video", "audio", "software", "people" and "rest" (as per
https://api.flattr.com/rest/v2/categories.txt).

Closes Pelican-Elegant#104.
  • Loading branch information
Schnouki committed Jul 9, 2014
1 parent 8553952 commit 83189e4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions static/css/elegant.css
Expand Up @@ -182,6 +182,9 @@ article div.article-content ul:not(.articles-timeline) a:hover {
text-decoration: none;
text-shadow: none;
}
article iframe.FlattrButton {
margin-top: 10px;
}
.article-content, div.recent-posts p {
font: 1.2em/1.6em 'PT Serif', Georgia, 'Times New Roman', Times, Serif;
text-align: justify;
Expand Down
32 changes: 32 additions & 0 deletions templates/_includes/flattr.html
@@ -0,0 +1,32 @@
{% macro flattr_script() %}
{% if FLATTR_USER %}
<script type="text/javascript">
/* <![CDATA[ */
(function() {
var s = document.createElement('script');
var t = document.getElementsByTagName('script')[0];

s.type = 'text/javascript';
s.async = true;
s.src = '//api.flattr.com/js/0.6/load.js?'+
'mode=auto&uid={{ FLATTR_USER }}&language={{ DEFAULT_LANG }}&category=text&button=compact';

t.parentNode.insertBefore(s, t);
})();
/* ]]> */
</script>
{% endif %}
{% endmacro %}

{% macro flattr_button(article) %}
{% if FLATTR_USER %}
<a class="FlattrButton" style="display:none;"
title="{{ article.title|striptags|escape }}"
data-flattr-uid="{{ FLATTR_USER }}"
data-flattr-tags="{{ article.tags|join(', ') }}"
data-flattr-category="{{ article.flattrcategory|default('text') }}"
href="{{ SITEURL }}/{{ article.url }}">
{{ article.summary|striptags|truncate(2000)|escape }}
</a>
{% endif %}
{% endmacro %}
1 change: 1 addition & 0 deletions templates/article.html
Expand Up @@ -79,6 +79,7 @@ <h4>Contents</h4>
</div>
<section>
<div class="span2" style="float:right;font-size:0.9em;">
{{ flattr.flattr_button(article) }}
{% if article.date %}
<h4>Published</h4>
{% set day = article.date.strftime('%d')|int %}
Expand Down
2 changes: 2 additions & 0 deletions templates/base.html
Expand Up @@ -49,6 +49,8 @@
{% include '_includes/feeds.html' %}
{% endblock feed_links %}
{% include '_includes/analytics.html' %}
{% import '_includes/flattr.html' as flattr with context %}
{{ flattr.flattr_script() }}
</head>
<body>
<div id="content-sans-footer">
Expand Down

0 comments on commit 83189e4

Please sign in to comment.