summaryrefslogtreecommitdiffstats
path: root/like.py
blob: 20b082fcbc3875af07ac2ef955c5c938f5e871a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
# -*- coding: utf-8 -*-

# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.

# Author: Stefan Ritter <xeno@thehappy.de>
# Description: Add social network buttons under your entry titles
# Version: 1.0

print("""
    <script type="text/javascript">
    $(document).ready(function() {
        blog_url = window.location;
        $("div.entry_title").after(" \\
            <a target='_blank' class='link_fb'><img src='plugins/like/icons/facebook.png' alt='facebook' /></a> \\
            <a target='_blank' class='link_gp'><img src='plugins/like/icons/google-plus.png' alt='google-plus' /></a> \\
            <a target='_blank' class='link_tw'><img src='plugins/like/icons/twitter.png' alt='twitter' /></a> \\
        ");
        $('a.link_fb a.link_gp a.link_tw').each(function(i) { // Add index class to all icons
            $(this).addClass('link_' + i);
        });
        $('div.entry_title').each(function(i) { // Add index class to every entry title
            $(this).addClass('link_' + i);
        });
        $('a.link_fb').each(function(i) { // Generate href for facebook icons
            title =  $('div.link_' + i).text().trim();
            url = blog_url + '?p=' + encodeURIComponent(title.replace(/\s/g, '-'));
            $(this).attr({'href': 'https://www.facebook.com/sharer.php?u=' + url + '&t=' + title});
        });
        $('a.link_gp').each(function(i) { // Generate href for google plus icons
            title =  $('div.link_' + i).text().trim();
            url = blog_url + '?p=' + encodeURIComponent(title.replace(/\s/g, '-'));
            $(this).attr({'href': 'https://m.google.com/app/plus/x/?v=compose&content=' + title + '%20' + url});
        });
        $('a.link_tw').each(function(i) { // Generate href for twitter icons
            title =  $('div.link_' + i).text().trim();
            url = blog_url + '?p=' + encodeURIComponent(title.replace(/\s/g, '-'));
            $(this).attr({'href': 'https://twitter.com/home?status=' + title + ' ' + url});
        });
    });
    </script>
""")

# vim: set sw=4 tw=0 ts=4 expandtab: