Skip to content

Commit

Permalink
Encode URLs shared via GPlus and Facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
tdg5 committed Sep 9, 2015
1 parent d8999cf commit f2c188b
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 27 deletions.
5 changes: 3 additions & 2 deletions lib/octopress-social/facebook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/octopress-social/google-plus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions test/site/_expected/post-loop.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ <h2>Share post</h2>

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-post/" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-post/">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Facebook</a>
<a href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Email</a>

Comment links:
Expand Down
8 changes: 4 additions & 4 deletions test/site/_expected/share-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Cool%20Page%20by%20%40imathis%20%23awesome%20%23stuff%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-page.html" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-page.html" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Cool%20Page%20by%20Guy%20McDude&body=Cool%20Page%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Cool%20Page%20by%20%40imathis%20%23awesome%20%23stuff%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-page.html">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-page.html">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Facebook</a>
<a href="mailto:?subject=Cool%20Page%20by%20Guy%20McDude&body=Cool%20Page%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Email</a>

Comment links:
Expand Down
8 changes: 4 additions & 4 deletions test/site/_expected/share-post/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-post/" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-post/">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Facebook</a>
<a href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Email</a>

Comment links:
Expand Down
8 changes: 4 additions & 4 deletions test/site/_site/post-loop.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ <h2>Share post</h2>

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-post/" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-post/">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Facebook</a>
<a href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Email</a>

Comment links:
Expand Down
8 changes: 4 additions & 4 deletions test/site/_site/share-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Cool%20Page%20by%20%40imathis%20%23awesome%20%23stuff%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-page.html" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-page.html" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Cool%20Page%20by%20Guy%20McDude&body=Cool%20Page%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Cool%20Page%20by%20%40imathis%20%23awesome%20%23stuff%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-page.html">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-page.html">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Facebook</a>
<a href="mailto:?subject=Cool%20Page%20by%20Guy%20McDude&body=Cool%20Page%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-page.html">Email</a>

Comment links:
Expand Down
8 changes: 4 additions & 4 deletions test/site/_site/share-post/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

Share Links:
<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Twitter">Twitter</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http://example.com/blog/share-post/" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/" title="Share on Facebook">Facebook</a>
<a class="g-plus-share-link" href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Google+">Google+</a>
<a class="facebook-share-link" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share on Facebook">Facebook</a>
<a class="email-share-link" href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F" title="Share via email">Email</a>

Share URLs:
<a href="https://twitter.com/intent/tweet?&text=Share%20post%20by%20%40octopress%20%23test%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Twitter</a>
<a href="https://plus.google.com/share?url=http://example.com/blog/share-post/">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http://example.com/blog/share-post/">Facebook</a>
<a href="https://plus.google.com/share?url=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Google+</a>
<a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Facebook</a>
<a href="mailto:?subject=Share%20post%20by%20Guy%20McDude&body=Share%20post%20by%20Guy%20McDude%20-%20http%3A%2F%2Fexample.com%2Fblog%2Fshare-post%2F">Email</a>

Comment links:
Expand Down

0 comments on commit f2c188b

Please sign in to comment.