From d8999cf6834f7406ba707c7d1f5772584e5e1a17 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Wed, 9 Sep 2015 08:11:00 -0400 Subject: [PATCH 01/10] Expose tags for generating share urls --- lib/octopress-social.rb | 4 ++++ lib/octopress-social/email.rb | 6 +++++- lib/octopress-social/facebook.rb | 18 ++++++++++-------- lib/octopress-social/google-plus.rb | 9 +++++++-- lib/octopress-social/twitter.rb | 10 +++++++--- test/site/_expected/post-loop.html | 6 ++++++ test/site/_expected/share-page.html | 6 ++++++ test/site/_expected/share-post/index.html | 6 ++++++ test/site/_includes/share.html | 6 ++++++ test/site/_site/post-loop.html | 6 ++++++ test/site/_site/share-page.html | 6 ++++++ test/site/_site/share-post/index.html | 6 ++++++ 12 files changed, 75 insertions(+), 14 deletions(-) diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 0e20be9..692447e 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -40,17 +40,20 @@ def item(context, input) Liquid::Template.register_tag('tweet', Octopress::Social::Twitter::Tweet) Liquid::Template.register_tag('tweet_button', Octopress::Social::Twitter::Tag) Liquid::Template.register_tag('tweet_link', Octopress::Social::Twitter::Tag) +Liquid::Template.register_tag('tweet_url', Octopress::Social::Twitter::Tag) Liquid::Template.register_tag('twitter_script_tag', Octopress::Social::Twitter::Tag) Liquid::Template.register_tag('twitter_follow_button', Octopress::Social::Twitter::Tag) Liquid::Template.register_tag('twitter_profile_link', Octopress::Social::Twitter::Tag) Liquid::Template.register_tag('gplus_share_button', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('gplus_share_link', Octopress::Social::GooglePlus::Tag) +Liquid::Template.register_tag('gplus_share_url', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('gplus_one_button', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('gplus_follow_button', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('gplus_profile_link', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('gplus_script_tag', Octopress::Social::GooglePlus::Tag) Liquid::Template.register_tag('facebook_like_button', Octopress::Social::Facebook::Tag) Liquid::Template.register_tag('facebook_share_link', Octopress::Social::Facebook::Tag) +Liquid::Template.register_tag('facebook_share_url', Octopress::Social::Facebook::Tag) Liquid::Template.register_tag('facebook_send_button', Octopress::Social::Facebook::Tag) Liquid::Template.register_tag('facebook_follow_button', Octopress::Social::Facebook::Tag) Liquid::Template.register_tag('facebook_profile_link', Octopress::Social::Facebook::Tag) @@ -60,6 +63,7 @@ def item(context, input) Liquid::Template.register_tag('disqus_comments', Octopress::Social::Disqus::Tag) Liquid::Template.register_tag('disqus_comments_link', Octopress::Social::Disqus::Tag) Liquid::Template.register_tag('email_share_link', Octopress::Social::Email::Tag) +Liquid::Template.register_tag('email_share_url', Octopress::Social::Email::Tag) Liquid::Template.register_tag('email_contact_link', Octopress::Social::Email::Tag) Liquid::Template.register_tag('github_profile_link', Octopress::Social::GitHub::Tag) diff --git a/lib/octopress-social/email.rb b/lib/octopress-social/email.rb index 6930860..ad32c56 100644 --- a/lib/octopress-social/email.rb +++ b/lib/octopress-social/email.rb @@ -64,10 +64,14 @@ def message(site, item) def email_share_link(site, item) %Q{#{config['share_link_text']}} end + def email_share_url(site, item) + "mailto:?subject=#{subject(site, item)}&body=#{message(site, item)}" + end + def email_contact_link(site, item) %Q{#{config['share_link_text']}} + end + + def facebook_share_url(site, item) if config['app_id'] - %Q{#{config['share_link_text']} - } + "https://www.facebook.com/dialog/share?". + concat("app_id=#{config['app_id']}"). + concat("&href=#{url}&redirect_uri=#{url}") else - %Q{#{config['share_link_text']}} + "https://www.facebook.com/sharer/sharer.php?u=#{url}" end end diff --git a/lib/octopress-social/google-plus.rb b/lib/octopress-social/google-plus.rb index 0ce8253..2693280 100644 --- a/lib/octopress-social/google-plus.rb +++ b/lib/octopress-social/google-plus.rb @@ -30,12 +30,17 @@ def config(site=nil) end def gplus_share_link(site, item) - %Q{#{config['share_link_text']}} end + def gplus_share_url(site, item) + url = Social.full_url(site, item) + "https://plus.google.com/share?url=#{url}" + end + def gplus_one_button(site, item) %Q{
} end diff --git a/lib/octopress-social/twitter.rb b/lib/octopress-social/twitter.rb index 3f386eb..a3355bd 100644 --- a/lib/octopress-social/twitter.rb +++ b/lib/octopress-social/twitter.rb @@ -29,15 +29,19 @@ def set_url(site, item) end def tweet_link(site, item) - %Q{#{config['tweet_link_text']}} end + def tweet_url(site, item) + "https://twitter.com/intent/tweet?&text=#{ERB::Util.url_encode(message(site, item)).strip}" + end + def tweet_button(site, item) %Q{ - Share post Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index 20dea0d..60ac9c1 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -13,6 +13,12 @@ Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index d24eb48..c85c918 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -13,6 +13,12 @@ Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index e7a2f57..bef5bee 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -10,3 +10,9 @@ {% gplus_share_link %} {% facebook_share_link %} {% email_share_link %} + +Share URLs: +Twitter +Google+ +Facebook +Email diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index ccaa827..a4646da 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -15,6 +15,12 @@

Share post

Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index 20dea0d..60ac9c1 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -13,6 +13,12 @@ Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index d24eb48..c85c918 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -13,6 +13,12 @@ Facebook Email +Share URLs: +Twitter +Google+ +Facebook +Email + Comment links: Comments Comments From f2c188b96f03afdec094cba154510ef1685d51f7 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Wed, 9 Sep 2015 08:20:26 -0400 Subject: [PATCH 02/10] Encode URLs shared via GPlus and Facebook --- lib/octopress-social/facebook.rb | 5 +++-- lib/octopress-social/google-plus.rb | 3 ++- test/site/_expected/post-loop.html | 8 ++++---- test/site/_expected/share-page.html | 8 ++++---- test/site/_expected/share-post/index.html | 8 ++++---- test/site/_site/post-loop.html | 8 ++++---- test/site/_site/share-page.html | 8 ++++---- test/site/_site/share-post/index.html | 8 ++++---- 8 files changed, 29 insertions(+), 27 deletions(-) diff --git a/lib/octopress-social/facebook.rb b/lib/octopress-social/facebook.rb index d86bff8..5c29a13 100644 --- a/lib/octopress-social/facebook.rb +++ b/lib/octopress-social/facebook.rb @@ -42,12 +42,13 @@ def facebook_share_link(site, item) end def facebook_share_url(site, item) + encoded_url = ERB::Util.url_encode(url) if config['app_id'] "https://www.facebook.com/dialog/share?". concat("app_id=#{config['app_id']}"). - concat("&href=#{url}&redirect_uri=#{url}") + concat("&href=#{encoded_url}&redirect_uri=#{encoded_url}") else - "https://www.facebook.com/sharer/sharer.php?u=#{url}" + "https://www.facebook.com/sharer/sharer.php?u=#{encoded_url}" end end diff --git a/lib/octopress-social/google-plus.rb b/lib/octopress-social/google-plus.rb index 2693280..68ef1ef 100644 --- a/lib/octopress-social/google-plus.rb +++ b/lib/octopress-social/google-plus.rb @@ -38,7 +38,8 @@ def gplus_share_link(site, item) def gplus_share_url(site, item) url = Social.full_url(site, item) - "https://plus.google.com/share?url=#{url}" + encoded_url = ERB::Util.url_encode(url) + "https://plus.google.com/share?url=#{encoded_url}" end def gplus_one_button(site, item) diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index a4646da..a3acd96 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -11,14 +11,14 @@

Share post

Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index 60ac9c1..e031f10 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -9,14 +9,14 @@ Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index c85c918..53b3ad2 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -9,14 +9,14 @@ Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index a4646da..a3acd96 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -11,14 +11,14 @@

Share post

Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index 60ac9c1..e031f10 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -9,14 +9,14 @@ Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index c85c918..53b3ad2 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -9,14 +9,14 @@ Share Links: -Google+ - +Google+ + Share URLs: Twitter -Google+ -Facebook +Google+ +Facebook Email Comment links: From e711b2f5514322674ed47c0747a60f413b4477db Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Wed, 9 Sep 2015 08:24:25 -0400 Subject: [PATCH 03/10] Remove extraneous & from Twitter share URL --- lib/octopress-social/twitter.rb | 2 +- test/site/_expected/post-loop.html | 4 ++-- test/site/_expected/share-page.html | 4 ++-- test/site/_expected/share-post/index.html | 4 ++-- test/site/_site/post-loop.html | 4 ++-- test/site/_site/share-page.html | 4 ++-- test/site/_site/share-post/index.html | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/octopress-social/twitter.rb b/lib/octopress-social/twitter.rb index a3355bd..86fae14 100644 --- a/lib/octopress-social/twitter.rb +++ b/lib/octopress-social/twitter.rb @@ -36,7 +36,7 @@ def tweet_link(site, item) end def tweet_url(site, item) - "https://twitter.com/intent/tweet?&text=#{ERB::Util.url_encode(message(site, item)).strip}" + "https://twitter.com/intent/tweet?text=#{ERB::Util.url_encode(message(site, item)).strip}" end def tweet_button(site, item) diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index a3acd96..083cbb8 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -10,13 +10,13 @@

Share post

Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index e031f10..0e9b1c7 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -8,13 +8,13 @@
Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index 53b3ad2..beea7bb 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -8,13 +8,13 @@
Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index a3acd96..083cbb8 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -10,13 +10,13 @@

Share post

Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index e031f10..0e9b1c7 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -8,13 +8,13 @@
Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index 53b3ad2..beea7bb 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -8,13 +8,13 @@
Share Links: - + Google+ Share URLs: -Twitter +Twitter Google+ Facebook Email From 1fe9375addd1b18225253839b89a14103d89b6ce Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Thu, 10 Sep 2015 08:07:29 -0400 Subject: [PATCH 04/10] Add docs for url tags --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 286b856..baee81b 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Sharing tags: ``` {% tweet_button %} {% tweet_link %} # Tweet with a (no js) link +{% tweet_url %} # URL to tweet with a (no js) link. URL only, no additional HTML markup included. ``` The tweet button and tweet link will open a new page with a composed tweet in the format in your Twitter configuration, `:title by :username - :url :hashtags`. @@ -176,6 +177,7 @@ Sharing tags: {% facebook_like_button %} {% facebook_send_button %} # For private sharing {% facebook_share_link %} # share with a (no js) link +{% facebook_share_url %} # URL to share with a (no js) link. URL only, no additional HTML markup included. ``` Friend and Follow tags: @@ -225,6 +227,7 @@ Sharing tags: {% gplus_one_button %} {% gplus_share_button %} {% gplus_share_link %} # Share with a (no js) link +{% gplus_share_url %} # URL to share with a (no js) link. URL only, no additional HTML markup included. ``` Follow tags: @@ -259,7 +262,8 @@ used to generate a subject and body for a sharing email link. ``` {% email_share_link %} # Share a post or page over email -{% email_contact_link %} # Contac the site's author +{% email_share_url %} # URL to share a post or page over email with a (no js) link. URL only, no additional HTML markup included. +{% email_contact_link %} # Contact the site's author ``` If you want, you may customize an email subject or message on From dcad71acae003eb4f01f0f9a1dff1f42c71b9ad7 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Wed, 9 Sep 2015 08:52:43 -0400 Subject: [PATCH 05/10] Add tag for sharing on Reddit --- lib/octopress-social.rb | 4 +- lib/octopress-social/reddit.rb | 65 +++++++++++++++++++++++ test/site/_expected/post-loop.html | 1 + test/site/_expected/share-page.html | 1 + test/site/_expected/share-post/index.html | 1 + test/site/_includes/share.html | 1 + test/site/_site/post-loop.html | 1 + test/site/_site/share-page.html | 1 + test/site/_site/share-post/index.html | 1 + 9 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 lib/octopress-social/reddit.rb diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 692447e..2afa2f2 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -13,7 +13,8 @@ module Social autoload :Disqus, 'octopress-social/disqus' autoload :Email, 'octopress-social/email' autoload :GitHub, 'octopress-social/github' - + autoload :Reddit, 'octopress-social/reddit' + def full_url(site, item) unless root = site['url'] abort "Site url not configured. Please set url: http://your-site.com in Jekyll configuration file." @@ -66,6 +67,7 @@ def item(context, input) Liquid::Template.register_tag('email_share_url', Octopress::Social::Email::Tag) Liquid::Template.register_tag('email_contact_link', Octopress::Social::Email::Tag) Liquid::Template.register_tag('github_profile_link', Octopress::Social::GitHub::Tag) +Liquid::Template.register_tag('reddit_share_link', Octopress::Social::Reddit::Tag) if defined? Octopress::Docs Octopress::Docs.add({ diff --git a/lib/octopress-social/reddit.rb b/lib/octopress-social/reddit.rb new file mode 100644 index 0000000..ed16881 --- /dev/null +++ b/lib/octopress-social/reddit.rb @@ -0,0 +1,65 @@ +# encoding: UTF-8 +module Octopress + module Social + module Reddit + extend self + + attr_accessor :url, :config + + DEFAULTS = { + 'share_link_text' => 'Reddit', + 'share_link_title' => 'Share on Reddit', + 'share_title' => ':title - :url', + } + + def set_config(site) + @config ||= begin + config = site['octopress_social'] || site + DEFAULTS.merge(config['reddit'] || {}) + end + end + + def set_url(site, item) + @url = Social.full_url(site, item) + end + + def reddit_share_link(site, item) + %Q{#{config['share_link_text']}} + end + + def reddit_share_url(site, item) + encoded_url = ERB::Util.url_encode(url) + encoded_share_title = ERB::Util.url_encode(share_title(site, item)) + "http://www.reddit.com/submit". + concat("?title=#{encoded_share_title}"). + concat("&url=#{encoded_url}") + end + + def share_title(site, item) + (item['reddit_share_title'] || config['share_title']) + .gsub(':title', item['title'] || '') + .gsub(':url', url) + .strip + end + + class Tag < Liquid::Tag + def initialize(tag, input, tokens) + @tag = tag.strip + @input = input.strip + end + + def render(context) + site = context['site'] + item = Octopress::Social.item(context, @input) + + Octopress::Social::Reddit.set_config(site) + Octopress::Social::Reddit.set_url(site, item) + Octopress::Social::Reddit.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip + end + end + end + end +end diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index 083cbb8..1387e9b 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -14,6 +14,7 @@

Share post

Google+ +Reddit Share URLs: Twitter diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index 0e9b1c7..cc6207c 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -12,6 +12,7 @@ Google+ +Reddit Share URLs: Twitter diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index beea7bb..501cab8 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -12,6 +12,7 @@ Google+ +Reddit Share URLs: Twitter diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index bef5bee..ce2d2ab 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -10,6 +10,7 @@ {% gplus_share_link %} {% facebook_share_link %} {% email_share_link %} +{% reddit_share_link %} Share URLs: Twitter diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index 083cbb8..1387e9b 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -14,6 +14,7 @@

Share post

Google+ +Reddit Share URLs: Twitter diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index 0e9b1c7..cc6207c 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -12,6 +12,7 @@ Google+ +Reddit Share URLs: Twitter diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index beea7bb..501cab8 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -12,6 +12,7 @@ Google+ +Reddit Share URLs: Twitter From 216fc4830c072b4ef3ea680c0733d2ecdab69bd8 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Thu, 10 Sep 2015 08:18:53 -0400 Subject: [PATCH 06/10] Add docs for reddit_share_link --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index baee81b..bf8f2dc 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,35 @@ Follow tags: {% gplus_profile_link %} ``` +## Reddit + +Configure this plugin in your site's `_config.yml`. No configurations are required. Here are the configuration defaults. + +```yaml +reddit: + share_link_text: Reddit # Configure the link text + share_link_title: Share on Reddit # Title of the share link + share_title: :title - :url # The suggested title auto-filled in the reddit form +``` + +To include a custom auto-filled share title for a post or page, include a +`reddit_share_title` attribute in the frontmatter of the post/page like this: + +```yaml +reddit_share_title: "Totally not click bait! :title - :url" +``` + +### Reddit Tags + +Sharing tags: +``` +{% reddit_share_link %} # Share with a (no js) link +``` + +The share button will open a new page with a pre-filled Reddit submission form +with a title derived from the `share_title` or page/post specific +`reddit_share_title` configuration discussed above. + ## Email sharing Add convenient `mail:to` links which which helps readers From 55b9ba7e279d49fe71cdac802632bfc8aca470af Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Thu, 10 Sep 2015 07:12:34 -0400 Subject: [PATCH 07/10] Add liquid tag for reddit_share_url --- README.md | 1 + lib/octopress-social.rb | 1 + test/site/_expected/post-loop.html | 1 + test/site/_expected/share-page.html | 1 + test/site/_expected/share-post/index.html | 1 + test/site/_includes/share.html | 1 + test/site/_site/post-loop.html | 1 + test/site/_site/share-page.html | 1 + test/site/_site/share-post/index.html | 1 + 9 files changed, 9 insertions(+) diff --git a/README.md b/README.md index bf8f2dc..52b8f09 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,7 @@ reddit_share_title: "Totally not click bait! :title - :url" Sharing tags: ``` {% reddit_share_link %} # Share with a (no js) link +{% reddit_share_url %} # URL to share with a (no js) link. URL only, no additional HTML markup included. ``` The share button will open a new page with a pre-filled Reddit submission form diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 2afa2f2..527fdd1 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -68,6 +68,7 @@ def item(context, input) Liquid::Template.register_tag('email_contact_link', Octopress::Social::Email::Tag) Liquid::Template.register_tag('github_profile_link', Octopress::Social::GitHub::Tag) Liquid::Template.register_tag('reddit_share_link', Octopress::Social::Reddit::Tag) +Liquid::Template.register_tag('reddit_share_url', Octopress::Social::Reddit::Tag) if defined? Octopress::Docs Octopress::Docs.add({ diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index 1387e9b..49ed20a 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -21,6 +21,7 @@

Share post

Google+ Facebook Email +Reddit Comment links: Comments diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index cc6207c..36d9006 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -19,6 +19,7 @@ Google+ Facebook Email +Reddit Comment links: Comments diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index 501cab8..6e1f7d3 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -19,6 +19,7 @@ Google+ Facebook Email +Reddit Comment links: Comments diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index ce2d2ab..de72435 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -17,3 +17,4 @@ Google+ Facebook Email +Reddit diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index 1387e9b..49ed20a 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -21,6 +21,7 @@

Share post

Google+ Facebook Email +Reddit Comment links: Comments diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index cc6207c..36d9006 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -19,6 +19,7 @@ Google+ Facebook Email +Reddit Comment links: Comments diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index 501cab8..6e1f7d3 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -19,6 +19,7 @@ Google+ Facebook Email +Reddit Comment links: Comments From 5958658704f60ea515107c28e8050cd7403b1182 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Wed, 9 Sep 2015 08:52:43 -0400 Subject: [PATCH 08/10] Add hacker_news_share_link tag for sharing on Hacker News --- lib/octopress-social.rb | 2 + lib/octopress-social/hacker-news.rb | 65 +++++++++++++++++++++++ test/site/_expected/post-loop.html | 1 + test/site/_expected/share-page.html | 1 + test/site/_expected/share-post/index.html | 1 + test/site/_includes/share.html | 1 + test/site/_site/post-loop.html | 1 + test/site/_site/share-page.html | 1 + test/site/_site/share-post/index.html | 1 + 9 files changed, 74 insertions(+) create mode 100644 lib/octopress-social/hacker-news.rb diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 527fdd1..47e6c7f 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -14,6 +14,7 @@ module Social autoload :Email, 'octopress-social/email' autoload :GitHub, 'octopress-social/github' autoload :Reddit, 'octopress-social/reddit' + autoload :HackerNews, 'octopress-social/hacker-news' def full_url(site, item) unless root = site['url'] @@ -69,6 +70,7 @@ def item(context, input) Liquid::Template.register_tag('github_profile_link', Octopress::Social::GitHub::Tag) Liquid::Template.register_tag('reddit_share_link', Octopress::Social::Reddit::Tag) Liquid::Template.register_tag('reddit_share_url', Octopress::Social::Reddit::Tag) +Liquid::Template.register_tag('hacker_news_share_link', Octopress::Social::HackerNews::Tag) if defined? Octopress::Docs Octopress::Docs.add({ diff --git a/lib/octopress-social/hacker-news.rb b/lib/octopress-social/hacker-news.rb new file mode 100644 index 0000000..c097f62 --- /dev/null +++ b/lib/octopress-social/hacker-news.rb @@ -0,0 +1,65 @@ +# encoding: UTF-8 +module Octopress + module Social + module HackerNews + extend self + + attr_accessor :url, :config + + DEFAULTS = { + 'share_link_text' => 'Hacker News', + 'share_link_title' => 'Share on HackerNews', + 'share_title' => ':title - :url', + } + + def set_config(site) + @config ||= begin + config = site['octopress_social'] || site + DEFAULTS.merge(config['hacker_news'] || {}) + end + end + + def set_url(site, item) + @url = Social.full_url(site, item) + end + + def hacker_news_share_link(site, item) + %Q{#{config['share_link_text']}} + end + + def hacker_news_share_url(site, item) + encoded_url = ERB::Util.url_encode(url) + encoded_share_title = ERB::Util.url_encode(share_title(site, item)) + "http://news.ycombinator.com/submitlink". + concat("?t=#{encoded_share_title}"). + concat("&u=#{encoded_url}") + end + + def share_title(site, item) + (item['hacker_news_share_title'] || config['share_title']) + .gsub(':title', item['title'] || '') + .gsub(':url', url) + .strip + end + + class Tag < Liquid::Tag + def initialize(tag, input, tokens) + @tag = tag.strip + @input = input.strip + end + + def render(context) + site = context['site'] + item = Octopress::Social.item(context, @input) + + Octopress::Social::HackerNews.set_config(site) + Octopress::Social::HackerNews.set_url(site, item) + Octopress::Social::HackerNews.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip + end + end + end + end +end diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index 49ed20a..a1a5c0b 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -15,6 +15,7 @@

Share post

Reddit +Hacker News Share URLs: Twitter diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index 36d9006..be3927f 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -13,6 +13,7 @@ Reddit +Hacker News Share URLs: Twitter diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index 6e1f7d3..39e1561 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -13,6 +13,7 @@ Reddit +Hacker News Share URLs: Twitter diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index de72435..cded9f1 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -11,6 +11,7 @@ {% facebook_share_link %} {% email_share_link %} {% reddit_share_link %} +{% hacker_news_share_link %} Share URLs: Twitter diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index 49ed20a..a1a5c0b 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -15,6 +15,7 @@

Share post

Reddit +Hacker News Share URLs: Twitter diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index 36d9006..be3927f 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -13,6 +13,7 @@ Reddit +Hacker News Share URLs: Twitter diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index 6e1f7d3..39e1561 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -13,6 +13,7 @@ Reddit +Hacker News Share URLs: Twitter From c495a3ac700e66effadef60e4dc424ab88a83549 Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Thu, 10 Sep 2015 08:28:55 -0400 Subject: [PATCH 09/10] Add docs for hacker_news_share_link --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 52b8f09..7245ce1 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,31 @@ The share button will open a new page with a pre-filled Reddit submission form with a title derived from the `share_title` or page/post specific `reddit_share_title` configuration discussed above. +## Hacker News + +Configure this plugin in your site's `_config.yml`. No configurations are required. Here are the configuration defaults. + +```yaml +hacker_news: + share_link_text: Hacker News # Configure the link text + share_link_title: Share on Hacker News # Title of the share link + share_title: :title - :url # The suggested title auto-filled in the Hacker News form +``` + +To include a custom auto-filled share title for a post or page, include a +`hacker_news_share_title` attribute in the frontmatter of the post/page like this: + +```yaml +hacker_news_share_title: "Totally not click bait! :title - :url" +``` + +### Hacker News Tags + +Sharing tags: +``` +{% hacker_news_share_link %} # Share with a (no js) link +``` + ## Email sharing Add convenient `mail:to` links which which helps readers From 18a8b8120631b7a5bc93908257bb0cde576e008a Mon Sep 17 00:00:00 2001 From: Danny Guinther Date: Thu, 10 Sep 2015 07:46:00 -0400 Subject: [PATCH 10/10] Add hacker_news_share_url tag --- README.md | 1 + lib/octopress-social.rb | 1 + test/site/_expected/post-loop.html | 1 + test/site/_expected/share-page.html | 1 + test/site/_expected/share-post/index.html | 1 + test/site/_includes/share.html | 1 + test/site/_site/post-loop.html | 1 + test/site/_site/share-page.html | 1 + test/site/_site/share-post/index.html | 1 + 9 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 7245ce1..0366fb6 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,7 @@ hacker_news_share_title: "Totally not click bait! :title - :url" Sharing tags: ``` {% hacker_news_share_link %} # Share with a (no js) link +{% hacker_news_share_url %} # URL to share with a (no js) link. URL only, no additional HTML markup included. ``` ## Email sharing diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 47e6c7f..a9b467e 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -71,6 +71,7 @@ def item(context, input) Liquid::Template.register_tag('reddit_share_link', Octopress::Social::Reddit::Tag) Liquid::Template.register_tag('reddit_share_url', Octopress::Social::Reddit::Tag) Liquid::Template.register_tag('hacker_news_share_link', Octopress::Social::HackerNews::Tag) +Liquid::Template.register_tag('hacker_news_share_url', Octopress::Social::HackerNews::Tag) if defined? Octopress::Docs Octopress::Docs.add({ diff --git a/test/site/_expected/post-loop.html b/test/site/_expected/post-loop.html index a1a5c0b..818c510 100644 --- a/test/site/_expected/post-loop.html +++ b/test/site/_expected/post-loop.html @@ -23,6 +23,7 @@

Share post

Facebook Email Reddit +Hacker News Comment links: Comments diff --git a/test/site/_expected/share-page.html b/test/site/_expected/share-page.html index be3927f..21ee260 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -21,6 +21,7 @@ Facebook Email Reddit +Hacker News Comment links: Comments diff --git a/test/site/_expected/share-post/index.html b/test/site/_expected/share-post/index.html index 39e1561..cce6034 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -21,6 +21,7 @@ Facebook Email Reddit +Hacker News Comment links: Comments diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index cded9f1..a62694f 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -19,3 +19,4 @@ Facebook Email Reddit +Hacker News diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index a1a5c0b..818c510 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -23,6 +23,7 @@

Share post

Facebook Email Reddit +Hacker News Comment links: Comments diff --git a/test/site/_site/share-page.html b/test/site/_site/share-page.html index be3927f..21ee260 100644 --- a/test/site/_site/share-page.html +++ b/test/site/_site/share-page.html @@ -21,6 +21,7 @@ Facebook Email Reddit +Hacker News Comment links: Comments diff --git a/test/site/_site/share-post/index.html b/test/site/_site/share-post/index.html index 39e1561..cce6034 100644 --- a/test/site/_site/share-post/index.html +++ b/test/site/_site/share-post/index.html @@ -21,6 +21,7 @@ Facebook Email Reddit +Hacker News Comment links: Comments