Skip to content

Commit

Permalink
Fix linkedin share button
Browse files Browse the repository at this point in the history
  • Loading branch information
fcurella committed Aug 4, 2020
1 parent c573732 commit 1d5b948
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
10 changes: 2 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Usage
{% post_to_twitter <text_to_post> <object_or_url> <link_text> %}
{% post_to_linkedin <subject> <object_or_url> <link_text> %}
{% post_to_linkedin <object_or_url> %}
{% send_email <subject> <text_to_post> <object_or_url> <link_text> %}
Expand Down Expand Up @@ -95,12 +95,6 @@ Will add a ``facebook_url`` variable to the context, containing the URL for the

Will add a ``gplus_url`` variable to the context, containing the URL for the Google+ sharer popup.

::

{% post_to_linkedin_url <subject> <object_or_url> %}

Will add a ``linkedin_url`` variable to the context, containing the URL for the LinkedIn sharer popup.

::

{% send_email_url <subject> <text_to_post> <object_or_url> <link_text> %}
Expand Down Expand Up @@ -132,7 +126,7 @@ Example::
{% post_to_facebook object_or_url "Post to Facebook!" %}
{% post_to_twitter "New Song: {{object.title}}. Check it out!" object_or_url "Post to Twitter" %}
{% post_to_gplus object_or_url "Post to Google+!" %}
{% post_to_linkedin object.title object_or_url "Post to LinkedIn" %}
{% post_to_linkedin object_or_url %}
{% send_email object.title "New Song: {{object.title}}. Check it out!" object_or_url "Share via email" %}
{% post_to_reddit "New Song: {{object.title}}" <object_or_url> %}
{% post_to_telegram "New Song: {{object.title}}" <object_or_url> %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="linkedin-this">
<a href="{{ linkedin_url }}" target="_blank">{{link_text}}</a>
{% load i18n social_share %}{% get_current_language as LANGUAGE_CODE %}<div class="linkedin-this">
<script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: {{ LANGUAGE_CODE|linkedin_locale }}</script>
<script type="IN/Share" data-url="{{ linkedin_url }}"></script>
</div>
16 changes: 10 additions & 6 deletions django_social_share/templatetags/social_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,23 @@ def send_email(context, subject, text, obj_or_url=None, link_text='Share via ema
return context


@register.filter(name='linkedin_locale')
def linkedin_locale(value):
lang, country = value.split('-')
return '_'.join([lang, country.upper()])


@register.simple_tag(takes_context=True)
def post_to_linkedin_url(context, title, obj_or_url=None):
def post_to_linkedin_url(context, obj_or_url=None):
request = context['request']
title = compile_text(context, title[:200]) # 200 char limit
url = _build_url(request, obj_or_url)
context['linkedin_url'] = mark_safe(LINKEDIN_ENDPOINT % (urlencode(title), urlencode(url)))
context['linkedin_url'] = url
return context


@register.inclusion_tag('django_social_share/templatetags/post_to_linkedin.html', takes_context=True)
def post_to_linkedin(context, title, obj_or_url=None, link_text='Post to LinkedIn'):
context = post_to_linkedin_url(context, title, obj_or_url)
context['link_text'] = link_text
def post_to_linkedin(context, obj_or_url=None):
context = post_to_linkedin_url(context, obj_or_url)
return context


Expand Down
4 changes: 2 additions & 2 deletions django_social_share/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ def test_mail(self):
self.assertEqual(result, expected)

def test_linkedin(self):
template = Template("{% load social_share %} {% post_to_linkedin text url text %}")
template = Template("{% load social_share %} {% post_to_linkedin url %}")
result = template.render(self.context)
expected = ' <div class="linkedin-this">\n <a href="https://www.linkedin.com/shareArticle?mini=true&title=example&url=http%3A//example.com" target="_blank">example</a>\n</div>\n'
expected = ' <div class="linkedin-this">\n <script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: en_US</script>\n <script type="IN/Share" data-url="http://example.com"></script>\n</div>\n'
self.assertEqual(result, expected)

def test_reddit(self):
Expand Down

0 comments on commit 1d5b948

Please sign in to comment.