octopress-social 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ad8a7ece7e30fbc6fce89ea3753d9eaf13355c8
4
- data.tar.gz: b4f122dce2d3e6ea8648372350925946a809dcd2
3
+ metadata.gz: fc69b51e6a1d4ccc410094fede2aee2d4d6af2a7
4
+ data.tar.gz: 909c4cb057c933360f3e35781217685f8e976b66
5
5
  SHA512:
6
- metadata.gz: 984ee78928c0d0c68bda2eb965364fdc0e27c4b6ba38413ee6cfd3e047cd5dfb27755dac7d0145ddf57b0fc3327d242b4303dd084287c88b9304c0495f5a50ea
7
- data.tar.gz: 9f7234ac4585cfbecffc5a8ce6ceb0b8b7125e6b08393a6c28e9a0215c9b3bba222cac7e8a4c2fabd9f83aa7d072a8c995c92849c894b630fbabdd7333214762
6
+ metadata.gz: 6715d8246cc3b68020c5b9697625515a112317d71d0ff74826996596884778286b7c4b0d61f8e2c6593ff86caf876584841370333793ae4b09153d6d68886a06
7
+ data.tar.gz: 59df88675057d14007087997e82dcfeccd22530a94559a26c58f6a65b5a2bab41a070812ade795c91d357ad5d9a16c0df3f3d4f99f266afd69da68c1694d3f8a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.2.0 (2015-03-18)
4
+ - New: Added Disqus comments link tag.
5
+ - New: Facebook comments link tag.
6
+ - New: Tags auto-detect context (sharing a post or the current page).
7
+ - Fixed: Hashtags are added on tweet link.
8
+
3
9
  ### 1.1.0 (2015-03-17)
4
10
  - New: Added support Disqus comments.
5
11
  - New: Disable Facebook comments on any page or post with `comments: false`.
data/README.md CHANGED
@@ -27,19 +27,28 @@ Then add the gem to your Jekyll configuration.
27
27
  gems:
28
28
  - octopress-social
29
29
 
30
+ ## Basics
31
+
32
+ To integrate these social services, you'll need to add some minimal configurations;
33
+ usually just a username or user id.
34
+
35
+ All tags respond to context. For example, in a post loop, `{% tweet_button %}` will
36
+ automatically point to the current post. Used outside of a post loop, tags will refer to the current page.
37
+
30
38
  ## Twitter
31
39
 
32
- Configure this plugin in your site's `_config.yml`.
40
+ Configure this plugin in your site's `_config.yml`. You really only need to configure
41
+ `username`, but these are the defaults
33
42
 
34
43
  ```yaml
35
44
  twitter:
36
45
  username: # Add your Twitter handle
37
- tweet_count: false # show number of shares on Twitter
38
- size: normal # or large
46
+ tweet_count: false # Show number of shares on Twitter
47
+ size: normal # Or large
39
48
  tweet_link_text: Twitter # Configure the link text
40
- tweet_message: ":title by :username - :url :hashtags"
49
+ tweet_message: ":title by :username :hashtags - :url" # With Tweet button Twitter add the URL last
41
50
 
42
- follow_count: false # show number of followers
51
+ follow_count: false # Show number of followers
43
52
  profile_link_text: "Follow :username"
44
53
  ```
45
54
 
@@ -80,11 +89,10 @@ To use Twitter's fancy buttons you'll need to add this tag to your site's layout
80
89
  Sharing tags:
81
90
  ```
82
91
  {% tweet_button %}
83
- {% tweet_button post %}
84
- {% tweet_link %} # tweet with a (no js) link
92
+ {% tweet_link %} # Tweet with a (no js) link
85
93
  ```
86
94
 
87
- 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`. If you want tweet buttons to show up on post index or archive pages, add the `post` argument to the tweet button tag.
95
+ 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`.
88
96
 
89
97
  Follow tags:
90
98
 
@@ -97,6 +105,13 @@ Follow tags:
97
105
 
98
106
  Configure this plugin in your site's `_config.yml`.
99
107
 
