Skip to content

Instantly share code, notes, and snippets.

@tonyseek
Created May 30, 2013 02:49
Show Gist options
  • Save tonyseek/5675459 to your computer and use it in GitHub Desktop.
Save tonyseek/5675459 to your computer and use it in GitHub Desktop.
Show a button to send post to kindle on the posts of Octopress.
diff --git a/_config.yml b/_config.yml
index 42de00c..24dff5e 100644
--- a/_config.yml
+++ b/_config.yml
@@ -72,6 +72,9 @@ github_repo_count: 3
github_show_profile_link: true
github_skip_forks: true
+# Send to Kindle
+send_to_kindle_button: true
+
# Twitter
twitter_user:
twitter_tweet_button: false
diff --git a/sass/custom/_styles.scss b/sass/custom/_styles.scss
index 91ffccc..beb87c3 100644
--- a/sass/custom/_styles.scss
+++ b/sass/custom/_styles.scss
@@ -1,2 +1,22 @@
// This File is imported last, and will override other styles in the cascade
// Add styles here to make changes without digging in too much
+.read-it-later {
+ overflow: hidden;
+ & > span, & > a {
+ float: right;
+ cursor: pointer;
+ font-size: 0.5em;
+ background-color: #ddd;
+ color: #777;
+ border-radius: 5px;
+ padding: 0.1em 0.3em;
+
+ &:hover {
+ color: #555;
+ }
+ }
+
+ position: absolute;
+ top: 0;
+ right: 0;
+}
diff --git a/source/_includes/article.html b/source/_includes/article.html
index 23f4884..8de3715 100644
--- a/source/_includes/article.html
+++ b/source/_includes/article.html
@@ -1,5 +1,10 @@
{% unless page.no_header %}
<header>
+ <div class="read-it-later">
+ {% if site.send_to_kindle_button %}
+ <span data-platform="kindle"></span>
+ {% endif %}
+ </div>
{% if index %}
<h1 class="entry-title"><a href="{{ root_url }}{{ post.url }}">{% if site.titlecase %}{{ post.title | titlecase }}{% else %}{{ post.title }}{% endif %}</a></h1>
{% else %}
diff --git a/source/_includes/head.html b/source/_includes/head.html
index d614b84..9aaee53 100644
--- a/source/_includes/head.html
+++ b/source/_includes/head.html
@@ -27,4 +27,5 @@
<script src="{{ root_url }}/javascripts/octopress.js" type="text/javascript"></script>
{% include custom/head.html %}
{% include google_analytics.html %}
+ {% include send_to_kindle.html %}
</head>
diff --git a/source/_includes/send_to_kindle.html b/source/_includes/send_to_kindle.html
new file mode 100644
index 0000000..2150645
--- /dev/null
+++ b/source/_includes/send_to_kindle.html
@@ -0,0 +1,19 @@
+{% if site.send_to_kindle_button %}
+ <script type="text/javascript" src="https://d1xnn692s7u6t6.cloudfront.net/widget.js"></script>
+ <script type="text/javascript">
+ $(function() {
+ $("article").each(function() {
+ if (!$(this).parent().hasClass("blog-index")) {
+ $(this).find(".read-it-later [data-platform='kindle']")
+ .addClass("kindleWidget").text("发送到 Kindle");
+ }
+ });
+ window.$SendToKindle && $SendToKindle.Widget.init({
+ "content":".entry-content",
+ "title":".entry-title",
+ "author":".author .fn",
+ "published":".meta time"
+ });
+ });
+ </script>
+{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment