A new Riff-radio.org site with a static approach.

social_buttons.html 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <dl class="docinfo simple">
  2. <dt class="version">Version<span class="colon">:</span></dt>
  3. <dd class="version">8.2.3</dd>
  4. </dl>
  5. <nav class="contents alert alert-primary float-md-right" id="contents" role="doc-toc">
  6. <p class="topic-title">Contents</p>
  7. <ul class="simple">
  8. <li><p><a class="reference internal" href="#the-default" id="toc-entry-1">The Default</a></p></li>
  9. <li><p><a class="reference internal" href="#sharenice" id="toc-entry-2">ShareNice</a></p></li>
  10. <li><p><a class="reference internal" href="#socialshareprivacy" id="toc-entry-3">SocialSharePrivacy</a></p>
  11. <ul>
  12. <li><p><a class="reference internal" href="#the-hard-way" id="toc-entry-4">The Hard Way</a></p></li>
  13. <li><p><a class="reference internal" href="#the-easy-way" id="toc-entry-5">The Easy Way</a></p></li>
  14. </ul>
  15. </li>
  16. </ul>
  17. </nav>
  18. <section id="the-default">
  19. <h1><a class="toc-backref" href="#toc-entry-1" role="doc-backlink">The Default</a></h1>
  20. <p>By Default, the themes provided with Nikola will add to your pages a &quot;slide in&quot; widget at
  21. the bottom right of the page, provided by Addthis. This is the HTML code for that:</p>
  22. <pre class="code html"><a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-1"></a><span class="c">&lt;!-- Social buttons --&gt;</span>
  23. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-2"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">&quot;addthisbox&quot;</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_toolbox addthis_peekaboo_style</span>
  24. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-3"></a><span class="s"> addthis_default_style addthis_label_style addthis_32x32_style&quot;</span><span class="p">&gt;</span>
  25. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-4"></a><span class="p">&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_button_more&quot;</span><span class="p">&gt;</span>Share<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  26. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-5"></a><span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_button_facebook&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  27. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-6"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_button_google_plusone_share&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  28. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-7"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_button_linkedin&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  29. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-8"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">&quot;addthis_button_twitter&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  30. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-9"></a><span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
  31. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-10"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
  32. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-11"></a><span class="p">&lt;</span><span class="nt">script</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f7088a56bb93798&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
  33. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-12"></a><span class="c">&lt;!-- End of social buttons --&gt;</span>
  34. <a name="rest_code_fdbd4b2582b34ec78f82fe9fab67f0d6-13"></a>&quot;&quot;&quot;
  35. </pre><p>You can change that using the <code class="docutils literal">SOCIAL_BUTTONS_CODE</code> option in your conf.py. In some cases, just
  36. doing that will be enough but in others, it won't. This document tries to describe all the bits
  37. involved in making this work correctly.</p>
  38. <dl>
  39. <dt>Part 1: <code class="docutils literal">SOCIAL_BUTTONS_CODE</code></dt>
  40. <dd><p>Social sharing services like addthis and others will provide you a HTML snippet.
  41. If it is self-contained, then just setting <code class="docutils literal">SOCIAL_BUTTONS_CODE</code> may be enough.
  42. Try :-)</p>
  43. </dd>
  44. <dt>Part 2: The theme</dt>
  45. <dd><p>The <code class="docutils literal">SOCIAL_BUTTONS_CODE</code> HTML fragment will be embedded <em>somewhere</em> by the theme. Whether that
  46. is the correct place or not is not something the theme author can truly know, so it is possible that
  47. you may have to tweak the <code class="docutils literal">base.html</code> template to make it look good.</p>
  48. </dd>
  49. <dt>Part 3: <code class="docutils literal">BODY_END</code> and <code class="docutils literal">EXTRA_HEAD_DATA</code></dt>
  50. <dd><p>Some social sharing code requires JS execution that depends on JQuery being available
  51. (example: <a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">SocialSharePrivacy</a>). It's good
  52. practice (and often, the only way that will work) to put those at the end of <code class="docutils literal">&lt;BODY&gt;</code>,
  53. and one easy way to do that is to put them in <code class="docutils literal">BODY_END</code></p>
  54. <p>On the other hand, it's possible that it requires you to load some CSS files.
  55. The right place for that is in the document's <code class="docutils literal">&lt;HEAD&gt;</code> so they should be added
  56. in <code class="docutils literal">EXTRA_HEAD_DATA</code></p>
  57. </dd>
  58. <dt>Part 4: assets</dt>
  59. <dd><p>For sharing code that doesn't rely on a social sharing service, you may need to add CSS, Image, or JS
  60. files to your site</p>
  61. </dd>
  62. </dl>
  63. </section>
  64. <section id="sharenice">
  65. <h1><a class="toc-backref" href="#toc-entry-2" role="doc-backlink">ShareNice</a></h1>
  66. <p><a class="reference external" href="https://graingert.co.uk/shareNice/">ShareNice</a> is &quot;written in order to provide social sharing features to
  67. web developers and website administrators who wish to maintain and protect their users' privacy&quot;
  68. which sounds cool to me.</p>
  69. <p>Let's go step by step into integrating the hosted version of ShareNice into a Nikola site.</p>
  70. <p>For testing purposes, let's do it on a demo site:</p>
  71. <pre class="literal-block">$ nikola init --demo sharenice_test
  72. A new site with example data has been created at sharenice_test.
  73. See README.txt in that folder for more information.
  74. $ cd sharenice_test/</pre>
  75. <p>To see what's going on, let's start Nikola in &quot;auto mode&quot;. This should build the
  76. site and open a web browser showing the default configuration, with the AddThis widget:</p>
  77. <pre class="literal-block">$ nikola auto -b</pre>
  78. <p>First, let's add the HTML snippet that will show the sharing options. In your conf.py, set this, which
  79. is the HTML code suggested by ShareNice:</p>
  80. <pre class="code python"><a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-1"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;&lt;div id=&quot;shareNice&quot; data-share-label=&quot;Share&quot;</span>
  81. <a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-2"></a><span class="s2"> data-color-scheme=&quot;black&quot; data-icon-size=&quot;32&quot; data-panel-bottom=&quot;plain&quot;</span>
  82. <a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-3"></a><span class="s2"> data-services=&quot;plus.google.com,facebook.com,digg.com,email,delicious.com,twitter.com&quot;</span>
  83. <a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-4"></a><span class="s2"> style=&quot;float:right&quot;&gt;&lt;/div&gt;&quot;&quot;&quot;</span>
  84. <a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-5"></a>
  85. <a name="rest_code_d45bd5e47f254bfeb9aa565ed399def8-6"></a><span class="n">BODY_END</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;&lt;script src=&quot;https://graingert.co.uk/shareNice/code.js&quot;&gt;&lt;/script&gt;&quot;&quot;&quot;</span>
  86. </pre><p>And you should now see a sharing box at the bottom right of the page.</p>
  87. <p>Main problem remaining is that it doesn't really look good and integrated in the page layout.
  88. I suggest changing the code to this which looks nicer, but still has some placement issues:</p>
  89. <pre class="code python"><a name="rest_code_b749fc146e7e47cc8686e5aaf4c038f1-1"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;&lt;div id=&quot;shareNice&quot; data-share-label=&quot;Share&quot;</span>
  90. <a name="rest_code_b749fc146e7e47cc8686e5aaf4c038f1-2"></a><span class="s2"> data-color-scheme=&quot;black&quot; data-icon-size=&quot;32&quot; data-panel-bottom=&quot;plain&quot;</span>
  91. <a name="rest_code_b749fc146e7e47cc8686e5aaf4c038f1-3"></a><span class="s2"> data-services=&quot;plus.google.com,facebook.com,email,twitter.com&quot;</span>
  92. <a name="rest_code_b749fc146e7e47cc8686e5aaf4c038f1-4"></a><span class="s2"> style=&quot;position: absolute; left: 20px; top: 60px;&quot;&gt;&lt;/div&gt;&quot;&quot;&quot;</span>
  93. </pre><p>If anyone comes up with a better idea of styling/placement, just let me know ;-)</p>
  94. <p>One bad bit of this so far is that you are now using a script from another site, and that
  95. doesn't let Nikola perform as many optimizations to your page as it could.
  96. So, if you really want to go the extra mile to save a few KB and round trips, you <em>could</em>
  97. install your own copy from the <a class="reference external" href="https://github.com/mischat/shareNice">github repo</a> and
  98. use that instead of the copy at <a class="reference external" href="https://graingert.co.uk/shareNice">ShareNice</a>.</p>
  99. <p>Then, you can create your own theme inheriting from the one you are using and add the CSS
  100. and JS files from ShareNice into your <code class="docutils literal">bundles</code> configuration so they are combined and
  101. minified.</p>
  102. </section>
  103. <section id="socialshareprivacy">
  104. <h1><a class="toc-backref" href="#toc-entry-3" role="doc-backlink">SocialSharePrivacy</a></h1>
  105. <section id="the-hard-way">
  106. <h2><a class="toc-backref" href="#toc-entry-4" role="doc-backlink">The Hard Way</a></h2>
  107. <p><a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">SocialSharePrivacy</a> is &quot;a jQuery plugin that
  108. lets you add social share buttons to your website that don't allow the social sites to track
  109. your users.&quot; Nice!</p>
  110. <p>Let's go step-by-step into integrating SocialSharePrivacy into a Nikola site. To improve
  111. privacy, they recommend you not use the hosted service so we'll do it the hard way, by
  112. getting and distributing everything in our own site.</p>
  113. <p><a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">https://github.com/panzi/SocialSharePrivacy</a></p>
  114. <p>For testing purposes, let's do it on a demo site:</p>
  115. <pre class="literal-block">$ nikola init --demo ssp_test
  116. A new site with example data has been created at ssp_test.
  117. See README.txt in that folder for more information.
  118. $ cd ssp_test/</pre>
  119. <p>To see what's going on, let's start Nikola in &quot;auto mode&quot;. This should build the
  120. site and open a web browser showing the default configuration, with the AddThis widget:</p>
  121. <pre class="literal-block">$ nikola auto -b</pre>
  122. <p>Now, download <a class="reference external" href="https://github.com/panzi/SocialSharePrivacy/archive/master.zip">the current version</a>
  123. and unzip it. You will have a <code class="docutils literal"><span class="pre">SocialSharePrivacy-master</span></code> folder with lots of stuff in it.</p>
  124. <p>First, we need to build it (this requires a working and modern uglifyjs, this may not be easy):</p>
  125. <pre class="literal-block">$ cd SocialSharePrivacy-master
  126. $ sh build.sh -m gplus,twitter,facebook,mail -s &quot;/assets/css/socialshareprivacy.css&quot; -a off</pre>
  127. <p>You will now have several files in a <code class="docutils literal">build</code> folder. We need to bring them into the site:</p>
  128. <pre class="literal-block">$ cp -Rv SocialSharePrivacy-master/build/* files/
  129. $ cp -R SocialSharePrivacy-master/images/ files/assets/</pre>
  130. <p>Edit your <code class="docutils literal">conf.py</code>:</p>
  131. <pre class="code python"><a name="rest_code_65b770dc716e498eb31cf1abee0d274c-1"></a><span class="n">BODY_END</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span>
  132. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-2"></a><span class="s2">&lt;script src=&quot;/javascripts/jquery.socialshareprivacy.min.js&quot;&gt;&lt;/script&gt;</span>
  133. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-3"></a><span class="s2">&lt;script&gt;</span>
  134. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-4"></a><span class="s2">$(document).ready(function () {</span>
  135. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-5"></a><span class="s2"> $(&#39;.share&#39;).socialSharePrivacy();</span>
  136. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-6"></a><span class="s2">});</span>
  137. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-7"></a><span class="s2">&lt;/script&gt;</span>
  138. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-8"></a><span class="s2">&quot;&quot;&quot;</span>
  139. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-9"></a>
  140. <a name="rest_code_65b770dc716e498eb31cf1abee0d274c-10"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;&lt;div class=&quot;share&quot;&gt;&lt;/div&gt;&quot;&quot;&quot;</span>
  141. </pre><p>In my experience this produces a broken, duplicate, semi-working thing. YMMV and if you make it work correctly, let me know how :-)</p>
  142. </section>
  143. <section id="the-easy-way">
  144. <h2><a class="toc-backref" href="#toc-entry-5" role="doc-backlink">The Easy Way</a></h2>
  145. <p>Go to <a class="reference external" href="https://panzi.github.io/SocialSharePrivacy/">https://panzi.github.io/SocialSharePrivacy/</a> and use the provided form to get the code. Make sure you check &quot;I already use JQuery&quot;
  146. if you are using one of the themes that require it, like site or default, select the services you want, and use your disqus name if
  147. you have one.</p>
  148. <p>It will give you 3 code snippets:</p>
  149. <dl class="simple">
  150. <dt>&quot;Insert this once in the head of your page&quot;</dt>
  151. <dd><p>Put it in <code class="docutils literal">BODY_END</code></p>
  152. </dd>
  153. <dt>&quot;Insert this wherever you want a share widget displayed&quot;</dt>
  154. <dd><p>Put it in <code class="docutils literal">SOCIAL_BUTTONS_CODE</code></p>
  155. </dd>
  156. <dt>&quot;Insert this once anywhere after the other code&quot;</dt>
  157. <dd><p>Put it in <code class="docutils literal">BODY_END</code></p>
  158. </dd>
  159. </dl>
  160. <p>That should give you a working integration (not tested)</p>
  161. </section>
  162. </section>