108
+ You don't need to configure anything to start using this plugin but if you want to
109
+ use the follow button or profile link, you'll need to add your `profile_id`.
110
+
111
+ To get your `profile_id`, take a section from the url to your profile page `https://www.facebook.com/[profile_id]`.
112
+
113
+ Here are the defaults:
114
+
100
115
  ```yaml
101
116
  facebook:
102
117
  app_id: # For a nicer (no js) sharing experience
@@ -107,16 +122,22 @@ facebook:
107
122
  show_faces: false
108
123
  colorscheme: light # Or dark
109
124
  kid_directed_site: false # Is your site directed at kids under 13?
125
+
110
126
  share_link_text: Facebook # Text for plain-old link
111
127
  profile_link_text: "Find me on Facebook"
128
+
112
129
  comment_count: 5 # Number of facebook comments to show by default
130
+ comments_link_text: Comments
131
+ disabled_comments_text: Comments disabled # Set to '' to output nothing when comments are disabled
113
132
  ```
114
133
 
115
134
  These configurations are all based on [Facebook's widget configuration spec](https://developers.facebook.com/docs/plugins/), visit that site for more info.
116
135
 
117
- To get your `profile_id`, take a section from the url to your profile page `https://www.facebook.com/[profile_id]`.
118
136
 
119
- To get an `app_id` you'll need to [register](https://developers.facebook.com/apps) as a developer and go through the process to create an
137
+ ### Facebook APP ID
138
+
139
+ If you want to use the fancy share link (lets you set default content for the share),
140
+ you'll need to get an `app_id`. For that you'll have to [register](https://developers.facebook.com/apps) as a developer and go through the process to create an
120
141
  'app'. This is free and it doesn't mean you're developing software or anything, it's just how Facebook wants to do this. Once you've
121
142
  created an app, go to the "Basic settings page" by clicking settings, and then finding the "Basic" link. There you should be able to find
122
143
  your App ID.
@@ -148,6 +169,7 @@ Embed Facebook comments widget:
148
169
 
149
170
  ```
150
171
  {% facebook_comments %}
172
+ {% facebook_comments_link %} # Add a link that jumps right to your comments section.
151
173
  ```
152
174
 
153
175
  ## Google+
@@ -180,7 +202,7 @@ Sharing tags:
180
202
  ```
181
203
  {% gplus_one_button %}
182
204
  {% gplus_share_button %}
183
- {% gplus_share_link %} # share with a (no js) link
205
+ {% gplus_share_link %} # Share with a (no js) link
184
206
  ```
185
207
 
186
208
  Follow tags:
@@ -195,7 +217,10 @@ Follow tags:
195
217
  Configure this plugin in your site's `_config.yml` and optionally on each page or post.
196
218
 
197
219
  ```yaml
198
- disqus_shortname: # Your site's disqus identifier
220
+ disqus:
221
+ shortname: # Your site's disqus identifier
222
+ comments_link_text: Comments # Text label for comments link
223
+ comments_disabled_link_text: Comments disabled # Set to '' to not output a comments link when disabled
199
224
  ```
200
225
 
201
226
  In any page or post, you can add these configurations to the YAML front-matter.
@@ -206,32 +231,16 @@ disqus_title: # Custom title for comments metadata (defaults to page/po
206
231
  comments: false # Disable comments for this page or post
207
232
  ```
208
233
 
209
- ### Tags
234
+ ### Disqus Tags
210
235
 
211
236
  These tags will help you integrate Disqus comments into your site.
212
237
 
213
238
  ```
214
- {% disqus_comments %} # Embed comments on a page
215
- ```
216
-
217
- If you want to link directly to the comments section of a post or page, create a link like this:
218
-
219
- ```
220
- {% disqus_comments_link %} # link to the comments section on the current page
221
- {% disqus_comments_link post %} # link to the comments section on a post (in the posts loop)
239
+ {% disqus_comments %} # Embed comments on a page
240
+ {% disqus_comments_link %} # Add a link that jumps right to your comments section.
222
241
  ```
223
242
 
224
- This will generate a link to the page or post with the on page anchor `#disqus_thread` added, linking you directly to the comments
225
- section.
226
-
227
- If you want to show the number of comments in the link, add the following tag to your page layout, somewhere before `</body>`.
228
-
229
- ```
230
- {% disqus_count_script %} # Add script for adding counts to comment links
231
- ```
232
-
233
- This tag will find all comments links on the current page and add the comment count. You can configure this link text from your the admin panel on Disqus's site.
234
-
243
+ Disqus has a script that lets you add comment count to the link, but it's so buggy, I'm not including it because I don't want to deal with the support. You can still add it to your site manually.
235
244
 
236
245
  ## Contributing
237
246
 
@@ -3,49 +3,64 @@ module Octopress
3
3
  module Disqus
4
4
  extend self
5
5
 
6
- def config(site=nil)
7
- @config ||= site['disqus_shortname']
6
+ attr_accessor :url, :config
7
+
8
+ DEFAULTS = {
9
+ 'comments_link_text' => 'Comments',
10
+ 'disabled_comments_text' => 'Comments disabled'
11
+ }
12
+
13
+ def set_config(site)
14
+ @config ||= DEFAULTS.merge(site['disqus'] || {})
8
15
  end
9
16
 
10
- def url(site, item)
11
- Social.full_url(site, item)
17
+ def set_url(site, item)
18
+ @url = Social.full_url(site, item)
12
19
  end
13
20
 
14
21
  def identifier(site, item)
15
- item['disqus_identifier'] || url(site, item)
22
+ item['disqus_identifier'] || url
16
23
  end
17
24
 
18
25
  def disqus_comments(site, item)
19
- %Q{<div id="disqus_thread"></div>
20
- <script type="text/javascript">
21
- var disqus_shortname = '#{config}';
22
- var disqus_url = '#{url(site, item)}';
23
- var disqus_identifier = '#{identifier(site, item)}';
24
- var disqus_title = '#{item['title']}';
25
- #{embed_script('embed')}
26
- </script>
27
- <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
28
- }
29
- end
30
-
31
- def disqus_count_script(site, item)
32
- %Q{<script type="text/javascript">
33
- var disqus_shortname = '#{config}';
34
- #{embed_script('count')}
35
- </script>
36
- }
26
+ if item['comments'] != false
27
+ %Q{<div id="disqus_thread"></div>
28
+ <script type="text/javascript">
29
+ var disqus_shortname = '#{config['shortname']}';
30
+ var disqus_url = '#{url}';
31
+ var disqus_identifier = '#{identifier(site, item)}';
32
+ var disqus_title = '#{item['title']}';
33
+ #{embed_script('embed')}
34
+ </script>
35
+ <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
36
+ }
37
+ else
38
+ ''
39
+ end
37
40
  end
38
41
 
39
42
  def embed_script(script)
40
43
  %Q{(function () {
41
44
  var s = document.createElement('script'); s.async = true;
42
45
  s.type = 'text/javascript';
43
- s.src = '//#{config}.disqus.com/#{script}.js';
46
+ s.src = '//#{config['shortname']}.disqus.com/#{script}.js';
44
47
  (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
45
48
  }());
46
49
  }
47
50
  end
48
51
 
52
+ def disqus_comments_link(site, item)
53
+ if item['comments'] != false
54
+ link = (item['context'] == 'page' ? '' : url)
55
+ link << '#disqus_thread'
56
+ %Q{<a class="disqus-comments-link" href="#{link}">Comments</a>}
57
+ elsif !config['disabled_comments_text'].empty?
58
+ %Q{<span class="disqus-comments-disabled">#{config['disabled_comments_text']}</span>}
59
+ else
60
+ ''
61
+ end
62
+ end
63
+
49
64
  class Tag < Liquid::Tag
50
65
  def initialize(tag, input, tokens)
51
66
  @tag = tag.strip
@@ -53,13 +68,12 @@ module Octopress
53
68
  end
54
69
 
55
70
  def render(context)
56
- item = context[@input] || context['page']
57
- site = context['site']
71
+ site = context['site']
72
+ item = Octopress::Social.item(context, @input)
58
73
 
59
- config = Octopress::Social::Disqus.config(site)
60
- if config && item['comments'] != false
61
- Octopress::Social::Disqus.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip
62
- end
74
+ Octopress::Social::Disqus.set_config(site)
75
+ Octopress::Social::Disqus.set_url(site, item)
76
+ Octopress::Social::Disqus.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip
63
77
  end
64
78
  end
65
79
  end
@@ -3,6 +3,8 @@ module Octopress
3
3
  module Facebook
4
4
  extend self
5
5
 
6
+ attr_accessor :url, :config
7
+
6
8
  DEFAULTS = {
7
9
  'profile_id' => nil,
8
10
  'app_id' => nil,
@@ -14,15 +16,20 @@ module Octopress
14
16
  'kid_directed_site' => false,
15
17
  'comment_count' => 5,
16
18
  'share_link_text' => 'Facebook',
17
- 'profile_link_text' => 'Friend me on Facebook'
19
+ 'profile_link_text' => 'Friend me on Facebook',
20
+ 'comments_link_text' => 'Comments',
21
+ 'disabled_comments_text' => 'Comments disabled'
18
22
  }
19
23
 
20
- def config(site=nil)
24
+ def set_config(site)
21
25
  @config ||= DEFAULTS.merge(site['facebook'] || {})
22
26
  end
23
27
 
28
+ def set_url(site, item)
29
+ @url = Social.full_url(site, item)
30
+ end
31
+
24
32
  def facebook_share_link(site, item)
25
- url = Social.full_url(site, item)
26
33
  if config['app_id']
27
34
  %Q{<a class="facebook-share-link" href="https://www.facebook.com/dialog/share?
28
35
  app_id=#{config['app_id']}
@@ -38,7 +45,7 @@ module Octopress
38
45
 
39
46
  def facebook_like_button(site, item)
40
47
  %Q{<div class="fb-like"
41
- data-href="#{Social.full_url(site, item)}"
48
+ data-href="#{url}"
42
49
  #{width}
43
50
  data-layout="#{config['layout']}"
44
51
  data-action="#{config['action']}"
@@ -66,7 +73,7 @@ module Octopress
66
73
 
67
74
  def facebook_send_button(site, item)
68
75
  %Q{<div class="fb-send"
69
- data-href="#{Social.full_url(site, item)}"
76
+ data-href="#{url}"
70
77
  #{width}
71
78
  data-colorscheme="#{config['colorscheme']}"
72
79
  data-kid-directed-site="#{config['kid_directed_site']}"></div>
@@ -96,8 +103,8 @@ module Octopress
96
103
 
97
104
  def facebook_comments(site, item)
98
105
  if item['comments'] != false
99
- %Q{<div class="fb-comments"
100
- data-href="#{Social.full_url(site, item)}"
106
+ %Q{<div class="fb-comments" id="facebook_comments"
107
+ data-href="#{url}"
101
108
  data-numposts="#{config['comment_count']}"
102
109
  data-colorscheme="#{config['colorscheme']}"
103
110
  ></div>}
@@ -106,6 +113,18 @@ module Octopress
106
113
  end
107
114
  end
108
115
 
116
+ def facebook_comments_link(site, item)
117
+ if item['comments'] != false
118
+ link = (item['context'] == 'page' ? '' : url)
119
+ link << '#facebook_comments'
120
+ %Q{<a class="facebook-comments-link" href="#{link}">Comments</a>}
121
+ elsif !config['disabled_comments_text'].empty?
122
+ %Q{<span class="facebook-comments-disabled">#{config['disabled_comments_text']}</span>}
123
+ else
124
+ ''
125
+ end
126
+ end
127
+
109
128
  class Tag < Liquid::Tag
110
129
  def initialize(tag, input, tokens)
111
130
  @tag = tag.strip
@@ -113,10 +132,11 @@ module Octopress
113
132
  end
114
133
 
115
134
  def render(context)
116
- item = context[@input] || context['page']
135
+ item = Octopress::Social.item(context, @input)
117
136
  site = context['site']
118
137
 
119
- Octopress::Social::Facebook.config(site)
138
+ Octopress::Social::Facebook.set_url(site, item)
139
+ Octopress::Social::Facebook.set_config(site)
120
140
  Octopress::Social::Facebook.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip
121
141
  end
122
142
  end
@@ -89,7 +89,7 @@ module Octopress
89
89
  end
90
90
 
91
91
  def render(context)
92
- item = context[@input] || context['page']
92
+ item = Octopress::Social.item(context, @input)
93
93
  site = context['site']
94
94
 
95
95
  Octopress::Social::GooglePlus.config(site)
@@ -3,8 +3,10 @@ module Octopress
3
3
  module Twitter
4
4
  extend self
5
5
 
6
+ attr_accessor :url, :config
7
+
6
8
  DEFAULTS = {
7
- 'tweet_message' => ":title by :username - :url :hashtags",
9
+ 'tweet_message' => ":title by :username :hashtags - :url",
8
10
  'size' => 'normal',
9
11
  'tweet_count' => false,
10
12
  'follow_count' => false,
@@ -12,12 +14,16 @@ module Octopress
12
14
  'profile_link_text' => "Follow :username"
13
15
  }
14
16
 
15
- def config(site=nil)
16
- @config ||= DEFAULTS.merge(site['twitter'] || {})
17
+ def set_config(site)
18
+ @config = DEFAULTS.merge(site['twitter'] || {})
19
+ end
20
+
21
+ def set_url(site, item)
22
+ @url = Social.full_url(site, item)
17
23
  end
18
24
 
19
25
  def tweet_link(site, item)
20
- %Q{<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=#{message(site, item).strip}" target="_blank">#{config['tweet_link_text']}</a>}
26
+ %Q{<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=#{message(site, item).strip.gsub('#', '%23')}" target="_blank">#{config['tweet_link_text']}</a>}
21
27
  end
22
28
 
23
29
  def tweet_button(site, item)
@@ -25,7 +31,7 @@ module Octopress
25
31
  <a href="https://twitter.com/share" class="twitter-share-button"
26
32
  #{'data-size="large"' if config['size'] == 'large'}
27
33
  #{'data-count="none"' if !config['tweet_count']}
28
- #{button_message(site, item)}
34
+ #{button_message(site, item).sub(/\s?#{url}/, '')}
29
35
  data-dnt="true">#{config['tweet_link_text']}</a>
30
36
  }
31
37
  end
@@ -48,7 +54,7 @@ module Octopress
48
54
  (item['tweet_message'] || config['tweet_message'])
49
55
  .sub(':title', item['title'] || '')
50
56
  .sub(':username', username(item))
51
- .sub(':url', Social.full_url(site, item))
57
+ .sub(':url', url)
52
58
  .sub(':hashtags', hashtags(item))
53
59
  .strip
54
60
  end
@@ -83,10 +89,11 @@ module Octopress
83
89
  end
84
90
 
85
91
  def render(context)
86
- item = context[@input] || context['page']
92
+ item = Octopress::Social.item(context, @input)
87
93
  site = context['site']
88
94
 
89
- Octopress::Social::Twitter.config(site)
95
+ Octopress::Social::Twitter.set_config(site)
96
+ Octopress::Social::Twitter.set_url(site, item)
90
97
  Octopress::Social::Twitter.send(@tag, site, item).gsub(/(\s{2,}|\n)/, ' ').strip
91
98
  end
92
99
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Social
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -17,6 +17,19 @@ module Octopress
17
17
 
18
18
  File.join(root, site['baseurl'], item['url'].sub('index.html', ''))
19
19
  end
20
+
21
+ def item(context, input)
22
+ if item = context[input]
23
+ item['context'] = input
24
+ elsif item = context['post']
25
+ item['context'] = 'post'
26
+ else
27
+ item = context['page']
28
+ item['context'] = 'page'
29
+ end
30
+
31
+ item
32
+ end
20
33
  end
21
34
  end
22
35
 
@@ -37,9 +50,9 @@ Liquid::Template.register_tag('facebook_send_button', Octopress::Social::Faceboo
37
50
  Liquid::Template.register_tag('facebook_follow_button', Octopress::Social::Facebook::Tag)
38
51
  Liquid::Template.register_tag('facebook_profile_link', Octopress::Social::Facebook::Tag)
39
52
  Liquid::Template.register_tag('facebook_comments', Octopress::Social::Facebook::Tag)
53
+ Liquid::Template.register_tag('facebook_comments_link', Octopress::Social::Facebook::Tag)
40
54
  Liquid::Template.register_tag('facebook_script_tag', Octopress::Social::Facebook::Tag)
41
55
  Liquid::Template.register_tag('disqus_comments', Octopress::Social::Disqus::Tag)
42
- Liquid::Template.register_tag('disqus_count_script', Octopress::Social::Disqus::Tag)
43
56
  Liquid::Template.register_tag('disqus_comments_link', Octopress::Social::Disqus::Tag)
44
57
 
45
58
  if defined? Octopress::Docs
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-social
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis