hancock_cms_seo 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +86 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/hancock/rails_admin/plugins/seo.coffee +4 -0
- data/app/assets/javascripts/hancock/rails_admin/plugins/seo/custom/ui.coffee +0 -0
- data/app/assets/stylesheets/hancock/rails_admin/plugins/seo.sass +3 -0
- data/app/assets/stylesheets/hancock/rails_admin/plugins/seo/custom/theming.sass +0 -0
- data/app/assets/stylesheets/hancock/rails_admin/plugins/seo/footer_nav_links.sass +16 -0
- data/app/controllers/concerns/hancock/seo/x_frame_options.rb +42 -0
- data/app/helpers/hancock/seo/seo_helper.rb +60 -0
- data/app/models/concerns/hancock/seo/decorators/seo.rb +60 -0
- data/app/models/concerns/hancock/seo/decorators/sitemap_data.rb +35 -0
- data/app/models/concerns/hancock/seo/seoable.rb +71 -0
- data/app/models/concerns/hancock/seo/sitemap_data_field.rb +37 -0
- data/app/models/concerns/hancock/seo/sitemapable.rb +7 -0
- data/app/models/hancock/seo/seo.rb +16 -0
- data/app/models/hancock/seo/sitemap_data.rb +16 -0
- data/app/views/blocks/_seo_block.html.slim +25 -0
- data/app/views/blocks/_seo_block_with_obj.html.slim +18 -0
- data/app/views/hancock/seo/blocks/_ga.html.slim +8 -0
- data/app/views/hancock/seo/blocks/_ym.html.slim +31 -0
- data/app/views/shared/_meta.html.slim +28 -0
- data/app/views/shared/_obj_with_seo.html.slim +38 -0
- data/app/views/shared/_og.html.slim +4 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/initializers/hancock_seo.rb +7 -0
- data/config/locales/ru.hancock.seo.yml +37 -0
- data/hancock_cms_seo.gemspec +40 -0
- data/lib/generators/hancock/seo/config/config_generator.rb +13 -0
- data/lib/generators/hancock/seo/config/templates/hancock_seo.erb +10 -0
- data/lib/generators/hancock/seo/migrations/migrations_generator.rb +18 -0
- data/lib/generators/hancock/seo/migrations/templates/migration_seos.rb +48 -0
- data/lib/generators/hancock/seo/models/decorators_generator.rb +24 -0
- data/lib/generators/hancock/seo/models/seo_generator.rb +39 -0
- data/lib/generators/hancock/seo/models/sitemap_data_generator.rb +39 -0
- data/lib/generators/hancock/seo/models/templates/seo.erb +57 -0
- data/lib/generators/hancock/seo/models/templates/sitemap_data.erb +31 -0
- data/lib/generators/hancock/seo/sitemap/sitemap_generator.rb +27 -0
- data/lib/generators/hancock/seo/sitemap/templates/sitemap.erb +31 -0
- data/lib/hancock/seo/admin.rb +24 -0
- data/lib/hancock/seo/admin/seo.rb +69 -0
- data/lib/hancock/seo/admin/sitemap_data.rb +47 -0
- data/lib/hancock/seo/configuration.rb +29 -0
- data/lib/hancock/seo/engine.rb +44 -0
- data/lib/hancock/seo/models/active_record/seo.rb +14 -0
- data/lib/hancock/seo/models/active_record/sitemap_data.rb +11 -0
- data/lib/hancock/seo/models/mongoid/seo.rb +25 -0
- data/lib/hancock/seo/models/mongoid/sitemap_data.rb +24 -0
- data/lib/hancock/seo/models/seo.rb +114 -0
- data/lib/hancock/seo/models/sitemap_data.rb +79 -0
- data/lib/hancock/seo/version.rb +5 -0
- data/lib/hancock_cms_seo.rb +43 -0
- data/release.sh +6 -0
- metadata +193 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 47fa9a50126db8a16d614a5fb6e72a3d68e98969
|
4
|
+
data.tar.gz: af8810345cbfa83152832e19901c021879e93371
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6c127efdf5eefb6bf31a66b29ccc8c0dd2b8499d0a03e872ced719d3f7f318aa5816a0bfe4a5baffaecf22c497d02a731830410fbbbb83d9991090e87c41125
|
7
|
+
data.tar.gz: 3ccd0bd7b5d4533f31a940996daf7a3a43dafff892ba4df36862fc242780bb9d9e24061bc5eea875c2890334d34332fcd5d894a4d99df6407d6e0a265c50aa82
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
hancock_seo
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alexander Kiseliev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# HancockCmsSeo
|
2
|
+
|
3
|
+
### Remaded from [EnjoyCMSSeo](https://github.com/enjoycreative/enjoy_cms_seo)
|
4
|
+
|
5
|
+
SEO and sitemap fields for [HancockCMS](https://github.com/red-rocks/hancock_cms).
|
6
|
+
Add Seo support to HancockCMS plugins by default and other objects in two lines.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'hancock_cms_seo'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install hancock_cms_seo
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Mongoid
|
27
|
+
|
28
|
+
Add this in your model for attributes
|
29
|
+
```ruby
|
30
|
+
include Hancock::Seo::Seoable
|
31
|
+
include Hancock::Seo::SitemapDataField
|
32
|
+
```
|
33
|
+
|
34
|
+
and this for rails_admin config
|
35
|
+
```ruby
|
36
|
+
group :seo do
|
37
|
+
active false
|
38
|
+
field :seo
|
39
|
+
end
|
40
|
+
group :sitemap_data do
|
41
|
+
active false
|
42
|
+
field :sitemap_data
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
Also you can generate and then edit config/initializers/hancock_seo.rb
|
47
|
+
|
48
|
+
$ rails g hancock:seo:config
|
49
|
+
|
50
|
+
SEO fields (h1, title, keywords, description, og_title, og_image, robots) and sitemap_data fields(sitemap_show, sitemap_lastmod, sitemap_changefreq, sitemap_priority) are delegated to your model.
|
51
|
+
|
52
|
+
#### Sitemap
|
53
|
+
|
54
|
+
Also you can use [SitemapGenerator](https://github.com/kjvarga/sitemap_generator) for sitemap.
|
55
|
+
|
56
|
+
#### Google Analitics and Yandex Metrika
|
57
|
+
|
58
|
+
We have helper methods for this. Usage
|
59
|
+
```ruby
|
60
|
+
hancock_ym_counter_tag('counter_id')
|
61
|
+
```
|
62
|
+
or
|
63
|
+
```ruby
|
64
|
+
hancock_ga_counter_tag('counter_id')
|
65
|
+
```
|
66
|
+
or
|
67
|
+
```ruby
|
68
|
+
render_hancock_counters(ym_counter_id: 'counter_id1', ga_counter_id: 'counter_id2')
|
69
|
+
```
|
70
|
+
[More](https://github.com/red-rocks/hancock_cms_seo/blob/master/app/helpers/hancock/seo/seo_helper.rb)
|
71
|
+
|
72
|
+
|
73
|
+
## Development
|
74
|
+
|
75
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
76
|
+
|
77
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
78
|
+
|
79
|
+
## Contributing
|
80
|
+
|
81
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/hancock_cms_seo.
|
82
|
+
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
.footer-nav-link.sitemap, .footer-nav-link.robots_txt
|
2
|
+
a
|
3
|
+
font-size: 0
|
4
|
+
&:before
|
5
|
+
display: inline-block
|
6
|
+
font-family: FontAwesome
|
7
|
+
font-size: 18px
|
8
|
+
text-rendering: auto
|
9
|
+
-webkit-font-smoothing: antialiased
|
10
|
+
-moz-osx-font-smoothing: grayscale
|
11
|
+
content: "\f0e8"
|
12
|
+
box-sizing: border-box
|
13
|
+
|
14
|
+
.footer-nav-link.robots_txt a:before
|
15
|
+
content: "\f0f6"
|
16
|
+
font-size: 18px
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Hancock::Seo::XFrameOptions
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
def clear_x_frame_options
|
6
|
+
begin
|
7
|
+
if x_frame_options_referer_regexp and request.referer =~ x_frame_options_referer_regexp
|
8
|
+
response.headers.delete('X-Frame-Options')
|
9
|
+
else
|
10
|
+
if defined?(Addressable)
|
11
|
+
_domain = Addressable::URI.parse(request.referer).domain
|
12
|
+
else
|
13
|
+
_domain = URI.parse(request.referer).host
|
14
|
+
end
|
15
|
+
|
16
|
+
if base_site_host.is_a?(Regexp)
|
17
|
+
response.headers.delete('X-Frame-Options') if _domain =~ base_site_host
|
18
|
+
else
|
19
|
+
response.headers.delete('X-Frame-Options') if _domain == base_site_host
|
20
|
+
end
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class_methods do
|
28
|
+
def clear_x_frame_options
|
29
|
+
after_action :clear_x_frame_options
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
protected
|
34
|
+
def x_frame_options_referer_regexp
|
35
|
+
# /^https?:\/\/([^\/]+metrika.*yandex.(ru|ua|com|com.tr|by|kz)|([^\/]+.)?webvisor.com)\//
|
36
|
+
/^https?\:\/\/([^\/]*metrika.*yandex\.(ru|ua|com|com\.tr|by|kz)|([^\/]+\.)?webvisor\.com)\//i
|
37
|
+
end
|
38
|
+
def base_site_host
|
39
|
+
request.domain
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hancock::Seo::SeoHelper
|
2
|
+
|
3
|
+
def hancock_ym_counter_tag(counter_id)
|
4
|
+
return nil if counter_id.blank?
|
5
|
+
render partial: "hancock/seo/blocks/ym", locals: {counter_id: counter_id}
|
6
|
+
end
|
7
|
+
def hancock_ga_counter_tag(counter_id)
|
8
|
+
return nil if counter_id.blank?
|
9
|
+
render partial: "hancock/seo/blocks/ga", locals: {counter_id: counter_id}
|
10
|
+
end
|
11
|
+
def render_hancock_counters(opts = {})
|
12
|
+
ret = []
|
13
|
+
|
14
|
+
_cache_key = "ym_counter".freeze
|
15
|
+
ym_counter = Rails.cache.fetch(_cache_key) do
|
16
|
+
if Hancock::Seo.config.cache_support
|
17
|
+
Hancock::Cache::Fragment.create_unless_exists(name: _cache_key, parents: hancock_cache_views_keys)
|
18
|
+
_cache_key = [_cache_key]
|
19
|
+
_cache_key += hancock_cache_views_keys
|
20
|
+
else
|
21
|
+
_cache_key = [_cache_key]
|
22
|
+
end
|
23
|
+
_add_cache_key = opts.delete(:cache_key)
|
24
|
+
_cache_key = [_cache_key, _add_cache_key].flatten if _add_cache_key
|
25
|
+
|
26
|
+
_html = Settings.ym_counter_html(default: '', kind: :code, label: 'Yandex Метрика HTML-код'.freeze, cache_keys: _cache_key).strip
|
27
|
+
unless _html.blank?
|
28
|
+
_html
|
29
|
+
else
|
30
|
+
ym_counter_id = opts[:ym_counter_id] || Settings.ym_counter_id(default: '', kind: :string, label: 'Yandex Метрика ID'.freeze, cache_keys: _cache_key).strip
|
31
|
+
ym_counter_id.blank? ? nil : hancock_ym_counter_tag(ym_counter_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
ret << ym_counter unless ym_counter.blank?
|
35
|
+
|
36
|
+
_cache_key = "ga_counter".freeze
|
37
|
+
ga_counter = Rails.cache.fetch(_cache_key) do
|
38
|
+
if Hancock::Seo.config.cache_support
|
39
|
+
Hancock::Cache::Fragment.create_unless_exists(name: _cache_key, parents: hancock_cache_views_keys)
|
40
|
+
_cache_key = [_cache_key]
|
41
|
+
_cache_key += hancock_cache_views_keys
|
42
|
+
else
|
43
|
+
_cache_key = [_cache_key]
|
44
|
+
end
|
45
|
+
_add_cache_key = opts.delete(:cache_key)
|
46
|
+
_cache_key = [_cache_key, _add_cache_key].flatten if _add_cache_key
|
47
|
+
|
48
|
+
_html = Settings.ga_counter_html(default: '', kind: :code, label: 'Google Analitics HTML-код'.freeze, cache_keys: _cache_key).strip
|
49
|
+
unless _html.blank?
|
50
|
+
_html
|
51
|
+
else
|
52
|
+
ga_counter_id = opts[:ga_counter_id] || Settings.ga_counter_id(default: '', kind: :string, label: 'Google Analitics ID'.freeze, cache_keys: _cache_key).strip
|
53
|
+
ga_counter_id.blank? ? nil : hancock_ga_counter_tag(ga_counter_id)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
ret << ga_counter unless ga_counter.blank?
|
57
|
+
|
58
|
+
ret.join.html_safe
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Hancock::Seo::Decorators
|
2
|
+
module Seo
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
# # after_save :og_image_auto_rails_admin_jcrop
|
7
|
+
# def og_image_auto_rails_admin_jcrop
|
8
|
+
# auto_rails_admin_jcrop(:og_image) # or nil for cancel autocrop
|
9
|
+
# end
|
10
|
+
|
11
|
+
# hancock_cms_attached_file(:og_image)
|
12
|
+
# def og_image_styles
|
13
|
+
# {thumb: "800x600>"}
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def og_image_jcrop_options
|
17
|
+
# {}
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
#
|
21
|
+
# def set_default_seo
|
22
|
+
# _obj = self.seoable
|
23
|
+
# if _obj and _obj.set_default_seo?
|
24
|
+
# self.h1 = _obj.default_seo_h1 if self.h1.blank?
|
25
|
+
# self.title = _obj.default_seo_title if self.title.blank?
|
26
|
+
# self.keywords = _obj.default_seo_keywords if self.keywords.blank?
|
27
|
+
# self.description = _obj.default_seo_description if self.description.blank?
|
28
|
+
# self.title = _obj.default_seo_og_title if self.title.blank?
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# ############ rails_admin ##############
|
33
|
+
# def self.rails_admin_add_fields
|
34
|
+
# [] #super
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# def self.rails_admin_add_config(config)
|
38
|
+
# #super(config)
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def self.admin_can_user_defined_actions
|
42
|
+
# [].freeze
|
43
|
+
# end
|
44
|
+
# def self.admin_cannot_user_defined_actions
|
45
|
+
# [].freeze
|
46
|
+
# end
|
47
|
+
# def self.manager_can_user_defined_actions
|
48
|
+
# [].freeze
|
49
|
+
# end
|
50
|
+
# def self.manager_cannot_user_defined_actions
|
51
|
+
# [].freeze
|
52
|
+
# end
|
53
|
+
# def self.rails_admin_user_defined_visible_actions
|
54
|
+
# [].freeze
|
55
|
+
# end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Hancock::Seo::Decorators
|
2
|
+
module SitemapData
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
|
7
|
+
############# rails_admin ##############
|
8
|
+
# def self.rails_admin_add_fields
|
9
|
+
# [] #super
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# def self.rails_admin_add_config(config)
|
13
|
+
# #super(config)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def self.admin_can_user_defined_actions
|
17
|
+
# [].freeze
|
18
|
+
# end
|
19
|
+
# def self.admin_cannot_user_defined_actions
|
20
|
+
# [].freeze
|
21
|
+
# end
|
22
|
+
# def self.manager_can_user_defined_actions
|
23
|
+
# [].freeze
|
24
|
+
# end
|
25
|
+
# def self.manager_cannot_user_defined_actions
|
26
|
+
# [].freeze
|
27
|
+
# end
|
28
|
+
# def self.rails_admin_user_defined_visible_actions
|
29
|
+
# [].freeze
|
30
|
+
# end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Hancock::Seo::Seoable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
LOCALIZED_FIELDS = [:h1, :title, :keywords, :description, :og_title, :author]
|
4
|
+
FIELDS = LOCALIZED_FIELDS + [:og_image, :robots]
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_one :seo, as: :seoable, autosave: true, class_name: "Hancock::Seo::Seo"
|
8
|
+
accepts_nested_attributes_for :seo
|
9
|
+
|
10
|
+
delegate(*FIELDS, to: :seo)
|
11
|
+
delegate(*(FIELDS.map {|f| "#{f}=".to_sym }), to: :seo)
|
12
|
+
|
13
|
+
if Hancock::Seo.config.localize
|
14
|
+
delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations".to_sym }), to: :seo)
|
15
|
+
delegate(*(LOCALIZED_FIELDS.map {|f| "#{f}_translations=".to_sym }), to: :seo)
|
16
|
+
end
|
17
|
+
|
18
|
+
alias seo_without_build seo
|
19
|
+
def seo
|
20
|
+
seo_without_build || build_seo
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def default_seo_h1
|
25
|
+
if self.respond_to?(:name)
|
26
|
+
self.name
|
27
|
+
elsif self.respond_to?(:title)
|
28
|
+
self.title
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def default_seo_title
|
32
|
+
if self.respond_to?(:name)
|
33
|
+
self.name
|
34
|
+
elsif self.respond_to?(:title)
|
35
|
+
self.title
|
36
|
+
end
|
37
|
+
end
|
38
|
+
def default_seo_keywords
|
39
|
+
""
|
40
|
+
end
|
41
|
+
def default_seo_description
|
42
|
+
""
|
43
|
+
end
|
44
|
+
def default_seo_og_title
|
45
|
+
if self.respond_to?(:name)
|
46
|
+
self.name
|
47
|
+
elsif self.respond_to?(:title)
|
48
|
+
self.title
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def set_default_seo?
|
53
|
+
true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def page_title
|
58
|
+
return self.title unless self.title.blank?
|
59
|
+
self.name if self.respond_to?(:name)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_og_title
|
63
|
+
return self.og_title unless self.og_title.blank?
|
64
|
+
self.name if self.respond_to?(:name)
|
65
|
+
end
|
66
|
+
|
67
|
+
def og_image_jcrop_options
|
68
|
+
{aspectRation: 800.0/600.0}
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|