jekyll-sitemap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jekyll-sitemap.rb +53 -0
- data/lib/sitemap.xml +27 -0
- data/lib/static_file.rb +21 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d3a165220778a80648f02febf36583691350cf38
|
4
|
+
data.tar.gz: 0480733be5165c40eae4459c333602f3163941cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 12b4ff869a137bf8a71f5ce0a19a5a47fafabe4b40c87055d3cd2d7d252225018da4238d44c6d499ec1dab202a3b1e2e99e693be780311f482c6d30fa0fa38f4
|
7
|
+
data.tar.gz: 0a7e3d9bef2ea241b0aa18a9b7153d34bc91cd087649a0198dd83ee3cec0c12cbe6ca20b3353e27002a527ca77ce8544b7e2b4137a31d9b3eb7ba29a94ff9cdc
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require File.expand_path('static_file', File.dirname(__FILE__))
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class JekyllSitemap < Jekyll::Generator
|
6
|
+
safe true
|
7
|
+
|
8
|
+
# Main plugin action, called by Jekyll-core
|
9
|
+
def generate(site)
|
10
|
+
@site = site
|
11
|
+
@site.config["time"] = Time.new
|
12
|
+
@site.config["static_files"] = html_files.map(&:to_liquid)
|
13
|
+
unless sitemap_exists?
|
14
|
+
write
|
15
|
+
@site.keep_files ||= []
|
16
|
+
@site.keep_files << "sitemap.xml"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Array of all non-jekyll site files with an HTML extension
|
21
|
+
def html_files
|
22
|
+
@site.static_files.select { |file| File.extname(file.relative_path) == ".html" }
|
23
|
+
end
|
24
|
+
|
25
|
+
# Path to sitemap.xml template file
|
26
|
+
def source_path
|
27
|
+
File.expand_path "sitemap.xml", File.dirname(__FILE__)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Destination for sitemap.xml file within the site source directory
|
31
|
+
def destination_path
|
32
|
+
File.expand_path "sitemap.xml", @site.dest
|
33
|
+
end
|
34
|
+
|
35
|
+
# copy sitemap template from source to destination
|
36
|
+
def write
|
37
|
+
FileUtils.mkdir_p File.dirname(destination_path)
|
38
|
+
File.open(destination_path, 'w') { |f| f.write(sitemap_content) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def sitemap_content
|
42
|
+
site_map = Page.new(@site, File.dirname(__FILE__), "", "sitemap.xml")
|
43
|
+
site_map.content = File.read(source_path)
|
44
|
+
site_map.render(@site.layouts, @site.site_payload)
|
45
|
+
site_map.output
|
46
|
+
end
|
47
|
+
|
48
|
+
# Checks if a sitemap already exists in the site source
|
49
|
+
def sitemap_exists?
|
50
|
+
File.exists? File.expand_path "sitemap.xml", @site.source
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/sitemap.xml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<?xml-stylesheet type="text/xsl" href="/sitemap.xsl"?>
|
3
|
+
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
4
|
+
{% capture site_url %}{% if site.url %}{{ site.url }}{% else %}{{ site.github.url }}{% endif %}{% endcapture %}
|
5
|
+
{% for post in site.posts %}
|
6
|
+
<url>
|
7
|
+
<loc>{{ site_url }}{{ post.url }}</loc>
|
8
|
+
<lastmod>{{ post.date | date_to_xmlschema }}</lastmod>
|
9
|
+
<priority>0.8</priority>
|
10
|
+
</url>
|
11
|
+
{% endfor %}
|
12
|
+
{% for post in site.pages %}
|
13
|
+
<url>
|
14
|
+
<loc>{{ site_url }}{{ post.url | replace:'index.html','' }}</loc>
|
15
|
+
<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>
|
16
|
+
<changefreq>weekly</changefreq>
|
17
|
+
<priority>{% if post.url == "/" or post.url == "/index.html" %}1.0{% else %}0.7{% endif %}</priority>
|
18
|
+
</url>
|
19
|
+
{% endfor %}
|
20
|
+
{% for file in site.static_files %}
|
21
|
+
<url>
|
22
|
+
<loc>{{ site_url }}{{ file.path }}</loc>
|
23
|
+
<lastmod>{{ file.modified_time | date_to_xmlschema }}</lastmod>
|
24
|
+
<priority>0.6</priority>
|
25
|
+
</url>
|
26
|
+
{% endfor %}
|
27
|
+
</urlset>
|
data/lib/static_file.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Monkey Patch Jekyll 2.0.0 static file treatment back to Jekyll 1.4.x
|
2
|
+
# See https://github.com/jekyll/jekyll/pull/2075/files
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class StaticFile
|
6
|
+
|
7
|
+
# Returns the source file path relative to the site source
|
8
|
+
def relative_path
|
9
|
+
@relative_path ||= path.sub(/\A#{@site.source}/, '')
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_liquid
|
13
|
+
{
|
14
|
+
"path" => relative_path,
|
15
|
+
"modified_time" => Time.at(mtime),
|
16
|
+
"extname" => File.extname(relative_path)
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-sitemap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- GitHub, Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.4.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.4.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
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: rake
|
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
|
+
description:
|
56
|
+
email: support@github.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files: []
|
60
|
+
files:
|
61
|
+
- lib/jekyll-sitemap.rb
|
62
|
+
- lib/sitemap.xml
|
63
|
+
- lib/static_file.rb
|
64
|
+
homepage: https://github.com/github/jekyll-sitemap
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.2.0
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Automatically generate a sitemap.xml for your Jekyll site.
|
88
|
+
test_files: []
|