middleman-search_engine_sitemap 1.0.1 → 1.1.0.pre

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: 4706cd09a6993f06326a3bbdd0d72e92c6a57f70
4
- data.tar.gz: 273f1b9b18575a93d59a3bd2ecf74976d7181542
3
+ metadata.gz: b3b58083244aa3f27819c34c0e6025e0746116d0
4
+ data.tar.gz: 548c765f5c78920a45ac94422bae157ad4e6afe7
5
5
  SHA512:
6
- metadata.gz: f9a59d58b24e6aee83c09270038350d8422037f5183136441b54ae38ec016506fa6f7806ace33e7ec8663c794561c6c0ab09fc1ba77ca95c65b2014fd90e9b74
7
- data.tar.gz: 5879500523aee627a9253875529e1f5a6e0dd9ff1c1660467c9ec37415299017f4792efe5ae19a1d84c2dd7d6728c2b525d3e05b87c364c26f2adde4e9eef882
6
+ metadata.gz: 5504652ca4c7661a1ef4018e0c4f61f88b207ebf85c839e0241221694d889e404757f45ea3f6b55c7280ef167b59caf210a4b4da050ff1cb71a00487dbe4ec7c
7
+ data.tar.gz: ccbfeb3dd221018e47829c1af11063c739093da9a3d77babbcc1b556c949b7f6127f5c43b3eaf96aab28618e5c4bab5fbaab288fb0a3dc5b42a8ffd75c5ffeff
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![Build Status](https://travis-ci.org/Aupajo/middleman-search_engine_sitemap.png?branch=master)](https://travis-ci.org/Aupajo/middleman-search_engine_sitemap)
4
4
  [![Code Climate](https://codeclimate.com/github/Aupajo/middleman-search_engine_sitemap.png)](https://codeclimate.com/github/Aupajo/middleman-search_engine_sitemap)
5
5
  [![Dependency Status](https://gemnasium.com/Aupajo/middleman-search_engine_sitemap.svg)](https://gemnasium.com/Aupajo/middleman-search_engine_sitemap)
6
+ [![Gem
7
+ Version](https://badge.fury.io/rb/middleman-search_engine_sitemap.svg)](http://badge.fury.io/rb/middleman-search_engine_sitemap)
6
8
 
7
9
  [Sitemaps](http://www.sitemaps.org/) are an open standard to tell search engines (such as Google) about each page on your site, how often they're updated, and how important each page is, relative to other pages on your site.
8
10
 
@@ -38,6 +40,27 @@ activate :search_engine_sitemap
38
40
 
39
41
  The sitemap will become available at [http://localhost:4567/sitemap.xml](http://localhost:4567/sitemap.xml).
40
42
 
43
+ ## Excluding pages
44
+
45
+ You can add a `hide_from_sitemap` attribute to your page's frontmatter to omit it from the sitemap:
46
+
47
+ ```erb
48
+ ---
49
+ title: My hidden page
50
+ hide_from_sitemap: true
51
+ ---
52
+
53
+ Shh. Don't tell anyone I'm here.
54
+ ```
55
+
56
+ If you would like to use a different frontmatter attribute, you can specify it in the extension options:
57
+
58
+ ```ruby
59
+ activate :search_engine_sitemap, exclude_attr: 'hidden'
60
+ ```
61
+
62
+ You would then be able to use `hidden: true` in place of `hide_from_sitemap: true`.
63
+
41
64
  ### Settings
42
65
 
43
66
  Pages have a priority of 0.5 and a change frequency of `monthly` by default.
@@ -1,6 +1,6 @@
1
1
  xml.instruct!
2
2
  xml.urlset 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9' do
3
- sitemap.resources.select { |page| page.path.end_with?('.html') }.each do |page|
3
+ resources_for_sitemap.each do |page|
4
4
  xml.url do
5
5
  xml.loc File.join(url_root, page.url)
6
6
  xml.lastmod File.mtime(page.source_file).iso8601
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module SearchEngineSitemap
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0.pre"
4
4
  end
5
5
  end
@@ -10,6 +10,7 @@ module Middleman
10
10
  option :default_priority, 0.5, 'Default page priority for search engine sitemap'
11
11
  option :default_change_frequency, 'monthly', 'Default page priority for search engine sitemap'
12
12
  option :sitemap_xml_path, 'sitemap.xml', 'Path to search engine sitemap'
13
+ option :exclude_attr, 'hide_from_sitemap'
13
14
 
14
15
  def after_configuration
15
16
  register_extension_templates
@@ -19,8 +20,32 @@ module Middleman
19
20
  resources << sitemap_resource
20
21
  end
21
22
 
23
+ def resource_in_sitemap?(resource)
24
+ is_page?(resource) && not_excluded?(resource)
25
+ end
26
+
27
+ helpers do
28
+ def resources_for_sitemap
29
+ sitemap.resources.select do |resource|
30
+ extensions[:search_engine_sitemap].resource_in_sitemap?(resource)
31
+ end
32
+ end
33
+ end
34
+
22
35
  private
23
36
 
37
+ def is_page?(resource)
38
+ resource.path.end_with?(page_ext)
39
+ end
40
+
41
+ def not_excluded?(resource)
42
+ !resource.ignored? && !resource.data[options.exclude_attr]
43
+ end
44
+
45
+ def page_ext
46
+ File.extname(app.index_file)
47
+ end
48
+
24
49
  def register_extension_templates
25
50
  # We call reload_path to register the templates directory with Middleman.
26
51
  # The path given to app.files must be relative to the Middleman site's root.
@@ -0,0 +1,3 @@
1
+ ---
2
+ hide_from_sitemap: true
3
+ ---
File without changes
@@ -4,10 +4,12 @@ require 'nokogiri'
4
4
  describe "Search engine sitemaps", :feature do
5
5
  include XmlHelpers
6
6
 
7
- it "produces a sitemap" do
7
+ it "produces a valid sitemap" do
8
8
  run_site 'dummy' do
9
9
  set :url_root, 'http://example.com'
10
10
  activate :search_engine_sitemap
11
+
12
+ ignore '/ignored.html'
11
13
  end
12
14
 
13
15
  visit '/sitemap.xml'
@@ -33,6 +35,9 @@ describe "Search engine sitemaps", :feature do
33
35
  'priority' => '0.5',
34
36
  'changefreq' => 'daily'
35
37
  )
38
+
39
+ expect(doc.to_s).not_to include('http://example.com/ignored.html')
40
+ expect(doc.to_s).not_to include('http://example.com/ignored-in-frontmatter.html')
36
41
  end
37
42
 
38
43
  it "works with directory indexes" do
@@ -40,6 +45,8 @@ describe "Search engine sitemaps", :feature do
40
45
  set :url_root, 'http://example.com'
41
46
  activate :directory_indexes
42
47
  activate :search_engine_sitemap
48
+
49
+ ignore '/ignored.html'
43
50
  end
44
51
 
45
52
  visit '/sitemap.xml'
@@ -62,5 +69,8 @@ describe "Search engine sitemaps", :feature do
62
69
  'priority' => '0.5',
63
70
  'changefreq' => 'daily'
64
71
  )
72
+
73
+ expect(doc.to_s).not_to include('http://example.com/ignored/')
74
+ expect(doc.to_s).not_to include('http://example.com/ignored-in-frontmatter/')
65
75
  end
66
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-search_engine_sitemap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Nicholls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -116,6 +116,8 @@ files:
116
116
  - spec/dummy/source/about.html
117
117
  - spec/dummy/source/blog.html
118
118
  - spec/dummy/source/home.html
119
+ - spec/dummy/source/ignored-in-frontmatter.html
120
+ - spec/dummy/source/ignored.html
119
121
  - spec/dummy/source/layouts/layout.erb
120
122
  - spec/features/sitemap_feature_spec.rb
121
123
  - spec/spec_helper.rb
@@ -136,9 +138,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  required_rubygems_version: !ruby/object:Gem::Requirement
138
140
  requirements:
139
- - - ">="
141
+ - - ">"
140
142
  - !ruby/object:Gem::Version
141
- version: '0'
143
+ version: 1.3.1
142
144
  requirements: []
143
145
  rubyforge_project:
144
146
  rubygems_version: 2.2.2
@@ -149,6 +151,8 @@ test_files:
149
151
  - spec/dummy/source/about.html
150
152
  - spec/dummy/source/blog.html
151
153
  - spec/dummy/source/home.html
154
+ - spec/dummy/source/ignored-in-frontmatter.html
155
+ - spec/dummy/source/ignored.html
152
156
  - spec/dummy/source/layouts/layout.erb
153
157
  - spec/features/sitemap_feature_spec.rb
154
158
  - spec/spec_helper.rb