Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Taxon seo #2787

Closed
wants to merge 2 commits into from

4 participants

@sbounmy

this pull request allow taxon seo customization.
I've also added some custom rspec matchers : have_title and have_meta

@futhr

+1

But a small comment that meta-tags are for the major search engines today just an indicator that the site might be spamming keywords if you read (and trust) the latest seo reports, so meta-keywords should be within valuation a deprecated feature and maybe only be used for supplying additional support to internal search and tag clouds.

...should this not be pushed to master. I wonder if it wise to add additional fields to a stable branch?

@joneslee85
Collaborator

@sbounmy looks good to me, +1 from me, if @radar or any core team votes for this, I am happy to merge
@futhr do you have any sources to backup your point?

@futhr

@joneslee85 I read an interview/article with some Google guy about it when I was doing an research to update myself about general usage of meta tags for HTML5. But I have to get back to you when I find the reference again, this is as always opinionated know-how when it comes to seo best practices. Well, of course I don't rely on one source so I use to check major websites built on HTML5 and I see that its a common pattern that its being dropped together with may other meta types that was common before.

@sbounmy

@futhr I also heard about meta-keywords deprecation, but I wanted to keep it consistent with products which had meta-keywords.
IMHO this is a quite straightforward pull request so it can be pushed to master and 1-3-stable

@radar
Collaborator

Looks good to me too.

@radar radar referenced this pull request from a commit in radar/spree
@sbounmy sbounmy feature : taxons meta tags and title
Fixes #2787
29e2234
@radar radar closed this pull request from a commit
@sbounmy sbounmy feature : taxons meta tags and title
Fixes #2787

Conflicts:
	frontend/spec/requests/taxons_spec.rb
7717108
@radar radar closed this in 7717108
@vergeman vergeman referenced this pull request from a commit
@sbounmy sbounmy feature : taxons meta tags and title
Fixes #2787

Conflicts:
	frontend/spec/requests/taxons_spec.rb
8adf029
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @sbounmy
Commits on Mar 30, 2013
  1. @sbounmy

    adding fields to form

    sbounmy authored
This page is out of date. Refresh to see the latest.
View
10 core/app/controllers/spree/taxons_controller.rb
@@ -18,8 +18,14 @@ def show
end
private
- def accurate_title
- @taxon ? @taxon.name : super
+
+ def accurate_title
+ if @taxon
+ @taxon.seo_title
+ else
+ super
end
+ end
+
end
end
View
12 core/app/models/spree/taxon.rb
@@ -8,7 +8,8 @@ class Taxon < ActiveRecord::Base
before_create :set_permalink
- attr_accessible :name, :parent_id, :position, :icon, :description, :permalink, :taxonomy_id
+ attr_accessible :name, :parent_id, :position, :icon, :description, :permalink, :taxonomy_id,
+ :meta_description, :meta_keywords, :meta_title
validates :name, :presence => true
@@ -36,6 +37,15 @@ def applicable_filters
fs
end
+ # Return meta_title if set otherwise generates from root name and/or taxon name
+ def seo_title
+ if meta_title
+ meta_title
+ else
+ root? ? name : "#{root.name} - #{name}"
+ end
+ end
+
# Creates permalink based on Stringex's .to_url method
def set_permalink
if parent_id.nil?
View
17 core/app/views/spree/admin/taxons/_form.html.erb
@@ -16,6 +16,22 @@
<%= f.label :icon, t(:icon) %><br />
<%= f.file_field :icon %>
<% end %>
+
+ <%= f.field_container :meta_title do %>
+ <%= f.label :meta_title, t(:meta_title) %><br />
+ <%= f.text_field :meta_title, :class => 'fullwidth', :rows => 6 %>
+ <% end %>
+
+ <%= f.field_container :meta_description do %>
+ <%= f.label :meta_description, t(:meta_description) %><br />
+ <%= f.text_field :meta_description, :class => 'fullwidth', :rows => 6 %>
+ <% end %>
+
+ <%= f.field_container :meta_description do %>
+ <%= f.label :meta_keywords, t(:meta_keywords) %><br />
+ <%= f.text_field :meta_keywords, :class => 'fullwidth', :rows => 6 %>
+ <% end %>
+
</div>
<div class="omega seven columns">
@@ -24,4 +40,5 @@
<%= f.text_area :description, :class => 'fullwidth', :rows => 6 %>
<% end %>
</div>
+
</div>
View
9 core/db/migrate/20130328195253_add_seo_metas_to_taxons.rb
@@ -0,0 +1,9 @@
+class AddSeoMetasToTaxons < ActiveRecord::Migration
+ def change
+ change_table :spree_taxons do |t|
+ t.string :meta_title
+ t.string :meta_description
+ t.string :meta_keywords
+ end
+ end
+end
View
30 core/lib/spree/core/testing_support/capybara_ext.rb
@@ -85,6 +85,36 @@ def find_label(text)
end
+RSpec::Matchers.define :have_meta do |name, expected|
+ match do |actual|
+ has_css?("meta[name='#{name}'][content='#{expected}']")
+ end
+
+ failure_message_for_should do |actual|
+ actual = first("meta[name='#{name}']")
+ if actual
+ "expected that meta #{name} would have content='#{expected}' but was '#{actual[:content]}'"
+ else
+ "expected that meta #{name} would exist with content='#{expected}'"
+ end
+ end
+end
+
+RSpec::Matchers.define :have_title do |expected|
+ match do |actual|
+ has_css?("title", :text => expected)
+ end
+
+ failure_message_for_should do |actual|
+ actual = first("title")
+ if actual
+ "expected that title would have been '#{expected}' but was '#{actual.text}'"
+ else
+ "expected that title would exist with '#{expected}'"
+ end
+ end
+end
+
RSpec.configure do |c|
c.include CapybaraExt
end
View
24 core/spec/requests/taxons_spec.rb
@@ -9,10 +9,34 @@
product = create(:product, :name => "Superman T-Shirt")
product.taxons << t_shirts
end
+ let(:metas) { { :meta_description => 'Brand new Ruby on Rails TShirts', :meta_title => "Ruby On Rails TShirt", :meta_keywords => 'ror, tshirt, ruby' } }
# Regression test for #1796
it "can see a taxon's products, even if that taxon has child taxons" do
visit '/t/category/clothing/t-shirts'
page.should have_content("Superman T-Shirt")
end
+
+ describe 'meta tags and title' do
+
+ it 'displays metas' do
+ t_shirts.update_attributes metas
+ visit '/t/category/clothing/t-shirts'
+ page.should have_meta(:description, 'Brand new Ruby on Rails TShirts')
+ page.should have_meta(:keywords, 'ror, tshirt, ruby')
+ end
+
+ it 'display title if set' do
+ t_shirts.update_attributes metas
+ visit '/t/category/clothing/t-shirts'
+ page.should have_title("Ruby On Rails TShirt")
+ end
+
+ it 'display title from taxon root and taxon name' do
+ visit '/t/category/clothing/t-shirts'
+ page.should have_title('Category - T-Shirts - Spree Demo Site')
+ end
+
+ end
+
end
Something went wrong with that request. Please try again.