Skip to content
This repository has been archived by the owner on Jun 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #735 from cfpb/updating_meta_description
Browse files Browse the repository at this point in the history
Fixes for meta tags and social icons
  • Loading branch information
sebworks authored Sep 11, 2017
2 parents 7bf7612 + 2b0099d commit f3022d6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 43 deletions.
16 changes: 16 additions & 0 deletions src/_layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@
<link rel="apple-touch-icon" size="144x144" href="http://www.consumerfinance.gov/wp-content/themes/cfpb_nemo/_/img/apple-touch-icon-144x144-precomposed.png">

<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}?v7">
<!-- Open Graph properties -->
<!-- Required -->
<meta property="og:title" content="{% block og_title %}{{ self.title() }}{% endblock %}">
<meta property="og:type" content="{% block og_type %}website{% endblock %}">
<meta property="og:url" content="{{ request.url }}">
<meta property="og:image"
content="{{ request.scheme }}://{{ request.get_host() }}{{ static('img/logo_open-graph_facebook.png') }}">
<meta property="twitter:image"
content="{{ request.scheme }}://{{ request.get_host() }}{{ static('img/logo_open-graph_twitter.png') }}">

<!-- Optional -->
<meta property="og:description" content="{{ self.metadescription() }}">
<meta property="og:site_name" content="Consumer Financial Protection Bureau">
<!-- Facebook -->
<meta property="fb:app_id" content="210516218981921">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>if (!window.jQuery) {
document.write('<script src="{{ url_for('static', filename='js/jquery.min.js') }}"><\/script>');
Expand Down
80 changes: 37 additions & 43 deletions src/_layouts/social-media.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@
value.is_share_view: Whether the "Share this" heading is shown.
Default is true.

value.email_title Sets subject for email

value.email_text Sets body for email

value.email_signature Sets signature for email

value.linkedin_title Sets title for LinkedIn post

value.linkedin_text Sets text for LinkedIn post

value.twitter_text: Sets content for tweet

value.twitter_hashtags: A comma-separated list of hashtags
to be appended to default Tweet text.
https://dev.twitter.com/web/tweet-button/parameters
Expand All @@ -30,66 +42,51 @@
if other than English.
https://dev.twitter.com/web/tweet-button/parameters

value.twitter_text: (Optional) content for tweet

value.linkedin_title (Optional) title for LinkedIn post

value.linkedin_text (Optional) text for LinkedIn post

value.email_title (Optional) subject for email

value.email_text (Optional) body for email

value.email_signature (Optional) signature for email

========================================================================== #}

{% macro render( value={} ) %}

{% set blurb = (value.blurb or (page.seo_title if page) or value.title or
'Look what I found on the CFPB’s site!') | urlencode %}

{% set twitter_text = value.twitter_text | urlencode or blurb %}
{% set linkedin_title = value.linkedin_title | urlencode or blurb %}
{% set linkedin_text = value.linkedin_text | urlencode or blurb %}
{% set parsed_url = request.url | urlencode %}
{% set is_share_view = value.is_share_view | default( true ) %}
{% set email_title = value.email_title | urlencode or blurb %}
{% set email_text = value.email_text | urlencode or blurb %}
{% set email_text = value.email_text | urlencode or 'Check out this page from the CFPB - ' %}
{% set email_signature = '%0A%0A' + value.email_signature | urlencode if value.email_signature else '' %}
{% set linkedin_title = value.linkedin_title | urlencode or blurb %}
{% set linkedin_text = value.linkedin_text | urlencode or '' %}
{% set twitter_text = value.twitter_text | urlencode or blurb %}


{% set parsed_url = request.url | urlencode %}
{% set external_redirect_url = '/external-site/?ext_url=' %}
{% set is_share_view = value.is_share_view | default( true ) %}
<div class="m-social-media
m-social-media__{{ 'share' if is_share_view else 'follow' }}">
{% if is_share_view %}
<div class="h5 m-social-media_heading">Share this</div>
<div class="h5 m-social-media_heading m-social-media_heading__es">Compartir este</div>
<div class="h5 m-social-media_heading m-social-media_heading__es">Compartir</div>
{% endif %}

<ul class="list
list__unstyled
list__horizontal
<ul class="m-list
m-list__unstyled
m-list__horizontal
m-social-media_icons">

{% set facebook_info = {
'name': 'Facebook',
'homepage': 'https://facebook.com/cfpb',
'share_url': 'https://www.facebook.com/dialog/share?app_id=210516218981921&display=page&href=' ~ parsed_url ~ '&redirect_uri=' ~ parsed_url,
'homepage': unsigned_redirect('https://facebook.com/cfpb'),
'share_url': signed_redirect('https://www.facebook.com/dialog/share?app_id=210516218981921&display=page&href=' ~ parsed_url ~ '&redirect_uri=' ~ parsed_url),
'class': 'cf-icon-facebook-square'
} %}

{% set twitter_info = {
'name': 'Twitter',
'homepage': 'https://twitter.com/cfpb',
'share_url': _share_twitter_url(parsed_url, twitter_text, value),
'homepage': unsigned_redirect('https://twitter.com/cfpb'),
'share_url': signed_redirect(_share_twitter_url(parsed_url, twitter_text, value)|trim),
'class': 'cf-icon-twitter-square'
} %}

{% set linkedin_info = {
'name': 'LinkedIn',
'homepage': 'https://www.linkedin.com/company/consumer-financial-protection-bureau',
'share_url': 'https://www.linkedin.com/shareArticle?mini=true&url=' ~ parsed_url ~ '&title=' ~ linkedin_title ~ '&summary=' ~ linkedin_text,
'homepage': unsigned_redirect('https://www.linkedin.com/company/consumer-financial-protection-bureau'),
'share_url': signed_redirect('https://www.linkedin.com/shareArticle?mini=true&url=' ~ parsed_url ~ '&title=' ~ linkedin_title ~ '&summary=' ~ linkedin_text),
'class': 'cf-icon-linkedin-square'
} %}

Expand All @@ -101,13 +98,13 @@

{% set youtube_info = {
'name': 'YouTube',
'homepage': 'https://www.youtube.com/user/cfpbvideo',
'homepage': unsigned_redirect('https://www.youtube.com/user/cfpbvideo'),
'class': 'cf-icon-youtube-square'
} %}

{% set flickr_info = {
'name': 'Flickr',
'homepage': 'https://www.flickr.com/photos/cfpbphotos',
'homepage': unsigned_redirect('https://www.flickr.com/photos/cfpbphotos'),
'class': 'cf-icon-flickr-square'
} %}

Expand All @@ -131,19 +128,18 @@

{% for link in links %}
{% if is_share_view %}
<li class="list_item">
<li class="m-list_item">
<a class="m-social-media_icon"
href="{{ external_redirect_url ~ link.share_url if link.name != 'email'
else link.share_url | trim }}"
href="{{ link.share_url if link.name != 'email' else link.share_url | trim }}"
{{ 'target=_blank' if link.name != 'email' else '' }}>
<span class="cf-icon {{ link.class }}"></span>
<span class="u-visually-hidden">Share on {{ link.name }}</span>
</a>
</li>
{% else %}
<li class="list_item">
<li class="m-list_item">
<a class="m-social-media_icon"
href="{{ external_redirect_url ~ link.homepage | trim }}">
href="{{ link.homepage | trim }}">
<span class="cf-icon {{ link.class }}"></span>
<span class="u-visually-hidden">Visit us on {{ link.name }}</span>
</a>
Expand Down Expand Up @@ -186,14 +182,14 @@

========================================================================== #}

{% macro _share_twitter_url(parsed_url, blurb, options) %}
{%- macro _share_twitter_url(parsed_url, blurb, options) -%}
{%- set _share_twitter_url = 'http://twitter.com/intent/tweet' -%}
{%- set _share_twitter_url = _share_twitter_url + '?url=' + parsed_url -%}
{%- set _share_twitter_url = _share_twitter_url + '&via=CFPB' -%}
{%- set _share_twitter_url = _share_twitter_url + '&text=' + blurb + '%20--' -%}

{%- if options.twitter_hashtags %}
{% set _share_twitter_url = _share_twitter_url + '&hashtags=' + options.twitter_hashtags %}
{% set _share_twitter_url = _share_twitter_url + '&hashtags=' + options.twitter_hashtags.replace('#','')|urlencode %}
{% endif -%}

{%- if options.twitter_related %}
Expand All @@ -204,7 +200,5 @@

{%- if options.twitter_lang %}
{% set _share_twitter_url = _share_twitter_url + '&lang=' + options.twitter_lang %}
{% endif -%}

{{ _share_twitter_url }}
{% endif -%}{{- _share_twitter_url -}}
{% endmacro %}

0 comments on commit f3022d6

Please sign in to comment.