diff --git a/README.md b/README.md index 286b856..0366fb6 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: @@ -234,6 +237,62 @@ 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 +{% 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 +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 +{% hacker_news_share_url %} # URL to share with a (no js) link. URL only, no additional HTML markup included. +``` + ## Email sharing Add convenient `mail:to` links which which helps readers @@ -259,7 +318,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 diff --git a/lib/octopress-social.rb b/lib/octopress-social.rb index 0e20be9..a9b467e 100644 --- a/lib/octopress-social.rb +++ b/lib/octopress-social.rb @@ -13,7 +13,9 @@ module Social autoload :Disqus, 'octopress-social/disqus' 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'] abort "Site url not configured. Please set url: http://your-site.com in Jekyll configuration file." @@ -40,17 +42,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,8 +65,13 @@ 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) +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/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) + encoded_url = ERB::Util.url_encode(url) if config['app_id'] - %Q{#{config['share_link_text']} - } + "https://www.facebook.com/dialog/share?". + concat("app_id=#{config['app_id']}"). + concat("&href=#{encoded_url}&redirect_uri=#{encoded_url}") else - %Q{#{config['share_link_text']}} + "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 0ce8253..68ef1ef 100644 --- a/lib/octopress-social/google-plus.rb +++ b/lib/octopress-social/google-plus.rb @@ -30,12 +30,18 @@ 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) + encoded_url = ERB::Util.url_encode(url) + "https://plus.google.com/share?url=#{encoded_url}" + end + def gplus_one_button(site, item) %Q{
} end 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/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/lib/octopress-social/twitter.rb b/lib/octopress-social/twitter.rb index 3f386eb..86fae14 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 Share Links: -Twitter -Google+ -Facebook +Twitter +Google+ +Facebook Email +Reddit +Hacker News + +Share URLs: +Twitter +Google+ +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 20dea0d..21ee260 100644 --- a/test/site/_expected/share-page.html +++ b/test/site/_expected/share-page.html @@ -8,10 +8,20 @@ Share Links: -Twitter -Google+ -Facebook +Twitter +Google+ +Facebook Email +Reddit +Hacker News + +Share URLs: +Twitter +Google+ +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 d24eb48..cce6034 100644 --- a/test/site/_expected/share-post/index.html +++ b/test/site/_expected/share-post/index.html @@ -8,10 +8,20 @@ Share Links: -Twitter -Google+ -Facebook +Twitter +Google+ +Facebook Email +Reddit +Hacker News + +Share URLs: +Twitter +Google+ +Facebook +Email +Reddit +Hacker News Comment links: Comments diff --git a/test/site/_includes/share.html b/test/site/_includes/share.html index e7a2f57..a62694f 100644 --- a/test/site/_includes/share.html +++ b/test/site/_includes/share.html @@ -10,3 +10,13 @@ {% gplus_share_link %} {% facebook_share_link %} {% email_share_link %} +{% reddit_share_link %} +{% hacker_news_share_link %} + +Share URLs: +Twitter +Google+ +Facebook +Email +Reddit +Hacker News diff --git a/test/site/_site/post-loop.html b/test/site/_site/post-loop.html index ccaa827..818c510 100644 --- a/test/site/_site/post-loop.html +++ b/test/site/_site/post-loop.html @@ -10,10 +10,20 @@