organic-sitemap 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25a753e3c05e6d9cc7638560aa7d60291dc41b64
4
+ data.tar.gz: 08850357c0eda30093911b4a1aa0f5d76c07edd7
5
+ SHA512:
6
+ metadata.gz: c4c050134631f2f6efda43de0b8658d097e0097f8e6a80f648d48ebeabc97a8dfd89c6bb6b054385380287c3d80148d3de5629ae199f2e35a68d41a026d60b46
7
+ data.tar.gz: df40f3371fd9cdb9863d49d11852e81223d19b46fada509792de2acc1a1d1c93b829f3e21e50b79a935c7d1c5ec8a0a21dcc181e97b30af40442e4cdc41e4ae9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ organic-sitemap
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in organic-sitemap.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Abelardo Gil Maldonado
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,61 @@
1
+ # OrganicSitemap
2
+ OrganicSitemap is a gem that gives you a structure to manage your sitemap with healthy urls. It adds a middleware that save on a expiry set on redis all urls served from your server that meet certain criteria
3
+
4
+ * *status* **200**
5
+ * Only html pages
6
+ * *method* **GET**
7
+ * Don't match with any of **skypped_urls** Array
8
+
9
+ ## Requisites
10
+
11
+ **OrganicSitemap** add a middleware on your **Rails** project.
12
+
13
+ Uses a **Redis** connection to save sitemaps urls
14
+
15
+ ## Installation
16
+ OrganicSearch is not available as a gem yet, you can load it using my github account.
17
+
18
+ Add in your Gemfile:
19
+
20
+ ```gem 'organic-sitemap', :git => 'git://github.com/abelardogilm/organic-sitemap.git'```
21
+
22
+ Run ```bundle install.```
23
+
24
+ ## Configuration
25
+
26
+ To setup this gem you should add your config:
27
+
28
+ ```
29
+ OrganicSitemap.configure do |config|
30
+
31
+ # Add here all regexp you don't want to add on your sitemap
32
+ # config.skipped_urls = [ "^/sitemap",
33
+ # ".txt$",
34
+ # ".rss$" ]
35
+
36
+ # OrganicSitemap ignore query_params to identify urls. You can add you allowed params
37
+ # config.allowed_params = [...]
38
+
39
+ # By default, all urls are saved on Redis.new(url: 'redis://127.0.0.1:6379'), but you can set you own connection
40
+ # config.redis_connection = Your redis connection
41
+
42
+ # url are saved on a set on redis called "sitemap-urls", but if you want you can change it
43
+ # config.storage_key = your key
44
+
45
+ # By dafault all url have a expiry time in 7 days, after this time, if no one load this page, it will be removed from the set. To change it (expect number of days):
46
+ # config.expiry_time = X
47
+ end
48
+ ```
49
+ ## Rails config generator
50
+
51
+ Copy base config file on your Rails app by
52
+
53
+ ```rails generator organic_sitemap:config```
54
+
55
+ ## Contribution
56
+
57
+ If you have cool idea for improving this Gem or any bug fix just open a pull request and I'll be glad to have a look and merge it if seems fine.
58
+
59
+ ## License
60
+
61
+ This project rocks and uses [MIT-LICENSE](https://github.com/abelardogilm/organic-sitemap/blob/master/LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "organic-sitemap"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ module OrganicSitemap
2
+ class ConfigGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("../templates", __FILE__)
4
+
5
+ desc "Generates the config initializer file for Organic Sitemap"
6
+ def copy_initializer_file
7
+ copy_file "organic_sitemap.rb", "config/initializers/organic_sitemap.rb"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ OrganicSitemap.configure do |config|
2
+
3
+ # Add here all regexp you don't want to add on your sitemap
4
+ # config.skipped_urls = [ "^/sitemap",
5
+ # ".txt$",
6
+ # ".rss$" ]
7
+
8
+ # OrganicSitemap ignore query_params to identify urls. You can add you allowed params
9
+ # config.allowed_params = [...]
10
+
11
+ # By default, all urls are saved on Redis.new(url: 'redis://127.0.0.1:6379'), but you can set you own connection
12
+ # config.redis_connection = Your redis connection
13
+
14
+ # url are saved on a set on redis called "sitemap-urls", but if you want you can change it
15
+ # config.storage_key = your key
16
+
17
+ # By dafault all url have a expiry time in 7 days, after this time, if no one load this page, it will be removed from the set. To change it (expect number of days):
18
+ # config.expiry_time = X
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'organic-sitemap/version'
2
+ require 'organic-sitemap/redis_manager'
3
+ require 'organic-sitemap/configuration'
4
+ require 'organic-sitemap/url_processor'
5
+ require 'redis'
6
+
7
+ if defined? Rails
8
+ require 'organic-sitemap/railtie'
9
+ require 'organic-sitemap/middleware/url_capture' if defined? Rails
10
+ end
11
+
12
+ module OrganicSitemap
13
+ end
@@ -0,0 +1,24 @@
1
+ module OrganicSitemap
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration) if block_given?
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :storage, :storage_key, :domains, :allowed_params,
13
+ :skipped_urls, :redis_connection, :expiry_time
14
+
15
+ def initialize
16
+ @storage = 'redis'
17
+ @storage_key = 'sitemap-urls'
18
+ @allowed_params = []
19
+ @skipped_urls = []
20
+ @redis_connection = Redis.new(url: 'redis://127.0.0.1:6379')
21
+ @expiry_time = 7
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module OrganicSitemap
2
+ module Middleware
3
+ class UrlCapture
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ status, headers, response = @app.call(env)
10
+ processor = OrganicSitemap::UrlProcessor.new(status, headers, Rack::Request.new(env))
11
+ if processor.sitemap_url?
12
+ OrganicSitemap::RedisManager.add(processor.sanitize_path_info)
13
+ end
14
+ [status, headers, response]
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,7 @@
1
+ module OrganicSitemap
2
+ class Railtie < Rails::Railtie
3
+ initializer "organic-sitemap.insert_middleware" do |app|
4
+ app.config.middleware.use "OrganicSitemap::Middleware::UrlCapture"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,30 @@
1
+ module OrganicSitemap
2
+ class RedisManager
3
+ def self.add(key)
4
+ return unless key
5
+ OrganicSitemap.configuration.
6
+ redis_connection.
7
+ zadd(OrganicSitemap.configuration.storage_key,
8
+ (DateTime.now + OrganicSitemap.configuration.expiry_time.to_i).to_time.to_i,
9
+ key)
10
+ end
11
+
12
+ def self.clean_set(time = Time.now)
13
+ OrganicSitemap.configuration.
14
+ redis_connection.
15
+ zremrangebyscore(OrganicSitemap.configuration.storage_key,
16
+ "-inf",
17
+ time.to_i)
18
+ end
19
+
20
+ def self.sitemap_urls(from: nil, to: nil)
21
+ from = from ? from.to_time.to_i : '-inf'
22
+ to = to ? to.to_time.to_i : '+inf'
23
+ OrganicSitemap.configuration.
24
+ redis_connection.
25
+ zrangebyscore(OrganicSitemap.configuration.storage_key,
26
+ from,
27
+ to)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ module OrganicSitemap
2
+ class UrlProcessor
3
+
4
+ attr_accessor :status, :headers, :request
5
+
6
+ def initialize(status, headers, request)
7
+ @status, @headers, @request = status, headers, request
8
+ end
9
+
10
+ def sanitize_path_info
11
+ query_string = Rack::Utils.parse_nested_query(request.query_string)
12
+
13
+ query_string.select!{|x,_| OrganicSitemap.configuration.allowed_params.include? x }
14
+
15
+ sanitize_url = request.path
16
+ sanitize_url << "?#{Rack::Utils.build_query(query_string.sort)}" if query_string.any?
17
+ sanitize_url
18
+ rescue => e
19
+ p "OrganicSitemap ERROR: sanitizing #{request.path} raise error"
20
+ p "OrganicSitemap ERROR: " + e
21
+ end
22
+
23
+ def sitemap_url?
24
+ success_response? && html_page? && request.get? && is_expected_domain? && is_allowed_url?
25
+ end
26
+
27
+ private
28
+
29
+ def success_response?
30
+ status == 200
31
+ end
32
+
33
+ def html_page?
34
+ headers["Content-Type"]["text/html"]
35
+ end
36
+
37
+ def is_expected_domain?
38
+ # Any domain if not explicitly configured
39
+ return true if OrganicSitemap.configuration.domains.nil?
40
+ OrganicSitemap.configuration.domains.include? request.host
41
+ end
42
+
43
+ def is_allowed_url?
44
+ # Any url if not explicitly configured
45
+ return true if OrganicSitemap.configuration.skipped_urls.nil?
46
+ [*OrganicSitemap.configuration.skipped_urls].each do |skip_url|
47
+ return false if request.path[skip_url]
48
+ end
49
+ true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module OrganicSitemap
2
+ VERSION = "0.1.1" # First stable version
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'organic-sitemap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "organic-sitemap"
8
+ spec.version = OrganicSitemap::VERSION
9
+ spec.authors = ["Kaskito"]
10
+ spec.email = ["abelardogilm@gmail.com"]
11
+
12
+ spec.summary = %q{Create your Sitemap in a organic way.}
13
+ spec.description = %q{Create your Sitemap in a organic way.}
14
+ spec.homepage = "https://github.com/abelardogilm/organic-sitemap/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'rack', '~> 1.0', '>= 1.0.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rspec", '~> 0'
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency 'simplecov', '~> 0'
28
+ spec.add_development_dependency 'redis', '~> 0'
29
+ spec.add_development_dependency 'pry', '~> 0'
30
+ spec.add_development_dependency 'fakeredis', '~> 0'
31
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: organic-sitemap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Kaskito
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.9'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: simplecov
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: redis
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: pry
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: fakeredis
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ description: Create your Sitemap in a organic way.
132
+ email:
133
+ - abelardogilm@gmail.com
134
+ executables: []
135
+ extensions: []
136
+ extra_rdoc_files: []
137
+ files:
138
+ - ".gitignore"
139
+ - ".rspec"
140
+ - ".ruby-gemset"
141
+ - ".ruby-version"
142
+ - ".travis.yml"
143
+ - Gemfile
144
+ - LICENSE.txt
145
+ - README.md
146
+ - Rakefile
147
+ - bin/console
148
+ - bin/setup
149
+ - lib/generators/organic_sitemap/config_generator.rb
150
+ - lib/generators/organic_sitemap/templates/organic_sitemap.rb
151
+ - lib/organic-sitemap.rb
152
+ - lib/organic-sitemap/configuration.rb
153
+ - lib/organic-sitemap/middleware/url_capture.rb
154
+ - lib/organic-sitemap/railtie.rb
155
+ - lib/organic-sitemap/redis_manager.rb
156
+ - lib/organic-sitemap/url_processor.rb
157
+ - lib/organic-sitemap/version.rb
158
+ - organic_sitemap.gemspec
159
+ homepage: https://github.com/abelardogilm/organic-sitemap/
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.3
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Create your Sitemap in a organic way.
183
+ test_files: []