para-seo_tools 0.4.0 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4b8959221c49d287170b758d7dbe9a0e2bb291b
4
- data.tar.gz: 2c9f4d8e455c31bf0f47c7c1cdb1dffdd54a571f
3
+ metadata.gz: 724bd64d9cc63d30dd64a7c34f5ac844e2a4aa58
4
+ data.tar.gz: 2cddf86252810fc4f146f2e458e126d9a33b45f1
5
5
  SHA512:
6
- metadata.gz: dd129c962571f25f126aeafed737ef17e86fb2e2ef73351bf1b416a4372c4a917f80b41017a614506001a2a2fe26ba829b7108e2675df715fe99015bea4ddc73
7
- data.tar.gz: 0880f858c0a6db534a542182e456f46f126a2ce4271bef67fc19a7e62297fb1b1330b297b4278db6f435866bc564e280f631fcd71b61816ab1278e75989b1c07
6
+ metadata.gz: af089b88e4d1fd13ed69e23a853adca81ee3829c976dde442876adcf2de804ccaa1a41c7ab34c6adda4ec2225fe275d84e27ccffb4d5b48f7b9b266cfae8d667
7
+ data.tar.gz: 956ba99b6bcd1ca62cd691efbdad934e0f71ccba101467c701c653b24c3f296b190803fc0a02c8d5f6fb7e968081e60ab57b5693ef1decc9a0be9087d7b252f1
data/README.md CHANGED
@@ -268,8 +268,8 @@ Then go to the admin panel, and click the **Sitemap** menu link.
268
268
  ### 3. Generate a sitemap.xml
269
269
 
270
270
  Sitemap generation is accomplished through the use of the
