Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Last active August 29, 2015 14:08
Show Gist options
  • Save fizerkhan/8c5fdef205479afb37d7 to your computer and use it in GitHub Desktop.
Save fizerkhan/8c5fdef205479afb37d7 to your computer and use it in GitHub Desktop.
Add hacker news button in Octopress

Steps

  1. Create a file hn_like.html with following contents under source/_includes directory
{% if site.hn_like_button %}
<!--
hn like button plugin for jekyll/octopress
Author: dryman (Felix Ren-Chyan Chern)

Inpired from http://hnlike.com/ written by sbashyal

(The MIT License)

Copyright © 2012-2013 Felix Ren-Chyan Chern

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the ‘Software’), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
  <script type="text/javascript">
    (function(){
      var hn_like = document.createElement('iframe');
      hn_like.frameborder="no";
      hn_like.scrolling="no";
      hn_like.height="28px";
      hn_like.width="115px";
      hn_like.src = "http://hnlike.com/upvote.php?link="
                    + encodeURIComponent(document.location)
                    + "&title="
                    + encodeURIComponent("{{ page.title }}");
      hn_like.innerHTML="iframes not supported by your browser";
      var twitter = document.getElementsByClassName("twitter-share-button")[0];

      twitter.parentNode.insertBefore(
        hn_like,
        twitter
      );
    })();
  </script>

<!-- end of hn like button -->
{% endif %}
  1. Add one line {% include hn_like.html %} into source/_includes/after_footer.html

  2. Add following lines into _config.yml

# hacker news like button
hn_like_button: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment