Skip to content

Commit cd59de6

Browse files
authored
Merge pull request #3319 from Vizzuality/feature/rails-seo
Feature/rails seo
2 parents b332c1d + 57ee9e5 commit cd59de6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+218
-204
lines changed

app/controllers/about_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class AboutController < ApplicationController
2-
layout 'about'
2+
layout 'application_react'
33

44
def index
55
@title = 'About'
+4-49
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
class CountriesController < ApplicationController
2-
before_action :check_country_iso, only: :show
2+
before_action :set_country, only: :show
33

44
include ActionView::Helpers::NumberHelper
55

66
layout 'countries'
77

88
def index
9-
@countries = find_countries
9+
@countries = Country.find_all
1010
@title = 'Country Profiles'
1111
@desc = 'Explore country-specific statistics and graphs to see the how forests change and contribute to various sectors.'
1212
@keywords = 'GFW, list, forest data, visualization, data, national, country, analysis, statistic, tree cover loss, tree cover gain, climate domain, boreal, tropical, subtropical, temperate, deforestation, overview'
@@ -44,53 +44,8 @@ def overview
4444
end
4545

4646
private
47-
def find_countries
48-
response = Typhoeus.get("#{ENV['GFW_API_HOST']}/countries", headers: {"Accept" => "application/json"})
49-
if response.success?
50-
Rails.cache.fetch 'countries', expires_in: 1.day do
51-
JSON.parse(response.body)['countries']
52-
end
53-
else
54-
nil
55-
end
56-
end
57-
58-
def find_by_iso(iso)
59-
unless iso.blank?
60-
# CACHE: &bust=true if you want to flush the cache
61-
iso = iso.downcase
62-
response = Typhoeus.get(
63-
"#{ENV['GFW_API_HOST']}/countries/#{iso}?thresh=30",
64-
headers: {"Accept" => "application/json"}
65-
)
66-
if response.success? and (response.body.length > 0)
67-
JSON.parse(response.body)
68-
else
69-
nil
70-
end
71-
end
72-
end
73-
74-
def find_by_name(country_name)
75-
country_name, *_ = country_name.split(/_/)
76-
country_name = country_name.capitalize
77-
response = Typhoeus.get("https://wri-01.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20gfw2_countries%20where%20name%20like%20'#{country_name}%25'",
78-
headers: {"Accept" => "application/json"}
79-
)
80-
if response.success?
81-
JSON.parse(response.body)['rows'][0]
82-
else
83-
nil
84-
end
85-
end
8647

87-
def check_country_iso
88-
@country = find_by_iso(params[:id])
89-
unless @country.nil?
90-
@country
91-
else
92-
@country = find_by_name(params[:id])
93-
end
94-
@country
48+
def set_country
49+
@country = Country.find_by_iso_or_name(params[:id])
9550
end
9651
end

app/controllers/country_controller.rb

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
class CountryController < ApplicationController
22

3-
layout 'country'
3+
layout 'application_react'
4+
before_action :set_country, only: [:show]
45

5-
def index
6-
@desc = 'Data about forest change, tenure, forest related employment and land use'
6+
def show
7+
@title = @country["name"]
8+
@desc = "Data about forest change, tenure, forest related employment and land use in #{@title}"
9+
if params[:widget]
10+
widgets_config = JSON.parse(File.read(Rails.root.join('app', 'javascript', 'pages', 'country', 'data', 'widgets-config.json')))
11+
widget_data = widgets_config[params[:widget]]
12+
@og_title = "#{widget_data["title"]} in #{@country["name"]}"
13+
# for dynamic widget image when the feature is ready
14+
# @img = "widgets/#{@widget}.png"
15+
end
716
end
817

918
def embed
10-
@desc = 'Data about forest change, tenure, forest related employment and land use'
11-
render layout: 'country_embed'
19+
@title = @country["name"]
20+
@desc = "Data about forest change, tenure, forest related employment and land use in #{@title}"
21+
render layout: 'application_react_embed'
1222
end
1323

24+
private
25+
26+
def set_country
27+
@country = Country.find_by_iso(params[:iso])
28+
end
1429
end

app/controllers/small_grants_fund_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
class SmallGrantsFundController < ApplicationController
22

3+
if ENV['FEATURE_ENV'] == 'staging'
4+
layout 'application_react'
5+
else
6+
layout 'small_grants_fund'
7+
end
8+
39
def index
410
@title = 'Small Grants Fund'
511
end

app/javascript/components/button/button-styles.scss

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ $button-height: rem(40px);
33

44
.c-button {
55
height: $button-height;
6+
font-family: $font-family-1;
67
border-radius: rem(20px);
78
width: 100%;
89
padding: 0 rem(15px);

app/javascript/components/modal/modal-component.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class CustomModal extends PureComponent {
2828
>
2929
<button
3030
onClick={onRequestClose}
31-
className={`c-modal-close ${closeClass}`}
31+
className={`modal-close ${closeClass}`}
3232
>
3333
<Icon icon={closeIcon} />
3434
</button>

app/javascript/components/modal/modal-styles.scss

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,19 @@ $close-position: 25px;
66
overflow: hidden;
77
}
88

9-
.c-modal-close {
9+
.modal-close {
1010
position: absolute;
1111
top: $close-position;
1212
right: $close-position;
1313
border: none;
1414
outline: none;
1515
cursor: pointer;
1616
z-index: 10;
17+
18+
svg {
19+
width: rem(15px);
20+
height: rem(15px);
21+
}
1722
}
1823

1924
html,
File renamed without changes.

app/javascript/pages/country/meta/meta-component.jsx

+2-13
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,28 @@ import { Helmet } from 'react-helmet';
66
class Meta extends PureComponent {
77
// eslint-disable-line react/prefer-stateless-function
88
render() {
9-
const { page, widgetImage } = this.props;
9+
const { page } = this.props;
1010
return (
1111
<Helmet>
1212
<title>{`${page ? `${page} | ` : ''}Global Forest Watch`}</title>
1313
<meta
1414
name="description"
1515
content={`Data about forest change, tenure, forest related employment and land use in ${page}`}
1616
/>
17-
<meta name="author" content="World Resources Institute" />
1817
<meta name="DC.title" content={`${page} | Global Forest Watch`} />
1918
<meta property="og:title" content={`${page} | Global Forest Watch`} />
2019
<meta
2120
property="og:description"
2221
content={`Data about forest change, tenure, forest related employment and land use in ${page}`}
2322
/>
2423
<meta property="og:url" content={window.location.href} />
25-
<meta
26-
property="og:image"
27-
content={
28-
widgetImage ||
29-
'http://www.globalforestwatch.org/assets/backgrounds/home-slider/bg_slide1.png'
30-
}
31-
/>
32-
<meta name="twitter:card" content="summary" />
33-
<meta name="twitter:site" content="@globalforests" />
3424
</Helmet>
3525
);
3626
}
3727
}
3828

3929
Meta.propTypes = {
40-
page: PropTypes.string,
41-
widgetImage: PropTypes.string
30+
page: PropTypes.string
4231
};
4332

4433
export default Meta;

app/javascript/pages/country/root/root-component.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ class Root extends PureComponent {
133133
{widgetAnchor && <ScrollTo target={widgetAnchor} />}
134134
<CountryDataProvider />
135135
<WhitelistsProvider />
136-
<Meta page={currentLocation} />
136+
<Meta
137+
page={
138+
locationNames &&
139+
locationNames.country &&
140+
locationNames.country.label
141+
}
142+
/>
137143
</div>
138144
);
139145
}

app/javascript/pages/country/widget/components/widget-header/widget-header.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { connect } from 'react-redux';
22
import compact from 'lodash/compact';
3-
import replace from 'lodash/replace';
43
import moment from 'moment';
54

65
import shareActions from 'components/share/share-actions';
@@ -43,11 +42,11 @@ const mapStateToProps = ({ location, modalMeta }, ownProps) => {
4342
subtitle: `${title} in ${
4443
locationNames.current ? locationNames.current.label : ''
4544
}`,
46-
shareUrl: `${replace(
47-
window.location.href,
48-
window.location.hash,
49-
''
50-
)}#${widget}`,
45+
shareUrl: `http://${window.location.host}${window.location.pathname}?${
46+
location && location.category && location.query.category
47+
? `category=${location.query.category}&`
48+
: ''
49+
}${`widget=${widget}`}#${widget}`,
5150
embedUrl,
5251
embedSettings:
5352
settingsConfig.config.size === 'small'

app/javascript/pages/country/widget/widgets/widget-glad-alerts/widget-glad-alerts-selectors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const getData = createSelector(
5858
if (!data || isEmpty(data)) return null;
5959
const groupedByYear = groupBy(data, 'year');
6060
const years = [];
61-
const latestFullWeek = moment(latest).subtract('weeks', 1);
61+
const latestFullWeek = moment(latest).subtract(1, 'weeks');
6262
const lastWeek = {
6363
isoWeek: latestFullWeek.isoWeek(),
6464
year: latestFullWeek.year()

app/models/country.rb

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class Country
2+
class << self
3+
def base_path
4+
ENV['GFW_API_HOST']
5+
end
6+
7+
def find_all
8+
url = "#{base_path}/countries"
9+
response = Typhoeus.get(url, headers: {"Accept" => "application/json"})
10+
if response.success?
11+
Rails.cache.fetch 'countries', expires_in: 1.day do
12+
JSON.parse(response.body)['countries']
13+
end
14+
else
15+
nil
16+
end
17+
end
18+
19+
def find_by_iso_or_name(value)
20+
find_by_iso(value) || find_by_name(value)
21+
end
22+
23+
def find_by_iso(iso)
24+
return nil unless iso
25+
url = "#{base_path}/countries/#{iso.downcase}?thresh=30"
26+
# CACHE: &bust=true if you want to flush the cache
27+
response = Typhoeus.get(url, headers: {"Accept" => "application/json"})
28+
29+
if response.success? and (response.body.length > 0)
30+
JSON.parse(response.body)
31+
else
32+
nil
33+
end
34+
end
35+
36+
def find_by_name(country_name)
37+
country_name, *_ = country_name.split(/_/)
38+
country_name = country_name.capitalize
39+
url = "https://wri-01.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20gfw2_countries%20where%20name%20like%20'#{country_name}%25'"
40+
response = Typhoeus.get(url, headers: {"Accept" => "application/json"})
41+
42+
if response.success?
43+
JSON.parse(response.body)['rows'][0]
44+
else
45+
nil
46+
end
47+
end
48+
end
49+
end

app/views/about/_about_page.html.erb

-1
This file was deleted.

app/views/about/_header.html.erb

-3
This file was deleted.

app/views/about/index.html.erb

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
<%= content_for :head do %>
2+
<%= render 'shared/icons' %>
3+
<%= controller_stylesheet_link_tag %>
4+
<% end %>
5+
6+
<%= requirejs_include_tag 'about' %>
17
<%= render 'shared/js_config' %>
28
<%= render 'shared/icons/svg_icons_about' %>
39
<%= render 'shared/icons/svg_icons_social' %>
4-
<%= render 'shared/gfw_assets' %>
5-
<%= render 'header' %>
6-
<%= render 'about_page' %>
10+
<div id="about-page"></div>

app/views/countries/overview.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= render 'shared/svg_icons_countries' %>
1+
<%= render 'shared/icons/svg_icons_countries' %>
22
<% content_for :js do %>
33
<%= render "countries_templates" %>
44
<%= render "shared/js_templates" %>

app/views/countries/show.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<%= render 'layouts/svg_icons' %>
2-
<%= render 'shared/svg_icons_countries' %>
1+
<%= render 'shared/icons/svg_icons' %>
2+
<%= render 'shared/icons/svg_icons_countries' %>
33
<% content_for :header do %>
44
<h1 class="header-title">
55
<a href="/">Global Forest Watch</a>

app/views/country/index.html.erb

-3
This file was deleted.

app/views/country/show.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<%= content_for :head do %>
2+
<%= render 'shared/google_v3_30_carto' %>
3+
<%= stylesheet_link_tag "http://libs.cartocdn.com/cartodb.js/v3/themes/css/cartodb.css", :media => 'all' %>
4+
<% end %>
5+
6+
<div id="country-page"></div>

app/views/embed/countries_overview.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
<%= render 'layouts/svg_icons' %>
2-
<%= render 'shared/svg_icons_countries' %>
1+
<%= render 'shared/icons/svg_icons' %>
2+
<%= render 'shared/icons/svg_icons_countries' %>
33
<%= render 'shared/modal' %>
44

55
<% content_for :css do %>

app/views/layouts/application.html.erb

+3-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
<link rel="canonical" href="<%= request.original_url %>" />
2121

22-
2322
<link href='http://fonts.googleapis.com/css?family=Fira+Sans:300,400,500,400italic' rel='stylesheet' type='text/css'>
2423

2524
<meta name="google-translate-customization" content="af2414ea962843fc-f48b15cdb6a3ab9b-gd8c738d3a7ff42de-1a">
@@ -33,12 +32,12 @@
3332
<%= render 'shared/gfw_assets' %>
3433
</head>
3534
<body class="<%= "is-#{controller_name}-page is-#{action_name}-action" %>">
36-
<%= render 'layouts/svg_icons' %>
35+
<%= render 'shared/icons/svg_icons' %>
3736

38-
<%= render 'shared/svg_icons_footer' %>
37+
<%= render 'shared/icons/svg_icons_footer' %>
3938
<%= render 'shared/modal' %>
4039
<%= render 'shared/notifications' %>
41-
40+
4241
<div class="wrap">
4342
<%= render "shared/header_landing" %>
4443
<div class="layout-content">

0 commit comments

Comments
 (0)