spinto 0.2.10 → 0.2.11
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.
- data/_plugins/sitemap_generator.rb +275 -0
- data/bin/spinto-site +4 -1
- data/lib/spinto.rb +1 -1
- data/spinto.gemspec +3 -2
- metadata +18 -17
@@ -0,0 +1,275 @@
|
|
1
|
+
# https://github.com/kinnetica/jekyll-plugins/blob/master/sitemap_generator.rb
|
2
|
+
#
|
3
|
+
# Sitemap.xml Generator is a Jekyll plugin that generates a sitemap.xml file by
|
4
|
+
# traversing all of the available posts and pages.
|
5
|
+
# pke: modified to use site.config['sitemap']['url'] instead of MY_URL
|
6
|
+
#
|
7
|
+
# How To Use:
|
8
|
+
# 1.) Copy source file into your _plugins folder within your Jekyll project.
|
9
|
+
# 2.) Set url or sitemap: url to reflect your domain name.
|
10
|
+
# 3.) Set sitemap: filename if you want your sitemap to be called something
|
11
|
+
# other than sitemap.xml.
|
12
|
+
# 4.) Change the PAGES_INCLUDE_POSTS list to include any pages that are looping
|
13
|
+
# through your posts (e.g. "index.html", "archive.html", etc.). This will
|
14
|
+
# ensure that right after you make a new post, the last modified date will
|
15
|
+
# be updated to reflect the new post.
|
16
|
+
# 5.) Run Jekyll: jekyll --server to re-generate your site.
|
17
|
+
# 6.) A sitemap.xml should be included in your _site folder.
|
18
|
+
#
|
19
|
+
# Customizations:
|
20
|
+
# 1.) If there are any files you don't want included in the sitemap, add them
|
21
|
+
# to the EXCLUDED_FILES list. The name should match the name of the source
|
22
|
+
# file.
|
23
|
+
# 2.) If you want to include the optional changefreq and priority attributes,
|
24
|
+
# simply include custom variables in the YAML Front Matter of that file.
|
25
|
+
# The names of these custom variables are defined below in the
|
26
|
+
# CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME and PRIORITY_CUSTOM_VARIABLE_NAME
|
27
|
+
# constants.
|
28
|
+
#
|
29
|
+
# Notes:
|
30
|
+
# 1.) The last modified date is determined by the latest from the following:
|
31
|
+
# system modified date of the page or post, system modified date of
|
32
|
+
# included layout, system modified date of included layout within that
|
33
|
+
# layout, ...
|
34
|
+
#
|
35
|
+
# Author: Michael Levin
|
36
|
+
# Site: http://www.kinnetica.com
|
37
|
+
# Distributed Under A Creative Commons License
|
38
|
+
# - http://creativecommons.org/licenses/by/3.0/
|
39
|
+
|
40
|
+
require 'rexml/document'
|
41
|
+
|
42
|
+
module Jekyll
|
43
|
+
|
44
|
+
# Change SITEMAP_FILE_NAME if you would like your sitemap file
|
45
|
+
# to be called something else
|
46
|
+
SITEMAP_FILE_NAME = "sitemap.xml"
|
47
|
+
|
48
|
+
# Any files to exclude from being included in the sitemap.xml
|
49
|
+
EXCLUDED_FILES = []
|
50
|
+
|
51
|
+
# Custom variable names for changefreq and priority elements
|
52
|
+
# These names are used within the YAML Front Matter of pages or posts
|
53
|
+
# for which you want to include these properties
|
54
|
+
CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME = "change_frequency"
|
55
|
+
PRIORITY_CUSTOM_VARIABLE_NAME = "priority"
|
56
|
+
|
57
|
+
# Recover from strange exception when starting server without --auto
|
58
|
+
class SitemapFile < StaticFile
|
59
|
+
def write(dest)
|
60
|
+
begin
|
61
|
+
super(dest)
|
62
|
+
rescue
|
63
|
+
end
|
64
|
+
|
65
|
+
true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class SitemapGenerator < Generator
|
70
|
+
|
71
|
+
# Valid values allowed by sitemap.xml spec for change frequencies
|
72
|
+
VALID_CHANGE_FREQUENCY_VALUES = ["always", "hourly", "daily", "weekly",
|
73
|
+
"monthly", "yearly", "never"]
|
74
|
+
|
75
|
+
# Goes through pages and posts and generates sitemap.xml file
|
76
|
+
#
|
77
|
+
# Returns nothing
|
78
|
+
def generate(site)
|
79
|
+
sitemap = REXML::Document.new << REXML::XMLDecl.new("1.0", "UTF-8")
|
80
|
+
|
81
|
+
urlset = REXML::Element.new "urlset"
|
82
|
+
urlset.add_attribute("xmlns",
|
83
|
+
"http://www.sitemaps.org/schemas/sitemap/0.9")
|
84
|
+
|
85
|
+
@last_modified_post_date = fill_posts(site, urlset)
|
86
|
+
fill_pages(site, urlset)
|
87
|
+
|
88
|
+
sitemap.add_element(urlset)
|
89
|
+
|
90
|
+
# Create destination directory if it doesn't exist yet. Otherwise, we cannot write our file there.
|
91
|
+
Dir::mkdir(site.dest) if !File.directory? site.dest
|
92
|
+
|
93
|
+
# File I/O: create sitemap.xml file and write out pretty-printed XML
|
94
|
+
filename = site.config['sitemap']['filename'] if site.config['sitemap']
|
95
|
+
filename ||= SITEMAP_FILE_NAME
|
96
|
+
file = File.new(File.join(site.dest, filename), "w")
|
97
|
+
formatter = REXML::Formatters::Pretty.new(4)
|
98
|
+
formatter.compact = true
|
99
|
+
formatter.write(sitemap, file)
|
100
|
+
file.close
|
101
|
+
|
102
|
+
# Keep the sitemap.xml file from being cleaned by Jekyll
|
103
|
+
site.static_files << Jekyll::SitemapFile.new(site, site.dest, "/", filename)
|
104
|
+
end
|
105
|
+
|
106
|
+
# Create url elements for all the posts and find the date of the latest one
|
107
|
+
#
|
108
|
+
# Returns last_modified_date of latest post
|
109
|
+
def fill_posts(site, urlset)
|
110
|
+
last_modified_date = nil
|
111
|
+
site.posts.each do |post|
|
112
|
+
if !excluded?(post.name)
|
113
|
+
url = fill_url(site, post)
|
114
|
+
urlset.add_element(url)
|
115
|
+
end
|
116
|
+
|
117
|
+
path = ".#{post.path_to_source}"
|
118
|
+
date = File.mtime(path)
|
119
|
+
last_modified_date = date if last_modified_date == nil or date > last_modified_date
|
120
|
+
end
|
121
|
+
|
122
|
+
last_modified_date
|
123
|
+
end
|
124
|
+
|
125
|
+
# Create url elements for all the normal pages and find the date of the
|
126
|
+
# index to use with the pagination pages
|
127
|
+
#
|
128
|
+
# Returns last_modified_date of index page
|
129
|
+
def fill_pages(site, urlset)
|
130
|
+
site.pages.each do |page|
|
131
|
+
if !excluded?(page.name)
|
132
|
+
path = ".#{page.path_to_source}"
|
133
|
+
if File.exists?(path)
|
134
|
+
url = fill_url(site, page)
|
135
|
+
urlset.add_element(url)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Fill data of each URL element: location, last modified,
|
142
|
+
# change frequency (optional), and priority.
|
143
|
+
#
|
144
|
+
# Returns url REXML::Element
|
145
|
+
def fill_url(site, page_or_post)
|
146
|
+
url = REXML::Element.new "url"
|
147
|
+
|
148
|
+
loc = fill_location(site, page_or_post)
|
149
|
+
url.add_element(loc)
|
150
|
+
|
151
|
+
lastmod = fill_last_modified(site, page_or_post)
|
152
|
+
url.add_element(lastmod) if lastmod
|
153
|
+
|
154
|
+
if (page_or_post.data[CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME])
|
155
|
+
change_frequency =
|
156
|
+
page_or_post.data[CHANGE_FREQUENCY_CUSTOM_VARIABLE_NAME].downcase
|
157
|
+
|
158
|
+
if (valid_change_frequency?(change_frequency))
|
159
|
+
changefreq = REXML::Element.new "changefreq"
|
160
|
+
changefreq.text = change_frequency
|
161
|
+
url.add_element(changefreq)
|
162
|
+
else
|
163
|
+
puts "ERROR: Invalid Change Frequency In #{page_or_post.name}"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
if (page_or_post.data[PRIORITY_CUSTOM_VARIABLE_NAME])
|
168
|
+
priority_value = page_or_post.data[PRIORITY_CUSTOM_VARIABLE_NAME]
|
169
|
+
if valid_priority?(priority_value)
|
170
|
+
priority = REXML::Element.new "priority"
|
171
|
+
priority.text = page_or_post.data[PRIORITY_CUSTOM_VARIABLE_NAME]
|
172
|
+
url.add_element(priority)
|
173
|
+
else
|
174
|
+
puts "ERROR: Invalid Priority In #{page_or_post.name}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
url
|
179
|
+
end
|
180
|
+
|
181
|
+
# Get URL location of page or post
|
182
|
+
#
|
183
|
+
# Returns the location of the page or post
|
184
|
+
def fill_location(site, page_or_post)
|
185
|
+
loc = REXML::Element.new "loc"
|
186
|
+
url = site.config['sitemap']['url'] if site.config['sitemap']
|
187
|
+
url ||= site.config['url']
|
188
|
+
loc.text = "#{url[-1..-1] == '/' ? url[0..-2] : url}#{page_or_post.location_on_server}"
|
189
|
+
|
190
|
+
loc
|
191
|
+
end
|
192
|
+
|
193
|
+
# Fill lastmod XML element with the last modified date for the page or post.
|
194
|
+
#
|
195
|
+
# Returns lastmod REXML::Element or nil
|
196
|
+
def fill_last_modified(site, page_or_post)
|
197
|
+
path = ".#{page_or_post.path_to_source}"
|
198
|
+
|
199
|
+
lastmod = REXML::Element.new "lastmod"
|
200
|
+
date = File.mtime(path)
|
201
|
+
latest_date = find_latest_date(date, site, page_or_post)
|
202
|
+
|
203
|
+
case page_or_post
|
204
|
+
when Jekyll::Page
|
205
|
+
final_date = greater_date(latest_date, @last_modified_post_date)
|
206
|
+
lastmod.text = final_date.iso8601
|
207
|
+
else
|
208
|
+
lastmod.text = latest_date.iso8601
|
209
|
+
end
|
210
|
+
lastmod
|
211
|
+
end
|
212
|
+
|
213
|
+
# Go through the page/post and any implemented layouts and get the latest
|
214
|
+
# modified date
|
215
|
+
#
|
216
|
+
# Returns formatted output of latest date of page/post and any used layouts
|
217
|
+
def find_latest_date(latest_date, site, page_or_post)
|
218
|
+
layouts = site.layouts
|
219
|
+
layout = layouts[page_or_post.data["layout"]]
|
220
|
+
while layout
|
221
|
+
path = ".#{layout.path_to_source}"
|
222
|
+
date = File.mtime(path)
|
223
|
+
|
224
|
+
latest_date = date if (date > latest_date)
|
225
|
+
|
226
|
+
layout = layouts[layout.data["layout"]]
|
227
|
+
end
|
228
|
+
|
229
|
+
latest_date
|
230
|
+
end
|
231
|
+
|
232
|
+
# Which of the two dates is later
|
233
|
+
#
|
234
|
+
# Returns latest of two dates
|
235
|
+
def greater_date(date1, date2)
|
236
|
+
if (date1 >= date2)
|
237
|
+
date1
|
238
|
+
else
|
239
|
+
date2
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# Is the page or post listed as something we want to exclude?
|
244
|
+
#
|
245
|
+
# Returns boolean
|
246
|
+
def excluded?(name)
|
247
|
+
name_frags = name.split('.')
|
248
|
+
EXCLUDED_FILES.include?(name) || !(name_frags.last == name || %q{html markdown textile}.include?(name_frags.last))
|
249
|
+
end
|
250
|
+
|
251
|
+
def posts_included?(name)
|
252
|
+
PAGES_INCLUDE_POSTS.include? name
|
253
|
+
end
|
254
|
+
|
255
|
+
# Is the change frequency value provided valid according to the spec
|
256
|
+
#
|
257
|
+
# Returns boolean
|
258
|
+
def valid_change_frequency?(change_frequency)
|
259
|
+
VALID_CHANGE_FREQUENCY_VALUES.include? change_frequency
|
260
|
+
end
|
261
|
+
|
262
|
+
# Is the priority value provided valid according to the spec
|
263
|
+
#
|
264
|
+
# Returns boolean
|
265
|
+
def valid_priority?(priority)
|
266
|
+
begin
|
267
|
+
priority_val = Float(priority)
|
268
|
+
return true if priority_val >= 0.0 and priority_val <= 1.0
|
269
|
+
rescue ArgumentError
|
270
|
+
end
|
271
|
+
|
272
|
+
false
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
data/bin/spinto-site
CHANGED
@@ -44,6 +44,10 @@ opts = OptionParser.new do |opts|
|
|
44
44
|
options['url'] = url
|
45
45
|
end
|
46
46
|
|
47
|
+
opts.on("--[no-]pygments", "Use pygments to highlight code (true at Spinto)") do |pygments|
|
48
|
+
options['pygments'] = pygments
|
49
|
+
end
|
50
|
+
|
47
51
|
opts.on("--version", "Display current version") do
|
48
52
|
puts "Spinto " + Spinto::VERSION
|
49
53
|
exit 0
|
@@ -69,7 +73,6 @@ end
|
|
69
73
|
|
70
74
|
options['safe'] = false
|
71
75
|
options['plugins'] = Spinto::PLUGINS_PATH
|
72
|
-
options['pygments'] = true
|
73
76
|
|
74
77
|
options = Jekyll.configuration(options)
|
75
78
|
|
data/lib/spinto.rb
CHANGED
data/spinto.gemspec
CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
|
|
4
4
|
s.rubygems_version = '1.3.5'
|
5
5
|
|
6
6
|
s.name = 'spinto'
|
7
|
-
s.version = '0.2.
|
8
|
-
s.date = '2012-04-
|
7
|
+
s.version = '0.2.11'
|
8
|
+
s.date = '2012-04-24'
|
9
9
|
|
10
10
|
s.summary = "The site generator used at spintoapp.com"
|
11
11
|
s.description = "Spinto uses Jekyll and plugins to build static sites, this gem provides the spinto-site builder."
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
_plugins/less_converter.rb
|
43
43
|
_plugins/sass_converter.rb
|
44
44
|
_plugins/scss_converter.rb
|
45
|
+
_plugins/sitemap_generator.rb
|
45
46
|
bin/spinto-site
|
46
47
|
lib/spinto.rb
|
47
48
|
spinto.gemspec
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spinto
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spinto-jekyll
|
16
|
-
requirement: &
|
16
|
+
requirement: &2180915740 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - =
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.11.2.3
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2180915740
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: coffee-script
|
27
|
-
requirement: &
|
27
|
+
requirement: &2180915280 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - =
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2180915280
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sass
|
38
|
-
requirement: &
|
38
|
+
requirement: &2180914820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.1.15
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2180914820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: less
|
49
|
-
requirement: &
|
49
|
+
requirement: &2180914360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - =
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 2.1.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2180914360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: RedCloth
|
60
|
-
requirement: &
|
60
|
+
requirement: &2180913900 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - =
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 4.2.9
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2180913900
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
|
-
requirement: &
|
71
|
+
requirement: &2180913440 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0.9'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2180913440
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rdoc
|
82
|
-
requirement: &
|
82
|
+
requirement: &2180912980 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '3.11'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2180912980
|
91
91
|
description: Spinto uses Jekyll and plugins to build static sites, this gem provides
|
92
92
|
the spinto-site builder.
|
93
93
|
email: matt.beale@madhatted.com
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- _plugins/less_converter.rb
|
107
107
|
- _plugins/sass_converter.rb
|
108
108
|
- _plugins/scss_converter.rb
|
109
|
+
- _plugins/sitemap_generator.rb
|
109
110
|
- bin/spinto-site
|
110
111
|
- lib/spinto.rb
|
111
112
|
- spinto.gemspec
|
@@ -124,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
125
|
version: '0'
|
125
126
|
segments:
|
126
127
|
- 0
|
127
|
-
hash: -
|
128
|
+
hash: -1798746641388548046
|
128
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
130
|
none: false
|
130
131
|
requirements:
|