Inspiration
I found out that some cool blogs have a cute hacker news like button on each of its posts.
The service is HN Like Button, created by shashyal. To use it you can use the generator like so:
However, we don’t want to do that every time, right? So I decided to write a small Jekyll plugin to generate the button automatically. Hope you can enjoy it!
The hidden API of HNLike
Well…not really. The generated html snippet looks like this:
1 2 3 |
|
Observe that in the src
after the upvote.php?
there are only two
key valure pairs:
link=
html link&title=
title text
We just need to replace the html link and title text to our URL-escaped string and it is done.
Integrate with Jekyll
Jekyll/Octopress is designed to extend its functionality by users. For details
you can take a look at Theming and Customization - Octopress. Follow
the instructions, I simply added a new html snippet in source/_includes/
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
I modified the height and width otherwise it will be too big. Also I use jekyll
liquid helpers instead of document.title
to form title text. Finally I use the
twitter-share-button
element to position where I should insert the button in.
Installation steps
-
To extend the built in snippet, download hn_like.html into your
source/_includes
directory -
Add one line
{% include hn_like.html %}
intosource/_includes/after_footer.html
. -
Add
1 2 |
|
into your _config.yml
.
Edit:
The vote won’t update immediately. It will show up until hacker news index the post and can be reached via HN search API.
Edit: 2012-04-07
I changed my domain name and all HN/Twitter/FB/G+ counts reset to zero. So I submit the post to HN again.