sitemap_boiler 0.1.0

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: 4a20e7255618af7746744e836ea449aca34e7379
4
+ data.tar.gz: f34c2137a0c76e66fb79a3690d1e6d59eb45bc2d
5
+ SHA512:
6
+ metadata.gz: 4fd9759d152fb23e665119d10566cc3717f09967f49f9aef1f0517bfe96eac99eed86a144e9cefd977df8e415f3db836c2f6bf34c1fd50935423b6c67e8ba2f8
7
+ data.tar.gz: acb9349ab85d08c57b5a298a84400143ca0ee7c8e854d25c6b7aec6f35361c75d9cdd734cfac2efd7b19babeb7a9d7cc507eff9250434a22300d1ee6fd07540d
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'builder', '~> 3.2', '>= 3.2.2'
6
+ gem 'json-schema'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 theocarrive
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,36 @@
1
+ # SitemapBoiler
2
+
3
+ [![Build Status](https://travis-ci.org/cheerz/sitemap_boiler.svg?branch=master)](https://travis-ci.org/cheerz/sitemap_boiler)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/e8e9c3b8ed2629568cd6/maintainability)](https://codeclimate.com/github/cheerz/sitemap_boiler/maintainability)
5
+
6
+ Welcome to SitemapBoiler!
7
+
8
+ This Gem is for websites with a limited number of URLs they want in their sitemap, to be registered in SEO results.
9
+ It allows you to have those URLs in a single JSON file, and to generate XML sitemaps in each language you want.
10
+ You can eventually make it run through a Cron job, and build the JSON input file from results of your database.
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'sitemap_boiler'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install sitemap_boiler
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sitemap_boiler.
31
+
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sitemap_boiler"
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
+ require "irb"
10
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require 'sitemap_boiler/version'
2
+ require 'sitemap_boiler/config'
3
+ require 'sitemap_boiler/sitemap_generator'
4
+
5
+ module SitemapBoiler
6
+ def self.generate(config_hash, output_dir)
7
+ config = SitemapBoiler::Config.new(config_hash)
8
+ generator = SitemapBoiler::SitemapGenerator.new(config)
9
+ config[:localizations].each do |localization|
10
+ file_suffix = localization['prefix'] || 'default'
11
+ generator.write(localization, "#{output_dir}/sitemap-#{file_suffix}.xml")
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'sitemap_boiler/default_config'
2
+ require 'json'
3
+
4
+ module SitemapBoiler
5
+ class Config
6
+ attr_accessor :config_hash
7
+
8
+ def initialize(config_hash)
9
+ @config_hash = DefaultConfig.merge(config_hash)
10
+ end
11
+
12
+ def [](key)
13
+ config_hash[key.to_s]
14
+ end
15
+
16
+ def self.from_file config_path
17
+ config_hash = JSON.parse(File.read(config_path))
18
+ new(config_hash)
19
+ end
20
+
21
+ private
22
+
23
+ def read_config(path)
24
+ JSON.parse File.open(path).read
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module SitemapBoiler
2
+ class DefaultConfig
3
+ def self.merge(config_hash)
4
+ to_h.merge(config_hash)
5
+ end
6
+
7
+ def self.to_h
8
+ {
9
+ 'urlset_headers' => {
10
+ 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
11
+ 'xhtml' => 'http://www.w3.org/1999/xhtml',
12
+ 'xmlns:mobile' => 'http://www.google.com/schemas/sitemap-mobile/1.0',
13
+ 'xmlns:image' => 'http://www.google.com/schemas/sitemap-image/1.1',
14
+ 'xmlns:xhtml' => 'http://www.w3.org/1999/xhtml'
15
+ }
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,48 @@
1
+ require 'builder'
2
+ require 'sitemap_boiler/url_composer'
3
+
4
+ module SitemapBoiler
5
+ class SitemapGenerator
6
+ attr_accessor :config
7
+
8
+ def initialize config
9
+ @config = config
10
+ end
11
+
12
+ def write localization, path
13
+ File.open(path, 'w') { |file| file.write(to_xml(localization)) }
14
+ end
15
+
16
+ def location_url config, localization, page
17
+ URLComposer.compose(config[:base_url], localization['prefix'], page['path'])
18
+ end
19
+
20
+ def to_xml localization
21
+ xml_markup.urlset(config[:urlset_headers]) do |urlset|
22
+ config[:pages].each do |page|
23
+ urlset.url do |url|
24
+ url.loc location_url(config, localization, page)
25
+ config[:localizations].each do |alternate|
26
+ url.tag!('xhtml:link',
27
+ href: location_url(config, alternate, page),
28
+ hreflang: alternate['hreflang'],
29
+ rel: :alternate
30
+ )
31
+ end
32
+ if page['android_url']
33
+ url.tag!('xhtml:link', href: page['android_url'], rel: :alternate)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def xml_markup
43
+ xml = Builder::XmlMarkup.new(indent: 2)
44
+ xml.instruct! :xml, encoding: 'UTF-8'
45
+ xml
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ module SitemapBoiler
2
+ class URLComposer
3
+ def self.compose(*args)
4
+ args.select { |a| a && a != '' }.join('/')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SitemapBoiler
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sitemap_boiler/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sitemap_boiler"
8
+ spec.version = SitemapBoiler::VERSION
9
+ spec.authors = ["Théo CARRIVE"]
10
+
11
+ spec.summary = %q{Generate multiple languages sitemap from one config file}
12
+ spec.homepage = "https://github.com/cheerz/sitemap_boiler"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
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_development_dependency "bundler", "~> 1.14"
23
+ spec.add_development_dependency "pry", "~> 0.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
data/test.xml ADDED
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">
3
+ <url>
4
+ <loc>https://www.testdomain.com</loc>
5
+ <xhtml:link href="https://www.testdomain.com" hreflang="x-default" rel="alternate"/>
6
+ <xhtml:link href="https://www.testdomain.com/fr" hreflang="fr-FR" rel="alternate"/>
7
+ <xhtml:link href="https://www.testdomain.com/ch-fr" hreflang="fr-CH" rel="alternate"/>
8
+ <xhtml:link href="https://www.testdomain.com/uk" hreflang="en-GB" rel="alternate"/>
9
+ <xhtml:link href="https://www.testdomain.com/us" hreflang="en-US" rel="alternate"/>
10
+ <xhtml:link href="https://www.testdomain.com/en" hreflang="en" rel="alternate"/>
11
+ <xhtml:link href="android-app://package.app/app/home" rel="alternate"/>
12
+ </url>
13
+ <url>
14
+ <loc>https://www.testdomain.com/categories/cute-giraffe</loc>
15
+ <xhtml:link href="https://www.testdomain.com/categories/cute-giraffe" hreflang="x-default" rel="alternate"/>
16
+ <xhtml:link href="https://www.testdomain.com/fr/categories/cute-giraffe" hreflang="fr-FR" rel="alternate"/>
17
+ <xhtml:link href="https://www.testdomain.com/ch-fr/categories/cute-giraffe" hreflang="fr-CH" rel="alternate"/>
18
+ <xhtml:link href="https://www.testdomain.com/uk/categories/cute-giraffe" hreflang="en-GB" rel="alternate"/>
19
+ <xhtml:link href="https://www.testdomain.com/us/categories/cute-giraffe" hreflang="en-US" rel="alternate"/>
20
+ <xhtml:link href="https://www.testdomain.com/en/categories/cute-giraffe" hreflang="en" rel="alternate"/>
21
+ </url>
22
+ <url>
23
+ <loc>https://www.testdomain.com/all_categories</loc>
24
+ <xhtml:link href="https://www.testdomain.com/all_categories" hreflang="x-default" rel="alternate"/>
25
+ <xhtml:link href="https://www.testdomain.com/fr/all_categories" hreflang="fr-FR" rel="alternate"/>
26
+ <xhtml:link href="https://www.testdomain.com/ch-fr/all_categories" hreflang="fr-CH" rel="alternate"/>
27
+ <xhtml:link href="https://www.testdomain.com/uk/all_categories" hreflang="en-GB" rel="alternate"/>
28
+ <xhtml:link href="https://www.testdomain.com/us/all_categories" hreflang="en-US" rel="alternate"/>
29
+ <xhtml:link href="https://www.testdomain.com/en/all_categories" hreflang="en" rel="alternate"/>
30
+ </url>
31
+ <url>
32
+ <loc>https://www.testdomain.com/categories/freaky-monkey</loc>
33
+ <xhtml:link href="https://www.testdomain.com/categories/freaky-monkey" hreflang="x-default" rel="alternate"/>
34
+ <xhtml:link href="https://www.testdomain.com/fr/categories/freaky-monkey" hreflang="fr-FR" rel="alternate"/>
35
+ <xhtml:link href="https://www.testdomain.com/ch-fr/categories/freaky-monkey" hreflang="fr-CH" rel="alternate"/>
36
+ <xhtml:link href="https://www.testdomain.com/uk/categories/freaky-monkey" hreflang="en-GB" rel="alternate"/>
37
+ <xhtml:link href="https://www.testdomain.com/us/categories/freaky-monkey" hreflang="en-US" rel="alternate"/>
38
+ <xhtml:link href="https://www.testdomain.com/en/categories/freaky-monkey" hreflang="en" rel="alternate"/>
39
+ <xhtml:link href="android-app://package.app/app/freaky-monkey" rel="alternate"/>
40
+ </url>
41
+ </urlset>
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sitemap_boiler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Théo CARRIVE
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/sitemap_boiler.rb
85
+ - lib/sitemap_boiler/config.rb
86
+ - lib/sitemap_boiler/default_config.rb
87
+ - lib/sitemap_boiler/sitemap_generator.rb
88
+ - lib/sitemap_boiler/url_composer.rb
89
+ - lib/sitemap_boiler/version.rb
90
+ - sitemap_boiler.gemspec
91
+ - test.xml
92
+ homepage: https://github.com/cheerz/sitemap_boiler
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.13
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Generate multiple languages sitemap from one config file
116
+ test_files: []