Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding meta robots input texts for pages and content entries pages #220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def set_automatic_translations(page, locale)
%i(
title slug fullpath template_path redirect_url
sections_content sections_dropzone_content
seo_title meta_description meta_keywords
seo_title meta_description meta_keywords meta_robots
).each do |name|
page[name][locale] ||= page[name][default_locale]
end
Expand Down
6 changes: 3 additions & 3 deletions lib/locomotive/steam/adapters/filesystem/yaml_loaders/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def complete_attributes_from_data(attributes, data, locale)

# set the attributes
%i(
title slug redirect_url seo_title meta_description meta_keywords
title slug redirect_url seo_title meta_description meta_keywords meta_robots
listed published position
sections_content sections_dropzone_content editable_elements raw_template
).each do |name|
Expand Down Expand Up @@ -118,7 +118,7 @@ def build(filepath, fullpath, locale)
}

%i(
redirect_url seo_title meta_description meta_keywords
redirect_url seo_title meta_description meta_keywords meta_robots
sections_content sections_dropzone_content
).each do |name|
_attributes[name] = { locale => attributes.delete(name) }
Expand All @@ -138,7 +138,7 @@ def update(leaf, filepath, fullpath, locale)
update_editable_elements(leaf, attributes.delete(:editable_elements), locale)

%i(
redirect_url seo_title meta_description meta_keywords
redirect_url seo_title meta_description meta_keywords meta_robots
sections_content sections_dropzone_content
).each do |name|
leaf[name][locale] ||= attributes.delete(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/locomotive/steam/liquid/drops/content_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Liquid
module Drops
class ContentEntry < I18nBase

delegate :_slug, :_translated, :seo_title, :meta_keywords, :meta_description, :created_at, :updated_at, to: :@_source
delegate :_slug, :_translated, :seo_title, :meta_keywords, :meta_description, :meta_robots, :created_at, :updated_at, to: :@_source

alias :_permalink :_slug

Expand Down
2 changes: 1 addition & 1 deletion lib/locomotive/steam/liquid/drops/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Drops
class Page < I18nBase

delegate :position, :fullpath, :depth, :redirect_url, :handle, to: :@_source
delegate :seo_title, :meta_keywords, :meta_description, to: :@_source
delegate :seo_title, :meta_keywords, :meta_description, :meta_robots, to: :@_source
delegate :listed?, :published?, :redirect?, :index?, :is_layout?, :templatized?, to: :@_source
delegate :sections_content, :sections_dropzone_content, to: :@_source

Expand Down
1 change: 1 addition & 0 deletions lib/locomotive/steam/liquid/tags/seo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def render_metadata(context)
%{
<meta name="description" content="#{self.value_for(:meta_description, context)}">
<meta name="keywords" content="#{self.value_for(:meta_keywords, context)}">
<meta name="robots" content="#{self.value_for(:meta_robots, context)}">
}
end

Expand Down
3 changes: 2 additions & 1 deletion lib/locomotive/steam/middlewares/templatized_page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def set_content_entry!
# log it
debug_log "Found content entry: #{entry._label}"
else
log "C"*25
url = services.url_builder.url_for(page_not_found, locale)
redirect_to url, 302
redirect_to url, 404
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def initialize(adapter, site = nil, locale = nil, content_type_repository = nil)

# Entity mapping
mapping :content_entries, entity: ContentEntry do
localized_attributes :_slug, :seo_title, :meta_description, :meta_keywords
localized_attributes :_slug, :seo_title, :meta_description, :meta_keywords, :meta_robots

default_attribute :content_type, -> (repository) { repository.content_type }
end
Expand Down
2 changes: 1 addition & 1 deletion lib/locomotive/steam/repositories/page_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PageRepository
localized_attributes :title, :slug, :permalink,
:source, :raw_template, :template_path, :data_path, :redirect_url, :fullpath,
:sections_content, :sections_dropzone_content,
:seo_title, :meta_description, :meta_keywords
:seo_title, :meta_description, :meta_keywords, :meta_robots

embedded_association :editable_elements, EditableElementRepository
end
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/default/app/views/pages/index.liquid.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ title: Home page

%meta{ content: "{{ site.meta_description }}", name: "description" }
%meta{ content: "{{ site.meta_keywords }}", name: "keywords" }
%meta{ content: "{{ site.meta_robots }}", name: "robots" }

{{ '/foo/bar' | auto_discovery_link_tag: 'rel:alternate', 'type:application/atom+xml', 'title:A title' }}

Expand Down
7 changes: 4 additions & 3 deletions spec/unit/liquid/drops/content_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

let(:site) { instance_double('Site', default_locale: 'en') }
let(:type) { instance_double('Type', fields_by_name: { title: instance_double('Field', type: :string ) }) }
let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', created_at: 0, updated_at: 1) }
let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', meta_robots: 'noindex', created_at: 0, updated_at: 1) }
let(:assigns) { {} }
let(:services) { Locomotive::Steam::Services.build_instance }
let(:context) { ::Liquid::Context.new(assigns, {}, { services: services, site: site, locale: 'en' }) }
Expand All @@ -20,6 +20,7 @@
expect(subject.seo_title).to eq 'seo title'
expect(subject.meta_keywords).to eq 'keywords'
expect(subject.meta_description).to eq 'description'
expect(subject.meta_robots).to eq 'noindex'
expect(subject.created_at).to eq 0
expect(subject.updated_at).to eq 1
end
Expand Down Expand Up @@ -110,7 +111,7 @@

describe 'belong_to content type' do

let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', created_at: 0, updated_at: 1, author: author) }
let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', meta_robots: 'noindex', created_at: 0, updated_at: 1, author: author) }
let(:type) { instance_double('Type', fields_by_name: { title: instance_double('StringField', type: :string ), author: instance_double('Author', type: :belongs_to), picture: instance_double('FileField', type: :file), category: instance_double('SelectField', type: :select) }) }
let(:author) { instance_double('Author', _slug: 'john-doe', localized_attributes: {}) }
let(:picture_field) { Locomotive::Steam::ContentEntry::FileField.new('foo.png', 'http://assets.dev', 0, 42) }
Expand Down Expand Up @@ -147,7 +148,7 @@

describe '#as_json' do

let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', created_at: 0, updated_at: 1, author: author, authors: authors) }
let(:entry) { instance_double('Article', _id: 42, localized_attributes: {}, content_type: type, title: 'Hello world', _label: 'Hello world', _slug: 'hello-world', _translated: false, seo_title: 'seo title', meta_keywords: 'keywords', meta_description: 'description', meta_robots: 'noindex', created_at: 0, updated_at: 1, author: author, authors: authors) }
let(:type) { instance_double('Type', fields_by_name: { title: instance_double('StringField', type: :string ), author: instance_double('Author', type: :belongs_to), authors: instance_double('Author', type: :many_to_many), picture: instance_double('FileField', type: :file), category: instance_double('SelectField', type: :select) }) }
let(:author) { instance_double('Author', _slug: 'john-doe', localized_attributes: {}) }
let(:authors) { instance_double('Authors', all: [author]) }
Expand Down
3 changes: 2 additions & 1 deletion spec/unit/liquid/drops/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:services) { Locomotive::Steam::Services.build_instance }
let(:site) { instance_double('Site', default_locale: 'en') }
let(:context) { ::Liquid::Context.new(assigns, {}, { locale: 'en', services: services, site: site }) }
let(:page) { instance_double('Page', id: 42, localized_attributes: [], title: 'Index', slug: 'index', fullpath: 'index', content_type: nil, depth: 1, templatized?: false, listed?: true, published?: true, is_layout?: true, redirect?: false, seo_title: 'seo title', redirect_url: '/', handle: 'index', meta_keywords: 'keywords', meta_description: 'description') }
let(:page) { instance_double('Page', id: 42, localized_attributes: [], title: 'Index', slug: 'index', fullpath: 'index', content_type: nil, depth: 1, templatized?: false, listed?: true, published?: true, is_layout?: true, redirect?: false, seo_title: 'seo title', redirect_url: '/', handle: 'index', meta_keywords: 'keywords', meta_description: 'description', meta_robots: 'noindex') }
let(:drop) { described_class.new(page).tap { |d| d.context = context } }

