seo_noindex 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +38 -0
- data/lib/seo_noindex/helper.rb +15 -0
- data/lib/seo_noindex/middleware.rb +42 -0
- data/lib/seo_noindex/railtie.rb +7 -0
- data/lib/seo_noindex/version.rb +3 -0
- data/lib/seo_noindex.rb +9 -0
- data/seo_noindex.gemspec +24 -0
- data/spec/middleware_spec.rb +61 -0
- data/spec/spec_helper.rb +14 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd2db9020eea8e6f6f58164bd2e1c7077b74348a
|
4
|
+
data.tar.gz: ca40272955bd46c5174fe395a058564470a76f55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c14404191416485e1b378853f1209d9efc46cfa894cbeaca5c87d9f4a8c6c22745db09c2cce3647663050f57b46c8c13f86d269dea63e70ca457426c9753d381
|
7
|
+
data.tar.gz: a9c05891ebbf9cc76aa0990b81befe0cd55b297e6940e9a01c295fe7d42b60c95bf5b281dd84d31af6a53cb71247bf73ace7ef053c118c2935a49bd668fcd31b
|
data/.gitignore
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
capybara-*.html
|
4
|
+
.rspec
|
5
|
+
/tmp
|
6
|
+
/coverage/
|
7
|
+
/spec/tmp
|
8
|
+
**.orig
|
9
|
+
Gemfile.lock
|
10
|
+
|
11
|
+
# dotenv
|
12
|
+
# TODO Comment out this rule if environment variables can be committed
|
13
|
+
.env
|
14
|
+
|
15
|
+
## Environment normalization:
|
16
|
+
/.bundle
|
17
|
+
/vendor/bundle
|
18
|
+
|
19
|
+
.powenv
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2016 Vsevolod
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# SeoNoindex
|
2
|
+
|
3
|
+
Add noindex tag in head for disallowed paths from robots.txt file
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'seo_noindex'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install seo_noindex
|
18
|
+
|
19
|
+
If you're not running Rails, you'll have to add the middleware to your config.ru:
|
20
|
+
|
21
|
+
require 'seo_noindex'
|
22
|
+
use SeoNoindex::Middleware
|
23
|
+
|
24
|
+
Add helper to your view file in head section
|
25
|
+
|
26
|
+
<header>
|
27
|
+
<%= robots_noindex_tag -%>
|
28
|
+
</header>
|
29
|
+
|
30
|
+
## Example
|
31
|
+
|
32
|
+
For example in robots.txt we have this string:
|
33
|
+
|
34
|
+
Disallow: /admin
|
35
|
+
|
36
|
+
And if we follow **https://sitename/admin** we get this:
|
37
|
+
|
38
|
+
<meta name="robots" content="noindex">
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SeoNoindex
|
2
|
+
class Middleware
|
3
|
+
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
if check_noindex(env)
|
10
|
+
env['seo_noindex'] = 'true'
|
11
|
+
end
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def check_noindex(env)
|
18
|
+
!!disallowed_array.find{ |x| env['REQUEST_URI'] =~ Regexp.new('^' + x.first) }
|
19
|
+
end
|
20
|
+
|
21
|
+
def disallowed_array
|
22
|
+
@disallowed_array ||= begin
|
23
|
+
if defined?(Rails)
|
24
|
+
Rails.cache.fetch('parsed_robots_txt', expires_in: 1.day) do
|
25
|
+
prepare_robots(File.read('public/robots.txt'))
|
26
|
+
end
|
27
|
+
else
|
28
|
+
prepare_robots(File.read('./public/robots.txt'))
|
29
|
+
end
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def prepare_robots(text)
|
36
|
+
text.gsub('*', '.*').
|
37
|
+
gsub('?', '\?').
|
38
|
+
scan(/Disallow: (.+)/).uniq || []
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/lib/seo_noindex.rb
ADDED
data/seo_noindex.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'seo_noindex/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "seo_noindex"
|
7
|
+
gem.version = SeoNoindex::VERSION
|
8
|
+
gem.authors = ["Vsevolod Avramov"]
|
9
|
+
gem.email = ["gsevka@gmail.com"]
|
10
|
+
gem.description = %q{Add noindex tag for disallowed path in robots.txt file}
|
11
|
+
gem.summary = "seo_noindex-#{SeoNoindex::VERSION}"
|
12
|
+
gem.homepage = "https://github.com/vsevolod/seo_noindex"
|
13
|
+
gem.license = "MIT"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "pry"
|
22
|
+
gem.add_development_dependency "rspec"
|
23
|
+
gem.add_development_dependency "rack"
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require 'rack/lint'
|
3
|
+
|
4
|
+
module SeoNoindex
|
5
|
+
describe Middleware do
|
6
|
+
|
7
|
+
subject do
|
8
|
+
Middleware.new(nil).send(:check_noindex, env)
|
9
|
+
end
|
10
|
+
|
11
|
+
let :env do
|
12
|
+
{'REQUEST_URI' => url}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'without robots file' do
|
16
|
+
let(:url){ '/lorem/ipsum/dolor' }
|
17
|
+
it { is_expected.to be false }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'with robots txt' do
|
21
|
+
|
22
|
+
before :each do
|
23
|
+
allow(File).to receive(:read).and_return("
|
24
|
+
Allow: /lorem
|
25
|
+
Disallow: /ipsum
|
26
|
+
Disallow: /*?dolor
|
27
|
+
Disallow: /*&sit=
|
28
|
+
")
|
29
|
+
end
|
30
|
+
|
31
|
+
indexed = %w{
|
32
|
+
/lorem/indexed
|
33
|
+
/noindexed/lorem
|
34
|
+
/indexed/ipsum
|
35
|
+
/indexed?a=b&dolor=true
|
36
|
+
/indexed?option=sit
|
37
|
+
}
|
38
|
+
|
39
|
+
noindexed = %w{
|
40
|
+
/ipsum/no_indexed
|
41
|
+
/no_indexed?dolor=false
|
42
|
+
/indexed?a=b&sit=false
|
43
|
+
}
|
44
|
+
|
45
|
+
indexed.each do |current_url|
|
46
|
+
context "for #{current_url} indexed" do
|
47
|
+
let(:url){ current_url }
|
48
|
+
it{ is_expected.to be false }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
noindexed.each do |current_url|
|
53
|
+
context "for #{current_url} no indexed" do
|
54
|
+
let(:url){ current_url }
|
55
|
+
it{ is_expected.to be true }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'pry'
|
3
|
+
require 'seo_noindex'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# Run specs in random order to surface order dependencies. If you find an
|
7
|
+
# order dependency and want to debug it, you can fix the order by providing
|
8
|
+
# the seed, which is printed after each run.
|
9
|
+
# --seed 1234
|
10
|
+
config.order = "random"
|
11
|
+
|
12
|
+
config.filter_run :focus => true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: seo_noindex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vsevolod Avramov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Add noindex tag for disallowed path in robots.txt file
|
70
|
+
email:
|
71
|
+
- gsevka@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- lib/seo_noindex.rb
|
81
|
+
- lib/seo_noindex/helper.rb
|
82
|
+
- lib/seo_noindex/middleware.rb
|
83
|
+
- lib/seo_noindex/railtie.rb
|
84
|
+
- lib/seo_noindex/version.rb
|
85
|
+
- seo_noindex.gemspec
|
86
|
+
- spec/middleware_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/vsevolod/seo_noindex
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.8
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: seo_noindex-0.0.3
|
112
|
+
test_files:
|
113
|
+
- spec/middleware_spec.rb
|
114
|
+
- spec/spec_helper.rb
|