271
- [rails-sitemap](https://github.com/viseztrance/rails-sitemap) gem,
272
- with a custom task to integrate easily with `seo_tools-para`.
271
+ [Sitemap Generator](https://github.com/kjvarga/sitemap_generator) gem,
272
+ with a custom task and interface to integrate easily with `seo_tools-para`.
273
273
 
274
274
  You'll first need to configure your application's host name.
275
275
  This can be defined in the generated initializer or in an environment variable.
@@ -277,7 +277,7 @@ This can be defined in the generated initializer or in an environment variable.
277
277
  In the `config/initializers/seo_tools.rb` initializer :
278
278
 
279
279
  ```ruby
280
- config.host = "www.mydomain.com"
280
+ config.host = 'www.mydomain.com'
281
281
  ```
282
282
 
283
283
  Or with the `APP_DOMAIN` environment variable.
@@ -286,19 +286,30 @@ Or with the `APP_DOMAIN` environment variable.
286
286
  APP_DOMAIN="www.mydomain.com"
287
287
  ```
288
288
 
289
- Generating the sitemap can be done with the dedicated rake task :
289
+ If you want to handle subdomains you need to set the `host` without a subdomain
290
+ and the `default_subdomain` configs together :
290
291
 
291
- ```bash
292
- rake seo_tools:sitemap:generate
292
+ ```ruby
293
+ config.host = 'mydomain.com'
294
+ config.default_subdomain = 'www'
293
295
  ```
294
296
 
295
- You can pass a `LOCATION` environment variable to define where to store it.
296
- By default, it will be stored at : `public/sitemap.xml`
297
+ Generating the sitemap can be done with the dedicated rake task, or through
298
+ the Seo Tools admin panel by refreshing it manually :
297
299
 
298
300
  ```bash
299
- rake seo_tools:sitemap:generate LOCATION=/home/user/apps/my-app/shared
301
+ rake para:seo_tools:sitemap:generate
300
302
  ```
301
303
 
304
+ This will generate the sitemap at `public/system/sitemap.xml.gz`. If you
305
+ need to change that path, you can use the `sitemaps_path` configuration, which
306
+ allows you to choose a `public/` subdirectory as the target folder for the
307
+ generated sitemaps.
308
+
309
+ For more customization informations, please read the
310
+ [Sitemap Generator](https://github.com/kjvarga/sitemap_generator) gem
311
+ documentation.
312
+
302
313
  ### 4. Retrieving meta tags in your app
303
314
 
304
315
  Meta tags edition and rendering is done through the
@@ -0,0 +1,17 @@
1
+ module Para
2
+ module SeoTools
3
+ module Admin
4
+ class SkeletonRefreshesController < ::Para::Admin::JobsController
5
+ def run
6
+ job = Para::SeoTools::Skeleton::Job.perform_later
7
+ track_job(job)
8
+ end
9
+
10
+ def ping
11
+ job = Para::SeoTools::SitemapPinger.perform_later
12
+ track_job(job)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -6,15 +6,6 @@ module Para
6
6
  super
7
7
  @available_locales = ::Para::SeoTools::Page.group(:locale).pluck(:locale)
8
8
  end
9
-
10
- def refresh
11
- ::Para::SeoTools::Skeleton.with_logging do
12
- ::Para::SeoTools::Skeleton.load
13
- ::Para::SeoTools::Skeleton::Worker.perform
14
- end
15
-
16
- redirect_to after_form_submit_path
17
- end
18
9
  end
19
10
  end
20
11
  end
@@ -10,8 +10,10 @@ module Para
10
10
 
11
11
  validate :identifier_uniqueness
12
12
 
13
- scope :with_subdomain, ->(subdomain) { where("config->>'subdomain' = ?", subdomain) }
14
- scope :with_domain, ->(domain) { where("config->>'domain' = ?", domain) }
13
+ scope :with_subdomain, ->(subdomain) { scope_with(subdomain: subdomain) }
14
+ scope :with_domain, ->(domain) { scope_with(domain: domain) }
15
+
16
+ scope :scope_with, -> (attributes) { PageScoping.scope_with(self, attributes) }
15
17
 
16
18
  def meta_tag(name)
17
19
  if (value = send(name).presence) && (meta = process(name, value)).present?
@@ -61,9 +63,20 @@ module Para
61
63
  end
62
64
  end
63
65
 
64
- def sitemap_host
66
+ def url
67
+ @url ||= [host, path].join
68
+ end
69
+
70
+ def host
65
71
  host = []
66
- host << config['subdomain'] if Para::SeoTools.handle_subdomain
72
+
73
+ if Para::SeoTools.handle_subdomain
74
+ if (subdomain = config['subdomain'])
75
+ host << subdomain
76
+ else
77
+ host << Para::SeoTools.default_domain
78
+ end
79
+ end
67
80
 
68
81
  if Para::SeoTools.handle_domain
69
82
  host << config['domain']
@@ -71,7 +84,13 @@ module Para
71
84
  host << Para::SeoTools.host
72
85
  end
73
86
 
74
- host.join('.')
87
+ host.compact.join('.')
88
+
89
+ [Para::SeoTools.protocol, host].join('://')
90
+ end
91
+
92
+ def siblings
93
+ self.class.where(identifier: identifier).where.not(id: id)
75
94
  end
76
95
 
77
96
  private
@@ -1,5 +1,10 @@
1
1
  %ul.panel-controls
2
2
  %li
3
- = link_to @component.relation_path(action: :refresh, return_to: request.fullpath), class: 'btn btn-default' do
3
+ = link_to run_admin_skeleton_refresh_path, class: 'btn btn-default', remote: true, data: { :'job-tracker-button' => true } do
4
4
  = fa_icon 'refresh'
5
5
  = t('para.seo_tools.pages.refresh_skeleton')
6
+
7
+ %li
8
+ = link_to ping_admin_skeleton_refresh_path, class: 'btn btn-default', remote: true, data: { :'job-tracker-button' => true } do
9
+ = fa_icon 'cloud-upload'
10
+ = t('para.seo_tools.pages.ping_search_engines')
@@ -6,8 +6,22 @@ fr:
6
6
  default_meta_tag_value: "Valeur par défaut : <b>%{value}</b>"
7
7
  additional_meta_tags: "Meta-données avancées"
8
8
  refresh_skeleton: "Mettre à jour"
9
+ ping_search_engines: "Envoyer le sitemap aux moteurs de recherche"
9
10
  choose_locale: "Choisissez une langue"
10
11
 
12
+ jobs:
13
+ para/seo_tools/skeleton/job:
14
+ progressing: "Le plan du site est actuellement recalculé, merci de patienter quelques instants ..."
15
+ success: "Le plan du site a bien été mis à jour !"
16
+ para/seo_tools/sitemap_pinger:
17
+ progressing: "Le plan du site est actuellement envoyé aux différents moteurs de recherche ..."
18
+ success: "Le plan du site a bien été transmis aux moteurs de recherche !"
19
+
20
+ activemodel:
21
+ models:
22
+ para/seo_tools/skeleton/job: "Mise à jour du plan du site"
23
+ para/seo_tools/sitemap_pinger: "Envoi du sitemap"
24
+
11
25
  activerecord:
12
26
  attributes:
13
27
  para/seo_tools/page:
@@ -1,7 +1,7 @@
1
1
  # Use `lazy: true` to avoid generating the pages skeleton on server run
2
2
  #
3
3
  # You'll then have to run `rake seo_tools:skeleton:build` to refresh it or use
4
- # the `Para::SeoTools::Skeleton::Worker.perform` method in some worker to
4
+ # the `Para::SeoTools::Skeleton::Job.perform` method in some worker to
5
5
  # refresh it periodically
6
6
  #
7
7
  # Note that you also have to always refresh the sitemap manually with the
@@ -21,6 +21,8 @@ module Para
21
21
 
22
22
  def set_meta_tags_from_page(page)
23
23
  if page.kind_of?(Para::SeoTools::Page)
24
+ meta_tags_store.page = page
25
+
24
26
  Para::SeoTools::Page::META_TAGS.each do |tag_name|
25
27
  if (value = page.meta_tag(tag_name)).present?
26
28
  set_meta_tag(tag_name, value)
@@ -20,8 +20,9 @@ module Para
20
20
  description_tag,
21
21
  keywords_tag,
22
22
  canonical_tag,
23
- vendor_tags
24
- ].compact.join(LINE_SEPARATOR).html_safe
23
+ vendor_tags,
24
+ hreflang_tags
25
+ ].flatten.compact.join(LINE_SEPARATOR).html_safe
25
26
  end
26
27
 
27
28
  private
@@ -68,7 +69,16 @@ module Para
68
69
  end
69
70
  end
70
71
 
71
- vendor_tags.join(LINE_SEPARATOR)
72
+ vendor_tags
73
+ end
74
+
75
+ def hreflang_tags
76
+ return unless Para::SeoTools.generate_hreflang_tags
77
+ return unless meta_tags.page
78
+
79
+ SeoTools::PageScoping.new(meta_tags.page).alternate_language_siblings.map do |page|
80
+ tag(:link, rel: 'alternate', href: page.url, hreflang: page.locale)
81
+ end
72
82
  end
73
83
 
74
84
  def meta_tags
@@ -3,6 +3,7 @@ module Para
3
3
  module MetaTags
4
4
  class Store
5
5
  attr_reader :controller, :defaults
6
+ attr_accessor :page
6
7
 
7
8
  TAGS = :title, :description, :image, :url, :site_name, :keywords, :type,
8
9
  :site, :card, :charset, :canonical
@@ -14,15 +14,26 @@ module Para
14
14
  resource.scope.present?
15
15
  end
16
16
 
17
- def column?(attribute)
18
- resource.class.column_names.include?(attribute.to_s)
19
- end
20
-
21
17
  def uniqueness_scope_conditions
22
18
  return resource.class unless scoped?
23
19
 
24
- resource.scope_attributes.reduce(resource.class) do |query, (attribute, value)|
25
- if column?(attribute)
20
+ self.class.scope_with(resource.class, resource.scope_attributes)
21
+ end
22
+
23
+ def unique_identifier
24
+ return resource.identifier unless scoped?
25
+
26
+ resource.scope_attributes.merge(identifier: resource.identifier).to_json
27
+ end
28
+
29
+ def alternate_language_siblings
30
+ attributes = resource.scope_attributes.reject { |attribute, _| attribute == 'locale' }
31
+ self.class.scope_with(resource.siblings, attributes)
32
+ end
33
+
34
+ def self.scope_with(resource_class, attributes)
35
+ attributes.reduce(resource_class) do |query, (attribute, value)|
36
+ if column?(resource_class, attribute)
26
37
  query.where(attribute => value)
27
38
  else
28
39
  query.where("config->>'#{ attribute }' = ?", value)
@@ -30,9 +41,8 @@ module Para
30
41
  end
31
42
  end
32
43
 
33
- def unique_identifier
34
- return resource.identifier unless scoped?
35
- resource.scope_attributes.merge(identifier: resource.identifier).to_json
44
+ def self.column?(resource_class, attribute)
45
+ resource_class.column_names.include?(attribute.to_s)
36
46
  end
37
47
  end
38
48
  end
@@ -3,9 +3,12 @@ module Para
3
3
  class Routes < Para::Plugins::Routes
4
4
  def draw
5
5
  plugin :seo_tools do
6
- crud_component :seo_tools_skeleton, scope: ':model', controller: :skeleton_resources do
7
- collection do
8
- get :refresh
6
+ crud_component :seo_tools_skeleton, scope: ':model', controller: :skeleton_resources
7
+
8
+ namespace :admin do
9
+ resource :skeleton_refresh, only: [:show] do
10
+ get 'run'
11
+ get 'ping'
9
12
  end
10
13
  end
11
14
  end
@@ -1,36 +1,26 @@
1
1
  module Para
2
2
  module SeoTools
3
3
  class Sitemap
4
- def self.generate!
5
- puts " * GENERATE SITEMAP ..."
6
-
7
- build
8
-
9
- puts " * BUILD ..."
10
-
11
- ::Sitemap::Generator.instance.build!
12
-
13
- puts " * SAVE ..."
14
-
15
- ::Sitemap::Generator.instance.save(path)
16
-
17
- puts " * SAVED !"
4
+ def self.prepare
5
+ SitemapGenerator::Sitemap.sitemaps_path = Para::SeoTools.sitemaps_path
6
+ SitemapGenerator::Sitemap.default_host = Para::SeoTools.full_host
18
7
  end
19
8
 
20
- def self.path
21
- @path ||= begin
22
- root = ::Sitemap.configuration.save_path || ENV["LOCATION"] || Rails.public_path
23
- File.join(root, "sitemap.xml")
24
- end
25
- end
9
+ def self.generate!
10
+ prepare
26
11
 
27
- def self.build
28
- ::Sitemap::Generator.instance.load do
12
+ SitemapGenerator::Sitemap.create do
29
13
  Para::SeoTools::Page.find_each do |page|
30
- literal page.path, host: page.sitemap_host
14
+ add page.path, host: page.host
31
15
  end
32
16
  end
33
17
  end
18
+
19
+ def self.ping_search_engines
20
+ prepare
21
+
22
+ SitemapGenerator::Sitemap.ping_search_engines
23
+ end
34
24
  end
35
25
  end
36
26
  end
@@ -0,0 +1,15 @@
1
+ module Para
2
+ module SeoTools
3
+ class SitemapPinger < Para::Job::Base
4
+ def perform
5
+ Para::SeoTools::Sitemap.ping_search_engines
6
+ end
7
+
8
+ private
9
+
10
+ def progress_total
11
+ nil
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module Para
2
+ module SeoTools
3
+ module Skeleton
4
+ class Job < Para::Job::Base
5
+ def perform
6
+ Para::SeoTools::Skeleton.build(load_skeleton: true)
7
+ Para::SeoTools::Sitemap.generate!
8
+ end
9
+
10
+ private
11
+
12
+ def progress_total
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -9,7 +9,7 @@ module Para
9
9
  attr_reader :name, :resource, :locale, :defaults, :config
10
10
 
11
11
  def initialize(name, path: nil, resource: nil, **options)
12
- @name = name
12
+ @name = Array.wrap(name).join(':')
13
13
  @path = path
14
14
  @resource = resource
15
15
 
@@ -5,7 +5,7 @@ module Para
5
5
 
6
6
  autoload :Site
7
7
  autoload :PageBuilder
8
- autoload :Worker
8
+ autoload :Job
9
9
 
10
10
  mattr_accessor :site, :config, :options, :enable_logging
11
11
 
@@ -1,5 +1,5 @@
1
1
  module Para
2
2
  module SeoTools
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
@@ -1,4 +1,4 @@
1
- require 'sitemap'
1
+ require 'sitemap_generator'
2
2
  require 'para'
3
3
 
4
4
  require 'para/seo_tools/engine'
@@ -12,6 +12,7 @@ module Para
12
12
  autoload :Routes
13
13
  autoload :Skeleton
14
14
  autoload :Sitemap
15
+ autoload :SitemapPinger
15
16
  autoload :PageScoping
16
17
 
17
18
  autoload :MetaTaggable
@@ -19,7 +20,10 @@ module Para
19
20
  autoload :ViewHelpers
20
21
 
21
22
  mattr_writer :host
22
- @@host = ENV['APP_DOMAIN']
23
+ @@host = nil
24
+
25
+ mattr_accessor :protocol
26
+ @@protocol = :http
23
27
 
24
28
  mattr_accessor :handle_domain
25
29
  @@handle_domain = false
@@ -27,6 +31,9 @@ module Para
27
31
  mattr_accessor :handle_subdomain
28
32
  @@handle_subdomain = false
29
33
 
34
+ mattr_accessor :default_subdomain
35
+ @@default_subdomain = nil
36
+
30
37
  mattr_accessor :title_methods
31
38
  @@title_methods = %w(title name)
32
39
 
@@ -39,6 +46,12 @@ module Para
39
46
  mattr_accessor :defaults
40
47
  @@defaults = nil
41
48
 
49
+ mattr_accessor :generate_hreflang_tags
50
+ @@generate_hreflang_tags = false
51
+
52
+ mattr_accessor :sitemaps_path
53
+ @@sitemaps_path = 'system/'
54
+
42
55
  def self.configure
43
56
  block_given? ? yield(self) : self
44
57
  end
@@ -48,7 +61,12 @@ module Para
48
61
  end
49
62
 
50
63
  def self.host
51
- @@host.presence && @@host.match(/[^:]+/)[0]
64
+ @@host ||= ENV['APP_DOMAIN']
65
+ end
66
+
67
+ def self.full_host
68
+ host = [Para::SeoTools.default_subdomain, Para::SeoTools.host].compact.join(',')
69
+ [Para::SeoTools.protocol, host].join('://')
52
70
  end
53
71
  end
54
72
  end
@@ -15,7 +15,7 @@ namespace :para do
15
15
 
16
16
  desc "Ping engines."
17
17
  task ping: :environment do
18
- ::Sitemap::Ping.send_request(Para::SeoTools::Sitemap.path)
18
+ SitemapGenerator::Sitemap.ping_search_engines
19
19
  end
20
20
  end
21
21
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency 'rails', '>= 4.0', '< 5.0'
22
- spec.add_dependency 'sitemap', '~> 0.3'
22
+ spec.add_dependency 'sitemap_generator'
23
23
  spec.add_dependency 'request_store'
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.7"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para-seo_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-03 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -31,19 +31,19 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: sitemap
34
+ name: sitemap_generator
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0.3'
39
+ version: '0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '0.3'
46
+ version: '0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: request_store
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ files:
102
102
  - app/.DS_Store
103
103
  - app/components/seo_tools_skeleton_component.rb
104
104
  - app/controllers/.DS_Store
105
+ - app/controllers/para/seo_tools/admin/skeleton_refreshes_controller.rb
105
106
  - app/controllers/para/seo_tools/admin/skeleton_resources_controller.rb
106
107
  - app/decorators/seo_tools_skeleton_component_decorator.rb
107
108
  - app/helpers/para/seo_tools/admin/fields_helper.rb
@@ -142,10 +143,11 @@ files:
142
143
  - lib/para/seo_tools/page_scoping.rb
143
144
  - lib/para/seo_tools/routes.rb
144
145
  - lib/para/seo_tools/sitemap.rb
146
+ - lib/para/seo_tools/sitemap_pinger.rb
145
147
  - lib/para/seo_tools/skeleton.rb
148
+ - lib/para/seo_tools/skeleton/job.rb
146
149
  - lib/para/seo_tools/skeleton/page_builder.rb
147
150
  - lib/para/seo_tools/skeleton/site.rb
148
- - lib/para/seo_tools/skeleton/worker.rb
149
151
  - lib/para/seo_tools/version.rb
150
152
  - lib/para/seo_tools/view_helpers.rb
151
153
  - lib/tasks/migration.rake
@@ -173,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
175
  version: '0'
174
176
  requirements: []
175
177
  rubyforge_project:
176
- rubygems_version: 2.5.1
178
+ rubygems_version: 2.6.7
177
179
  signing_key:
178
180
  specification_version: 4
179
181
  summary: SEO tools for the Para CMS
@@ -1,11 +0,0 @@
1
- module Para
2
- module SeoTools
3
- module Skeleton
4
- class Worker
5
- def self.perform
6
- Para::SeoTools::Skeleton.build
7
- end
8
- end
9
- end
10
- end
11
- end