subject { drop }
Expand All @@ -25,6 +25,7 @@
expect(subject.seo_title).to eq 'seo title'
expect(subject.meta_keywords).to eq 'keywords'
expect(subject.meta_description).to eq 'description'
expect(subject.meta_robots).to eq 'robots'
expect(subject.listed?).to eq true
expect(subject.redirect?).to eq false
expect(subject.is_layout?).to eq true
Expand Down
8 changes: 4 additions & 4 deletions spec/unit/liquid/tags/seo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
let(:page) { nil }
let(:content_entry) { nil }

let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: 'Acme (SEO)', meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: 'Acme (SEO)', meta_description: 'A short site description', meta_keywords: 'test only cat dog', meta_robots: 'noindex,nofollow') }
let(:assigns) { { 'site' => site, 'page' => page, 'content_entry' => content_entry } }
let(:context) { ::Liquid::Context.new(assigns, {}, {}) }

Expand All @@ -30,7 +30,7 @@

describe 'no seo_title site property' do

let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: nil, meta_description: 'A short site description', meta_keywords: 'test only cat dog') }
let(:site) { liquid_instance_double('Site', name: 'Acme', seo_title: nil, meta_description: 'A short site description', meta_keywords: 'test only cat dog', meta_robots: 'noindex,nofollow') }
it { is_expected.to eq '<title>Acme</title>' }

end
Expand Down Expand Up @@ -66,15 +66,15 @@

describe 'with a page' do

let(:page) { liquid_instance_double('Page', meta_description: "It's snowing", meta_keywords: 'snow') }
let(:page) { liquid_instance_double('Page', meta_description: "It's snowing", meta_keywords: 'snow', meta_robots: 'nofollow') }
it { is_expected.to include %Q[<meta name="description" content="It's snowing">] }
it { is_expected.to include %Q[<meta name="keywords" content="snow">] }

end

describe 'with a content entry' do

let(:content_entry) { liquid_instance_double('Entry', meta_description: "It's snowing", meta_keywords: 'snow') }
let(:content_entry) { liquid_instance_double('Entry', meta_description: "It's snowing", meta_keywords: 'snow', meta_robots: 'nofollow') }
it { is_expected.to include %Q[<meta name="description" content="It's snowing">] }
it { is_expected.to include %Q[<meta name="keywords" content="snow">] }

Expand Down