jekyll-absolute-links 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 56c531a208572d758809283df820b25555ce3901
4
+ data.tar.gz: c5ff0606703f9493027451de65aa6902bea0a144
5
+ SHA512:
6
+ metadata.gz: 17bed3637a0d412a36159afcf00676a528164d1df29aa2d0e125c62d0c8115867796733447f54ad61637394eece136b59b9b3d58742848a187ee1c03b05713a4
7
+ data.tar.gz: ebda7c60e74c4e9424d7b37cd865637112197ac160e2af77db97850fe688024b4aa1ebed4da2bddfd134ecda62755be7c815905172e00084f92ce93b0bde4139
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /spec/dest/
10
+ /tmp/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
14
+
15
+ Session.vim
16
+ .ruby-version
17
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --tty
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-absolute-links.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jose Miguel Venegas Mendoza
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.
@@ -0,0 +1,59 @@
1
+ # Jekyll Absolute Links
2
+
3
+ Absolute link converter for Jekyll sites. Crawls the generated HTML and XML
4
+ files in search of relative links and transform them to absolute links by
5
+ prepending the site domain.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your Gemfile:
10
+
11
+ ```ruby
12
+ gem "jekyll-absolute-links"
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```sh
18
+ $ bundle
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```sh
24
+ $ gem install jekyll-absolute-links
25
+ ```
26
+
27
+ Finally add this line to `gems` section in your `_config.yml` file:
28
+
29
+ ```yaml
30
+ gems:
31
+ - jekyll-absolute-links
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ There's really nothing more to do. Links will be transformed automatically for
37
+ production site only.
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
42
+ `rake spec` to run the tests. You can also run `bin/console` for an interactive
43
+ prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To
46
+ release a new version, update the version number in `version.rb`, and then run
47
+ `bundle exec rake release`, which will create a git tag for the version, push
48
+ git commits and tags, and push the `.gem` file to
49
+ [rubygems.org](https://rubygems.org).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at
54
+ https://github.com/rukbotto/jekyll-absolute-links.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT
59
+ License](http://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/jekyll-absolute-links/version", __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "jekyll-absolute-links"
6
+ spec.version = JekyllAbsoluteLinks::VERSION
7
+ spec.authors = ["Jose Miguel Venegas Mendoza"]
8
+ spec.email = ["jvenegasmendoza@gmail.com"]
9
+ spec.homepage = "https://github.com/rukbotto/jekyll-absolute-links"
10
+ spec.license = "MIT"
11
+
12
+ spec.summary = "Absolute link converter for Jekyll sites."
13
+ spec.description = <<-DESCRIPTION
14
+ Absolute link converter for Jekyll sites. Crawls the generated HTML and XML
15
+ files in search of relative links and transform them to absolute links by
16
+ prepending the site domain.
17
+ DESCRIPTION
18
+
19
+ spec.files = `git ls-files`.split("\n")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency("jekyll", "~> 3.3")
25
+
26
+ spec.add_development_dependency("bundler", "~> 1.14")
27
+ spec.add_development_dependency("rake", "~> 10.0")
28
+ spec.add_development_dependency("rspec", "~> 3.0")
29
+ end
@@ -0,0 +1,2 @@
1
+ require "jekyll"
2
+ require "jekyll-absolute-links/crawler"
@@ -0,0 +1,24 @@
1
+ module JekyllAbsoluteLinks
2
+ class Crawler
3
+ @regexp = %r{("|&quot;|>)(/[\w/.-]*)("|&quot;|<)}
4
+
5
+ Jekyll::Hooks.register :posts, :post_render do |post|
6
+ next if Jekyll::env == "development"
7
+ transform(post.output, @regexp, post.site.config["url"])
8
+ end
9
+
10
+ Jekyll::Hooks.register :pages, :post_render do |page|
11
+ next if Jekyll::env == "development"
12
+ transform(page.output, @regexp, page.site.config["url"])
13
+ end
14
+
15
+ class << self
16
+ private
17
+ def transform(output, regexp, site_url)
18
+ output.gsub!(regexp) do |match|
19
+ match.gsub($2, "#{site_url}#{$2}".sub(%r{(\w)/+}, "\\1/"))
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllAbsoluteLinks
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll-absolute-links"
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(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe(JekyllAbsoluteLinks::Crawler) do
4
+ let(:overrides) { Hash.new }
5
+ let(:site_config) do
6
+ Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
7
+ "source" => File.expand_path("../fixtures/absolute-links", __FILE__),
8
+ "destination" => File.expand_path("../dest", __FILE__)
9
+ }, overrides))
10
+ end
11
+ let(:site) { Jekyll::Site.new(site_config) }
12
+
13
+ before(:each) do
14
+ site.process
15
+ end
16
+
17
+ context("When development environment is active") do
18
+ describe("Crawler") do
19
+ it("performs no link transformation on posts") do
20
+ url = "\"/posts/curabitur-sed-condimentum-enim/\""
21
+ expect(site.posts[0].output).to include(url)
22
+ end
23
+
24
+ it("performs no link transformation on pages") do
25
+ url = "\"/posts/lorem-ipsum-dolor-sit-amet/\""
26
+ expect(site.pages[1].output).to include(url)
27
+ end
28
+
29
+ it("performs no link transformation on feeds") do
30
+ url = ">/posts/lorem-ipsum-dolor-sit-amet/<"
31
+ expect(site.pages[0].output).to include(url)
32
+ end
33
+
34
+ it("performs no encoded link transformation on feeds") do
35
+ url = "&quot;/posts/lorem-ipsum-dolor-sit-amet/&quot;"
36
+ expect(site.pages[0].output).to include(url)
37
+ end
38
+ end
39
+ end
40
+
41
+ context("When production environment is active") do
42
+ around(:each) do |example|
43
+ ENV["JEKYLL_ENV"] = "production"
44
+ example.run
45
+ end
46
+
47
+ describe("Crawler") do
48
+ it("transforms relative urls to absolute urls on posts") do
49
+ url = "\"http://example.com/posts/curabitur-sed-condimentum-enim/\""
50
+ expect(site.posts[0].output).to include(url)
51
+ end
52
+
53
+ it("transforms relative urls to absolute urls on pages") do
54
+ url = "\"http://example.com/posts/lorem-ipsum-dolor-sit-amet/\""
55
+ expect(site.pages[1].output).to include(url)
56
+ end
57
+
58
+ it("transforms relative urls to absolute urls on feeds") do
59
+ url = ">http://example.com/posts/lorem-ipsum-dolor-sit-amet/<"
60
+ expect(site.pages[0].output).to include(url)
61
+ end
62
+
63
+ it("transforms relative encoded urls to absolute urls on feeds") do
64
+ url = "&quot;http://example.com/posts/lorem-ipsum-dolor-sit-amet/&quot;"
65
+ expect(site.pages[0].output).to include(url)
66
+ end
67
+ end
68
+
69
+ context("And site domain has a trailing slash") do
70
+ let(:overrides) do
71
+ {
72
+ "url" => "http://example.com/"
73
+ }
74
+ end
75
+
76
+ describe("Crawler") do
77
+ it("Removes duplicate slashes from urls on posts") do
78
+ url = "\"http://example.com/posts/curabitur-sed-condimentum-enim/\""
79
+ expect(site.posts[0].output).to include(url)
80
+ end
81
+
82
+ it("Removes duplicate slashes from urls on pages") do
83
+ url = "\"http://example.com/posts/lorem-ipsum-dolor-sit-amet/\""
84
+ expect(site.pages[1].output).to include(url)
85
+ end
86
+
87
+ it("Removes duplicate slashes from urls on feeds") do
88
+ url = ">http://example.com/posts/lorem-ipsum-dolor-sit-amet/<"
89
+ expect(site.pages[0].output).to include(url)
90
+ end
91
+
92
+ it("Removes duplicate slashes from encoded urls on feeds") do
93
+ url = "&quot;http://example.com/posts/lorem-ipsum-dolor-sit-amet/&quot;"
94
+ expect(site.pages[0].output).to include(url)
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,15 @@
1
+ url: http://example.com
2
+
3
+ defaults:
4
+ - scope:
5
+ path: ""
6
+ type: posts
7
+ values:
8
+ layout: default
9
+ permalink: /posts/:title/
10
+
11
+ - scope:
12
+ path: ""
13
+ type: pages
14
+ values:
15
+ layout: default
@@ -0,0 +1,11 @@
1
+ ---
2
+ ---
3
+ <html>
4
+ <head>
5
+ <title>{{ page.title }}</title>
6
+ <meta name="description" content="{{ page.excerpt | strip_html }}">
7
+ </head>
8
+ <body>
9
+ {{ content }}
10
+ </body>
11
+ </html>
@@ -0,0 +1,11 @@
1
+ ---
2
+ title: Lorem ipsum dolor sit amet
3
+ ---
4
+
5
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis vitae imperdiet
6
+ magna. Maecenas suscipit quis nisi vel cursus. In hac habitasse platea
7
+ dictumst. Sed a mi eu magna semper porta. Donec mollis, leo sit amet elementum
8
+ egestas, est nibh euismod mauris, quis molestie libero ex in erat. [Curabitur
9
+ sed condimentum enim][link]
10
+
11
+ [link]: /posts/curabitur-sed-condimentum-enim/
@@ -0,0 +1,11 @@
1
+ ---
2
+ title: Curabitur sed condimentum enim
3
+ ---
4
+
5
+ Curabitur sed condimentum enim. Integer ut velit vitae ante facilisis
6
+ consequat. Nullam egestas ipsum sit amet nibh ornare, non consequat massa
7
+ dictum. Fusce porttitor iaculis velit elementum feugiat. Lorem ipsum dolor sit
8
+ amet, consectetur adipiscing elit. Morbi nisi tortor, aliquet et eros id,
9
+ cursus tincidunt sapien. [Lorem ipsum dolor sit amet][link]
10
+
11
+ [link]: /posts/lorem-ipsum-dolor-sit-amet/
@@ -0,0 +1,31 @@
1
+ ---
2
+ layout: null
3
+ permalink: /feed.xml
4
+ ---
5
+ <?xml version="1.0" encoding="UTF-8"?>
6
+ <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
7
+ <channel>
8
+ <title>{{ "Feed" | xml_escape }}</title>
9
+ <description>{{ "Feed" | xml_escape }}</description>
10
+ <link>/</link>
11
+ <atom:link href="{{ page.url }}" rel="self" type="application/rss+xml"/>
12
+ <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
13
+ <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
14
+ <generator>Jekyll v{{ jekyll.version }}</generator>
15
+ {% for post in site.posts limit:10 %}
16
+ <item>
17
+ <title>{{ post.title | xml_escape }}</title>
18
+ <description>{{ post.excerpt | xml_escape }}</description>
19
+ <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
20
+ <link>{{ post.url }}</link>
21
+ <guid isPermaLink="true">{{ post.url }}</guid>
22
+ {% for tag in post.tags %}
23
+ <category>{{ tag | xml_escape }}</category>
24
+ {% endfor %}
25
+ {% for cat in post.categories %}
26
+ <category>{{ cat | xml_escape }}</category>
27
+ {% endfor %}
28
+ </item>
29
+ {% endfor %}
30
+ </channel>
31
+ </rss>
@@ -0,0 +1,13 @@
1
+ ---
2
+ title: Morbi ultrices nulla
3
+ permalink: /morbi-ultrices-nulla/
4
+ ---
5
+
6
+ Morbi ultrices nulla et dolor auctor elementum. In lacinia, leo et dignissim
7
+ ornare, lectus odio lacinia nibh, nec vehicula nisi nulla a massa. Aliquam
8
+ vulputate, risus ut dapibus tristique, sem nibh posuere elit, id venenatis odio
9
+ dui non arcu. Duis ut justo consectetur, consequat odio vitae, vulputate urna.
10
+
11
+ [Lorem ipsum dolor sit amet][link]
12
+
13
+ [link]: /posts/lorem-ipsum-dolor-sit-amet/
@@ -0,0 +1,13 @@
1
+ require "bundler/setup"
2
+ require File.expand_path("../lib/jekyll-absolute-links", File.dirname(__FILE__))
3
+
4
+ Jekyll.logger.log_level = :error
5
+
6
+ RSpec.configure do |config|
7
+ # Enable flags like --only-failures and --next-failure
8
+ config.example_status_persistence_file_path = ".rspec_status"
9
+
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :expect
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-absolute-links
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jose Miguel Venegas Mendoza
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-27 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: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
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: |2
70
+ Absolute link converter for Jekyll sites. Crawls the generated HTML and XML
71
+ files in search of relative links and transform them to absolute links by
72
+ prepending the site domain.
73
+ email:
74
+ - jvenegasmendoza@gmail.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - LICENSE.md
84
+ - README.md
85
+ - Rakefile
86
+ - jekyll-absolute-links.gemspec
87
+ - lib/jekyll-absolute-links.rb
88
+ - lib/jekyll-absolute-links/crawler.rb
89
+ - lib/jekyll-absolute-links/version.rb
90
+ - script/console
91
+ - script/setup
92
+ - spec/crawler_spec.rb
93
+ - spec/fixtures/absolute-links/_config.yml
94
+ - spec/fixtures/absolute-links/_layouts/default.html
95
+ - spec/fixtures/absolute-links/_posts/2001-01-01-lorem-ipsum-dolor-sit-amet.md
96
+ - spec/fixtures/absolute-links/_posts/2001-01-02-curabitur-sed-condimentum-enim.md
97
+ - spec/fixtures/absolute-links/feed.xml
98
+ - spec/fixtures/absolute-links/morbi-ultrices-nulla.md
99
+ - spec/spec_helper.rb
100
+ homepage: https://github.com/rukbotto/jekyll-absolute-links
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.10
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Absolute link converter for Jekyll sites.
124
+ test_files:
125
+ - spec/crawler_spec.rb
126
+ - spec/fixtures/absolute-links/_config.yml
127
+ - spec/fixtures/absolute-links/_layouts/default.html
128
+ - spec/fixtures/absolute-links/_posts/2001-01-01-lorem-ipsum-dolor-sit-amet.md
129
+ - spec/fixtures/absolute-links/_posts/2001-01-02-curabitur-sed-condimentum-enim.md
130
+ - spec/fixtures/absolute-links/feed.xml
131
+ - spec/fixtures/absolute-links/morbi-ultrices-nulla.md
132
+ - spec/spec_helper.rb