jekyll-redirect-from-0.16.0/0000755000004100000410000000000013614127107015662 5ustar www-datawww-datajekyll-redirect-from-0.16.0/.travis.yml0000644000004100000410000000052113614127107017771 0ustar www-datawww-datalanguage: ruby cache: bundler rvm: - &latest_ruby 2.6 - 2.4 - 2.3 env: - JEKYLL_VERSION="~> 3.8" matrix: include: - # GitHub Pages rvm: 2.5.3 env: GH_PAGES=true - rvm: *latest_ruby env: JEKYLL_VERSION="~> 4.0" before_install: - gem update --system before_script: bundle update script: script/cibuild jekyll-redirect-from-0.16.0/jekyll-redirect-from.gemspec0000644000004100000410000000242013614127107023257 0ustar www-datawww-data# frozen_string_literal: true lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "jekyll-redirect-from/version" Gem::Specification.new do |spec| spec.name = "jekyll-redirect-from" spec.version = JekyllRedirectFrom::VERSION spec.authors = ["Parker Moore"] spec.email = ["parkrmoore@gmail.com"] spec.summary = "Seamlessly specify multiple redirection URLs " \ "for your pages and posts" spec.homepage = "https://github.com/jekyll/jekyll-redirect-from" spec.license = "MIT" # rubocop:disable Style/SpecialGlobalVars spec.files = `git ls-files`.split($/) # rubocop:enable Style/SpecialGlobalVars spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r!^(test|spec|features)/!) spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.4.0" spec.add_runtime_dependency "jekyll", ">= 3.3", "< 5.0" spec.add_development_dependency "bundler" spec.add_development_dependency "jekyll-sitemap", "~> 1.0" spec.add_development_dependency "rake", "~> 12.0" spec.add_development_dependency "rspec", "~> 3.5" spec.add_development_dependency "rubocop-jekyll", "~> 0.10" end jekyll-redirect-from-0.16.0/.rspec0000644000004100000410000000007713614127107017003 0ustar www-datawww-data--color --format progress --require spec_helper --order random jekyll-redirect-from-0.16.0/README.md0000644000004100000410000001063013614127107017141 0ustar www-datawww-data# JekyllRedirectFrom Give your Jekyll posts and pages multiple URLs. When importing your posts and pages from, say, Tumblr, it's annoying and impractical to create new pages in the proper subdirectories so they, e.g. `/post/123456789/my-slug-that-is-often-incompl`, redirect to the new post URL. Instead of dealing with maintaining those pages for redirection, let `jekyll-redirect-from` handle it for you. [![Build Status](https://travis-ci.org/jekyll/jekyll-redirect-from.svg?branch=master)](https://travis-ci.org/jekyll/jekyll-redirect-from) ## How it Works Redirects are performed by serving an HTML file with an HTTP-REFRESH meta tag which points to your destination. No `.htaccess` file, nginx conf, xml file, or anything else will be generated. It simply creates HTML files. ## Installation Add this line to your application's Gemfile: gem 'jekyll-redirect-from' And then execute: $ bundle Or install it yourself as: $ gem install jekyll-redirect-from Once it's installed into your evironment, add it to your `_config.yml`: ```yaml plugins: - jekyll-redirect-from ``` 💡 If you are using a Jekyll version less than 3.5.0, use the `gems` key instead of `plugins`. If you're using Jekyll in `safe` mode to mimic GitHub Pages, make sure to add jekyll-redirect-from to your whitelist: ```yaml whitelist: - jekyll-redirect-from ``` Then run `jekyll --safe` like normal. ## Usage The object of this gem is to allow an author to specify multiple URLs for a page, such that the alternative URLs redirect to the new Jekyll URL. To use it, simply add the array to the YAML front-matter of your page or post: ```yaml title: My amazing post redirect_from: - /post/123456789/ - /post/123456789/my-amazing-post/ ``` Redirects including a trailing slash will generate a corresponding subdirectory containing an `index.html`, while redirects without a trailing slash will generate a corresponding `filename` without an extension, and without a subdirectory. For example... ```text redirect_from: - /post/123456789/my-amazing-post ``` ...will generate the following page in the destination: ```text /post/123456789/my-amazing-post ``` While... ```text redirect_from: - /post/123456789/my-amazing-post/ ``` ...will generate the following page in the destination: ```text /post/123456789/my-amazing-post/index.html ``` These pages will contain an HTTP-REFRESH meta tag which redirect to your URL. You can also specify just **one url** like this: ```text title: My other awesome post redirect_from: /post/123456798/ ``` ### Prefix If `site.url` is set, its value, together with `site.baseurl`, is used as a prefix for the redirect url automatically. This is useful for scenarios where a site isn't available from the domain root, so the redirects point to the correct path. If `site.url` is not set, only `site.baseurl` is used, if set. **_Note_**: If you are hosting your Jekyll site on [GitHub Pages](https://pages.github.com/), and `site.url` is not set, the prefix is set to the pages domain name i.e. http://example.github.io/project or a custom CNAME. ### Redirect To Sometimes, you may want to redirect a site page to a totally different website. This plugin also supports that with the `redirect_to` key: ```yaml title: My amazing post redirect_to: http://www.github.com ``` **Note**: Using `redirect_to` or `redirect_from` with collections will only work with files which are output to HTML, such as `.md`, `.textile`, `.html` etc. ## Customizing the redirect template If you want to customize the redirect template, you can. Simply create a layout in your site's `_layouts` directory called `redirect.html`. Your layout will get the following variables: * `page.redirect.from` - the relative path to the redirect page * `page.redirect.to` - the absolute URL (where available) to the target page ## Configuration You can configure this plugin in `_config.yml` by adding to the `redirect_from` key. ### Disabling `redirects.json` By default, a file called `redirects.json`, which can be used for automated testing or to implement server-side redirects, will be included in the output. To exclude it from the output, set the `json` key to `false`: ```yml redirect_from: json: false ``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request jekyll-redirect-from-0.16.0/spec/0000755000004100000410000000000013614127107016614 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/0000755000004100000410000000000013614127107023012 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/redirect_page_spec.rb0000644000004100000410000001423013614127107027146 0ustar www-datawww-data# frozen_string_literal: true describe JekyllRedirectFrom::RedirectPage do let(:from) { "/foo" } let(:to) { "/bar" } let(:site_url) { site.config["url"] } subject { described_class.from_paths(site, from, to) } before { site.read } context "being a page" do before { subject.read_yaml(nil, nil, nil) } it "returns no content" do expect(subject.content).to eql("") end it "returns no output" do expect(subject.output).to eql("") end it "sets default data" do expect(subject.to_liquid["layout"]).to eql("redirect") expect(subject.to_liquid["sitemap"]).to be_falsey end end context "creating a page from paths" do it "sets the permalink" do expect(subject.to_liquid["permalink"]).to eql(from) end it "sets redirect metadata" do expect(subject.to_liquid).to have_key("redirect") expect(subject.to_liquid["redirect"]["from"]).to eql(from) expect(subject.to_liquid["redirect"]["to"]).to eql("#{site_url}#{to}") end context "with a document" do let(:doc) { site.documents.first } context "redirect from" do let(:page) { described_class.redirect_from(doc, from) } it "creates with redirect_from" do expect(page.to_liquid["permalink"]).to eql(from) expect(page.to_liquid).to have_key("redirect") expect(page.to_liquid["redirect"]["from"]).to eql(from) expected = "http://jekyllrb.com/2014/01/03/redirect-me-plz.html" expect(page.to_liquid["redirect"]["to"]).to eql(expected) end end context "redirect to" do let(:page) { described_class.redirect_to(doc, to) } context "redirecting to a path" do let(:to) { "/bar" } it "redirects" do expect(page.to_liquid["permalink"]).to eql("/2014/01/03/redirect-me-plz.html") expect(page.to_liquid).to have_key("redirect") expect(page.to_liquid["redirect"]["to"]).to eql("#{site_url}#{to}") expect(page.to_liquid["redirect"]["from"]).to eql("/2014/01/03/redirect-me-plz.html") end context "with no leading slash" do let(:to) { "bar" } it "redirects" do expect(page.to_liquid).to have_key("redirect") expect(page.to_liquid["redirect"]["to"]).to eql("#{site_url}/#{to}") end end context "with a trailing slash" do let(:to) { "/bar/" } it "redirects" do expect(page.to_liquid).to have_key("redirect") expect(page.to_liquid["redirect"]["to"]).to eql("#{site_url}#{to}") end end end context "redirecting to a URL" do let(:to) { "https://foo.invalid" } it "redirects" do expect(page.to_liquid["permalink"]).to eql("/2014/01/03/redirect-me-plz.html") expect(page.to_liquid).to have_key("redirect") expect(page.to_liquid["redirect"]["to"]).to eql("https://foo.invalid") expect(page.to_liquid["redirect"]["from"]).to eql("/2014/01/03/redirect-me-plz.html") end end end end end context "setting the paths" do let(:from) { "/foo2" } let(:to) { "/bar2" } before { subject.set_paths(from, to) } it "sets the paths" do expect(subject.to_liquid["permalink"]).to eql(from) expect(subject.to_liquid).to have_key("redirect") expect(subject.to_liquid["redirect"]["from"]).to eql(from) expect(subject.to_liquid["redirect"]["to"]).to eql("#{site_url}#{to}") end end context "generating" do before { site.generate } let(:output) { Jekyll::Renderer.new(site, subject, site.site_payload).run } it "renders the template" do expect(output).to_not be_nil expect(output.to_s).to_not be_empty end it "contains the meta refresh tag" do expect(output).to match("") end it "contains the javascript redirect" do expect(output).to match("") end it "contains canonical link in header" do expect(output).to match("") end it "contains the clickable link" do expect(output).to match("Click here if you are not redirected.") end end context "redirect from destination" do context "when redirect from has no extension" do let(:from) { "/foo" } it "adds .html" do expected = File.expand_path "foo.html", site.dest expect(subject.destination("/")).to eql(expected) end end context "when redirect from is a directory" do let(:from) { "/foo/" } it "knows to add the index.html" do expected = File.expand_path "foo/index.html", site.dest expect(subject.destination("/")).to eql(expected) end end context "when redirect from is an HTML file" do let(:from) { "/foo.html" } it "adds .html" do expected = File.expand_path "foo.html", site.dest expect(subject.destination("/")).to eql(expected) end end context "when redirect from is another extension" do let(:from) { "/foo.htm" } it "doesn't add .html" do expected = File.expand_path "foo.htm", site.dest expect(subject.destination("/")).to eql(expected) end end context "when redirect from has no leading slash" do let(:from) { "foo" } it "adds the slash" do expected = File.expand_path "foo.html", site.dest expect(subject.destination("/")).to eql(expected) end end end context "output extension" do context "with an extension" do let(:from) { "foo.htm" } it "honors the extension" do expect(subject.output_ext).to eql(".htm") end end context "with a trailing slash" do let(:from) { "foo/" } it "uses HTML" do expect(subject.output_ext).to eql(".html") end end context "with no slash" do let(:from) { "foo" } it "uses HTML" do expect(subject.output_ext).to eql(".html") end end end end jekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/layout_spec.rb0000644000004100000410000000141113614127107025663 0ustar www-datawww-data# frozen_string_literal: true RSpec.describe JekyllRedirectFrom::Layout do subject { described_class.new(@site) } it "exposes the site" do expect(subject.site).to eql(@site) end it "exposes the name" do expect(subject.name).to eql("redirect.html") end it "exposes the path" do expected = File.expand_path "../../lib/jekyll-redirect-from/redirect.html", __dir__ expect(subject.path).to eql(expected) end it "exposes the relative path" do expect(subject.relative_path).to eql("_layouts/redirect.html") end it "exposes the ext" do expect(subject.ext).to eql("html") end it "exposes data" do expect(subject.data).to eql({}) end it "exposes content" do expect(subject.content).to match("Redirecting...") end end jekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/redirectable_spec.rb0000644000004100000410000000267413614127107027007 0ustar www-datawww-data# frozen_string_literal: true class RedirectableTestHelper include JekyllRedirectFrom::Redirectable attr_reader :to_liquid def initialize(data) @to_liquid = data end end RSpec.describe JekyllRedirectFrom::Redirectable do let(:data) { "" } subject { RedirectableTestHelper.new(data) } context "with strings" do let(:data) { { "redirect_from" => "/foo", "redirect_to" => "/bar" } } it "returns redirect_from" do expect(subject.redirect_from).to eql(["/foo"]) end it "returns redirect_to" do expect(subject.redirect_to).to eql("/bar") end end context "with arrays" do let(:data) { { "redirect_from" => ["/foo"], "redirect_to" => ["/bar"] } } it "returns redirect_from" do expect(subject.redirect_from).to eql(["/foo"]) end it "returns redirect_to" do expect(subject.redirect_to).to eql("/bar") end end context "with fields missing" do let(:data) { {} } it "returns an empty array for redirect_from" do expect(subject.redirect_from).to eql([]) end it "returns nil for redirect_to" do expect(subject.redirect_to).to be_nil end end context "with nils" do let(:data) { { "redirect_from" => nil, "redirect_to" => nil } } it "returns an empty array for redirect_from" do expect(subject.redirect_from).to eql([]) end it "returns nil for redirect_to" do expect(subject.redirect_to).to be_nil end end end jekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/generator_spec.rb0000644000004100000410000001207213614127107026341 0ustar www-datawww-data# frozen_string_literal: true RSpec.describe JekyllRedirectFrom::Generator do before(:each) do site.read site.generate site.render site.write end context "layouts" do context "a site with a redirect layout" do before { site.layouts["redirect"] = "foo" } it "doesn't inject the layout" do expect(site.layouts["redirect"]).to eql("foo") end end context "a site without a redirect layout" do it "injects the layout" do expect(site.layouts["redirect"]).to be_a(JekyllRedirectFrom::Layout) end end end context "redirect froms" do context "pages" do context "a page with a single redirect" do let(:page) { site.pages.find { |p| p.url == "/some/other/path" } } it "creates the redirect" do expect(page).to_not be_nil expect(page.output).to match("http://jekyllrb.com/one_redirect_from.html") end end context "a page with multiple redirects" do let(:redirects) do ["/help", "/contact", "/let-there/be/light-he-said", "/geepers/mccreepin"] end it "creates all the redirects" do redirects.each do |url| page = site.pages.find { |p| p.url == url } expect(page).to_not be_nil expect(page.output).to match("http://jekyllrb.com/multiple_redirect_froms.html") end end end end context "documents" do let(:page) { site.pages.find { |p| p.url == "/articles/23128432159832/mary-had-a-little-lamb" } } it "redirects" do expect(page).to_not be_nil expect(page.output).to match("http://jekyllrb.com/articles/redirect-me-plz.html") end end end context "redirect tos" do context "pages" do context "a single redirect to" do let(:page) { site.pages.find { |p| p.url == "/one_redirect_to_url.html" } } it "redirects" do expect(page.output).to match("https://www.github.com") end end context "multiple redirect tos" do let(:page) { site.pages.find { |p| p.url == "/multiple_redirect_tos.html" } } it "redirects to the first entry" do expect(page.output).to match("https://www.jekyllrb.com") end end end context "documents" do let(:doc) { site.documents.find { |p| p.url == "/articles/redirect-somewhere-else-plz.html" } } it "redirects" do expect(doc.output).to match("http://www.zombo.com") end end end context "redirects.json" do let(:path) { dest_dir("redirects.json") } let(:contents) { File.read(path) } let(:redirects) { JSON.parse(contents) } let(:domain) { "http://jekyllrb.com" } it "creates the redirects file" do expect(path).to exist end it "contains redirects" do expect(redirects.count).to eql(13) end it "contains single redirects tos" do expect(redirects.keys).to include "/one_redirect_to_path.html" expect(redirects["/one_redirect_to_path.html"]).to eql("#{domain}/foo") end it "contains multiple redirect tos" do expect(redirects.keys).to include "/multiple_redirect_tos.html" expect(redirects["/multiple_redirect_tos.html"]).to eql("https://www.jekyllrb.com") end it "contains single redirect froms" do expect(redirects.keys).to include "/some/other/path" expect(redirects["/some/other/path"]).to eql("#{domain}/one_redirect_from.html") end it "contains multiple redirect froms" do expect(redirects.keys).to include "/help" expect(redirects["/help"]).to eql("#{domain}/multiple_redirect_froms.html") expect(redirects.keys).to include "/contact" expect(redirects["/contact"]).to eql("#{domain}/multiple_redirect_froms.html") end context "with a user-supplied redirects.json" do let(:source_path) { File.join fixtures_path, "redirects.json" } before do File.write source_path, { "foo" => "bar" }.to_json site.reset site.read site.generate site.render site.write end after do FileUtils.rm_f source_path end it "doesn't overwrite redirects.json" do expect(path).to exist expect(redirects).to eql("foo" => "bar") end end context "when explicitly disabled" do let(:site) { Jekyll::Site.new(config.merge("redirect_from" => { "json" => false })) } it "does not create the redirects file" do expect(path).to_not exist end end end context "redirectable_document?" do let(:generator) { JekyllRedirectFrom::Generator.new } it "accepts subclasses of Jekyll::Document" do SubclassOfJekyllDocument = Class.new(Jekyll::Document) { define_method(:initialize) {} } expect(generator.send(:redirectable_document?, SubclassOfJekyllDocument.new)).to be_truthy end it "accepts subclasses of Jekyll::Page" do SubclassOfJekyllPage = Class.new(Jekyll::Page) { define_method(:initialize) {} } expect(generator.send(:redirectable_document?, SubclassOfJekyllPage.new)).to be_truthy end end end jekyll-redirect-from-0.16.0/spec/jekyll_redirect_from/context_spec.rb0000644000004100000410000000053313614127107026036 0ustar www-datawww-data# frozen_string_literal: true RSpec.describe JekyllRedirectFrom::Context do subject { described_class.new(site) } it "stores the site" do expect(subject.site).to be_a(Jekyll::Site) end it "returns the register" do expect(subject.registers).to have_key(:site) expect(subject.registers[:site]).to be_a(Jekyll::Site) end end jekyll-redirect-from-0.16.0/spec/fixtures/0000755000004100000410000000000013614127107020465 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/tags/0000755000004100000410000000000013614127107021423 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/tags/how we work.md0000644000004100000410000000011213614127107024073 0ustar www-datawww-data--- redirect_to: "/tags/how-we-work/" permalink: "/tags/how we work/" --- jekyll-redirect-from-0.16.0/spec/fixtures/one_redirect_to_path.md0000644000004100000410000000012713614127107025167 0ustar www-datawww-data--- title: I am going somewhere external redirect_to: /foo --- Redirecting elsewhere. jekyll-redirect-from-0.16.0/spec/fixtures/one_redirect_from.md0000644000004100000410000000013613614127107024474 0ustar www-datawww-data--- title: I only have one redirect path redirect_from: some/other/path --- One redirect url jekyll-redirect-from-0.16.0/spec/fixtures/_layouts/0000755000004100000410000000000013614127107022324 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/_layouts/layout.html0000644000004100000410000000005013614127107024522 0ustar www-datawww-data--- --- LAYOUT INCLUDED {{ content }} jekyll-redirect-from-0.16.0/spec/fixtures/one_redirect_to_url.md0000644000004100000410000000015113614127107025032 0ustar www-datawww-data--- title: I am going somewhere external redirect_to: https://www.github.com --- Redirecting elsewhere. jekyll-redirect-from-0.16.0/spec/fixtures/_articles/0000755000004100000410000000000013614127107022432 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/_articles/redirect-me-plz.md0000644000004100000410000000015513614127107025760 0ustar www-datawww-data--- title: Please redirect me, sir. redirect_from: /articles/23128432159832/mary-had-a-little-lamb --- Yay. jekyll-redirect-from-0.16.0/spec/fixtures/_articles/redirect-somewhere-else-im-a-permalink.html0000644000004100000410000000020413614127107032640 0ustar www-datawww-data--- title: Please redirect away from me and my permalink. permalink: /tags/our projects/ redirect_to: /tags/our-projects/ --- Bye. jekyll-redirect-from-0.16.0/spec/fixtures/_articles/redirect-somewhere-else-plz.html0000644000004100000410000000013413614127107030644 0ustar www-datawww-data--- title: Please redirect away from me, sir. redirect_to: "http://www.zombo.com" --- Boo. jekyll-redirect-from-0.16.0/spec/fixtures/multiple_redirect_tos.md0000644000004100000410000000024513614127107025411 0ustar www-datawww-data--- title: I have lots of redirect to urls redirect_to: - https://www.jekyllrb.com - https://www.github.com - https://www.twitter.com --- Lots of redirect to urls. jekyll-redirect-from-0.16.0/spec/fixtures/multiple_redirect_froms.md0000644000004100000410000000022513614127107025730 0ustar www-datawww-data--- title: I have lots of redirect urls redirect_from: - help - contact - let-there/be/light-he-said - /geepers/mccreepin --- Lots of redirect urls jekyll-redirect-from-0.16.0/spec/fixtures/_authors/0000755000004100000410000000000013614127107022311 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/_authors/kansaichris.md0000644000004100000410000000005213614127107025127 0ustar www-datawww-data--- redirect_from: /kansaichris/ --- Hi. jekyll-redirect-from-0.16.0/spec/fixtures/_posts/0000755000004100000410000000000013614127107021774 5ustar www-datawww-datajekyll-redirect-from-0.16.0/spec/fixtures/_posts/2014-01-03-redirect-me-plz.md0000644000004100000410000000015213614127107026341 0ustar www-datawww-data--- title: Please redirect me, sir. redirect_from: /posts/23128432159832/mary-had-a-little-lamb --- Yay. jekyll-redirect-from-0.16.0/spec/spec_helper.rb0000644000004100000410000000231113614127107021427 0ustar www-datawww-data# frozen_string_literal: true require "jekyll" require File.expand_path("lib/jekyll-redirect-from.rb") RSpec.configure do |config| config.run_all_when_everything_filtered = true config.filter_run :focus config.expect_with :rspec do |c| c.syntax = :expect end config.before(:each) do Jekyll.logger.log_level = :error dest_path.rmtree if dest_path.exist? site.reset end config.after(:each) do dest_path.rmtree if dest_path.exist? end def fixtures_path Pathname.new(__dir__).join("fixtures") end def dest_path Pathname.new(site.dest) end def dest_dir(*paths) dest_path.join(*paths) end def config Jekyll.configuration( "source" => fixtures_path.to_s, "destination" => fixtures_path.join("_site").to_s, "collections" => { "articles" => { "output" => true }, "authors" => {}, }, "url" => "http://jekyllrb.com", "plugins" => [ "jekyll-redirect-from", "jekyll-sitemap", ], "defaults" => [{ "scope" => { "path" => "" }, "values" => { "layout" => "layout" }, }] ) end def site @site ||= Jekyll::Site.new(config) end end jekyll-redirect-from-0.16.0/spec/integrations_spec.rb0000644000004100000410000000466513614127107022674 0ustar www-datawww-data# frozen_string_literal: true RSpec.describe "JekyllRedirectFrom integration tests" do before { site.process } let(:relative_path) { "" } let(:path) { dest_dir(relative_path) } let(:contents) { File.read(path) } context "pages" do context "single redirect from" do let(:relative_path) { "some/other/path.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://jekyllrb.com/one_redirect_from.html") end end context "multiple redirect froms" do %w(help contact let-there/be/light-he-said geepers/mccreepin).each do |redirect| context "the #{redirect} redirect" do let(:relative_path) { "#{redirect}.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://jekyllrb.com/multiple_redirect_froms.html") end end end end context "a redirect to URL" do let(:relative_path) { "one_redirect_to_url.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("https://www.github.com") end end context "a redirect to path" do let(:relative_path) { "one_redirect_to_path.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://jekyllrb.com/foo") end end end context "documents" do context "a single redirect from" do let(:relative_path) { "articles/23128432159832/mary-had-a-little-lamb.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://jekyllrb.com/articles/redirect-me-plz.html") end end context "redirect to" do let(:relative_path) { "articles/redirect-somewhere-else-plz.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://www.zombo.com") end end context "with a permalink" do let(:relative_path) { "tags/our projects/index.html" } it "exists in the built site" do expect(path).to exist expect(contents).to match("http://jekyllrb.com/tags/our-projects/") end end end context "sitemap" do let(:relative_path) { "sitemap.xml" } it "doesn't contain redirects" do expect(contents).to_not be_nil expect(contents).to_not match("redirect_to") end end end jekyll-redirect-from-0.16.0/.rubocop.yml0000644000004100000410000000024613614127107020136 0ustar www-datawww-datainherit_from: .rubocop_todo.yml require: rubocop-jekyll inherit_gem: rubocop-jekyll: .rubocop.yml AllCops: TargetRubyVersion: 2.4 Exclude: - vendor/**/* jekyll-redirect-from-0.16.0/.gitignore0000644000004100000410000000034313614127107017652 0ustar www-datawww-data*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports spec/fixtures/.jekyll-metadata spec/fixtures/.jekyll-cache test/tmp test/version_tmp tmp vendor/bundle jekyll-redirect-from-0.16.0/script/0000755000004100000410000000000013614127107017166 5ustar www-datawww-datajekyll-redirect-from-0.16.0/script/test0000755000004100000410000000003713614127107020073 0ustar www-datawww-data#!/bin/sh bundle exec rspec $@ jekyll-redirect-from-0.16.0/script/release0000755000004100000410000000006613614127107020536 0ustar www-datawww-data#! /bin/bash script/cibuild bundle exec rake release jekyll-redirect-from-0.16.0/script/cibuild0000755000004100000410000000010313614127107020521 0ustar www-datawww-data#! /bin/bash set -e script/test script/fmt bundle exec rake build jekyll-redirect-from-0.16.0/script/bootstrap0000755000004100000410000000007213614127107021130 0ustar www-datawww-data#! /bin/bash set -e bundle install -j8 || bundle install jekyll-redirect-from-0.16.0/script/fmt0000755000004100000410000000034013614127107017677 0ustar www-datawww-data#!/bin/bash set -e echo "Rubocop $(bundle exec rubocop --version)" bundle exec rubocop -D -E $@ success=$? if ((success != 0)); then echo -e "\nTry running \`script/fmt -a\` to automatically fix errors" fi exit $success jekyll-redirect-from-0.16.0/.rubocop_todo.yml0000644000004100000410000000305513614127107021164 0ustar www-datawww-data# This configuration was generated by # `rubocop --auto-gen-config` # on 2018-12-06 11:51:19 +0100 using RuboCop version 0.61.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 12 # Configuration parameters: CountComments, Max, ExcludedMethods. # ExcludedMethods: refine Metrics/BlockLength: Exclude: - 'spec/integrations_spec.rb' - 'spec/jekyll_redirect_from/generator_spec.rb' - 'spec/jekyll_redirect_from/redirect_page_spec.rb' - 'spec/jekyll_redirect_from/redirectable_spec.rb' - 'spec/spec_helper.rb' # Offense count: 3 # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Exclude: - 'spec/jekyll_redirect_from/generator_spec.rb' - 'spec/jekyll_redirect_from/redirect_page_spec.rb' # Offense count: 1 # Configuration parameters: EnforcedStyleForLeadingUnderscores. # SupportedStylesForLeadingUnderscores: disallowed, required, optional Naming/MemoizedInstanceVariableName: Exclude: - 'lib/jekyll-redirect-from/page_without_a_file.rb' # Offense count: 2 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. # AllowedNames: io, id, to, by, on, in, at, ip, db Naming/UncommunicativeMethodParamName: Exclude: - 'lib/jekyll-redirect-from/redirect_page.rb' jekyll-redirect-from-0.16.0/Rakefile0000644000004100000410000000022413614127107017325 0ustar www-datawww-data# frozen_string_literal: true require "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) task :default => :spec jekyll-redirect-from-0.16.0/lib/0000755000004100000410000000000013614127107016430 5ustar www-datawww-datajekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/0000755000004100000410000000000013614127107022462 5ustar www-datawww-datajekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/version.rb0000644000004100000410000000012213614127107024467 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom VERSION = "0.16.0" end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect_page.rb0000644000004100000410000000375713614127107025620 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom # Specialty page which implements the redirect path logic class RedirectPage < Jekyll::Page # Use Jekyll's native absolute_url filter include Jekyll::Filters::URLFilters DEFAULT_DATA = { "sitemap" => false, "layout" => "redirect", }.freeze # Creates a new RedirectPage instance from a source path and redirect path # # site - The Site object # from - the (URL) path, relative to the site root to redirect from # to - the relative path or URL which the page should redirect to def self.from_paths(site, from, to) page = RedirectPage.new(site, site.source, "", "redirect.html") page.set_paths(from, to) page end # Creates a new RedirectPage instance from the path to the given doc def self.redirect_from(doc, path) RedirectPage.from_paths(doc.site, path, doc.url) end # Creates a new RedirectPage instance from the doc to the given path def self.redirect_to(doc, path) RedirectPage.from_paths(doc.site, doc.url, path) end # Overwrite the default read_yaml method since the file doesn't exist def read_yaml(_base, _name, _opts = {}) self.content = self.output = "" self.data ||= DEFAULT_DATA.dup end # Helper function to set the appropriate path metadata # # from - the relative path to the redirect page # to - the relative path or absolute URL to the redirect target def set_paths(from, to) @context ||= context from = ensure_leading_slash(from) data.merge!( "permalink" => from, "redirect" => { "from" => from, "to" => %r!^https?://!.match?(to) ? to : absolute_url(to), } ) end def redirect_from data["redirect"]["from"] if data["redirect"] end def redirect_to data["redirect"]["to"] if data["redirect"] end private def context JekyllRedirectFrom::Context.new(site) end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/page_without_a_file.rb0000644000004100000410000000023313614127107027003 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom class PageWithoutAFile < Jekyll::Page def read_yaml(*) @data ||= {} end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/context.rb0000644000004100000410000000043413614127107024474 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom # Stubbed LiquidContext to support relative_url and absolute_url helpers class Context attr_reader :site def initialize(site) @site = site end def registers { :site => site } end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/layout.rb0000644000004100000410000000077513614127107024335 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom # A stubbed layout for our default redirect template # We cannot use the standard Layout class because of site.in_source_dir class Layout < Jekyll::Layout def initialize(site) @site = site @base = __dir__ @name = "redirect.html" @path = File.expand_path(@name, @base) @relative_path = "_layouts/redirect.html" self.data = {} self.ext = "html" self.content = File.read(@path) end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirect.html0000644000004100000410000000066113614127107025154 0ustar www-datawww-data Redirecting…

Redirecting…

Click here if you are not redirected. jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/redirectable.rb0000644000004100000410000000143713614127107025441 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom # Module which can be mixed in to documents (and pages) to provide # redirect_to and redirect_from helpers module Redirectable # Returns a string representing the relative path or URL # to which the document should be redirected def redirect_to if to_liquid["redirect_to"].is_a?(Array) to_liquid["redirect_to"].compact.first else to_liquid["redirect_to"] end end # Returns an array representing the relative paths to other # documents which should be redirected to this document def redirect_from if to_liquid["redirect_from"].is_a?(Array) to_liquid["redirect_from"].compact else [to_liquid["redirect_from"]].compact end end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from/generator.rb0000644000004100000410000000340213614127107024774 0ustar www-datawww-data# frozen_string_literal: true module JekyllRedirectFrom class Generator < Jekyll::Generator safe true attr_reader :site, :redirects def generate(site) @site = site @redirects = {} # Inject our layout, unless the user has already specified a redirect layout' unless site.layouts.key?("redirect") site.layouts["redirect"] = JekyllRedirectFrom::Layout.new(site) end # Must duplicate pages to modify while in loop (site.docs_to_write + site.pages.dup).each do |doc| next unless redirectable_document?(doc) generate_redirect_from(doc) generate_redirect_to(doc) end generate_redirects_json if generate_redirects_json? end private # For every `redirect_from` entry, generate a redirect page def generate_redirect_from(doc) doc.redirect_from.each do |path| page = RedirectPage.redirect_from(doc, path) doc.site.pages << page redirects[page.redirect_from] = page.redirect_to end end def generate_redirect_to(doc) return unless doc.redirect_to page = RedirectPage.redirect_to(doc, doc.redirect_to) doc.data.merge!(page.data) doc.content = doc.output = page.output redirects[page.redirect_from] = page.redirect_to end def generate_redirects_json return if File.exist? site.in_source_dir("redirects.json") page = PageWithoutAFile.new(site, "", "", "redirects.json") page.content = redirects.to_json page.data["layout"] = nil site.pages << page end def redirectable_document?(doc) doc.is_a?(Jekyll::Document) || doc.is_a?(Jekyll::Page) end def generate_redirects_json? site.config.dig("redirect_from", "json") != false end end end jekyll-redirect-from-0.16.0/lib/jekyll-redirect-from.rb0000644000004100000410000000126413614127107023012 0ustar www-datawww-data# frozen_string_literal: true require "jekyll" require "jekyll-redirect-from/version" require "jekyll-redirect-from/generator" module JekyllRedirectFrom # Jekyll classes which should be redirectable CLASSES = [Jekyll::Page, Jekyll::Document].freeze autoload :Context, "jekyll-redirect-from/context" autoload :RedirectPage, "jekyll-redirect-from/redirect_page" autoload :Redirectable, "jekyll-redirect-from/redirectable" autoload :Layout, "jekyll-redirect-from/layout" autoload :PageWithoutAFile, "jekyll-redirect-from/page_without_a_file" end JekyllRedirectFrom::CLASSES.each do |klass| klass.send :include, JekyllRedirectFrom::Redirectable end jekyll-redirect-from-0.16.0/History.markdown0000644000004100000410000001056413614127107021075 0ustar www-datawww-data## 0.16.0 / 2020-01-26 ### Minor Enhancements * Allows generation of `redirects.json` to be disabled (#207) * Allow redirects from and for subclasses of page and document (#204) ### Bug Fixes * Use `Hash#key?` instead of `Hash#keys.any?` (#201) ### Development Fixes * Target Ruby 2.4 * Stop testing with backwards-compatible site config (#211) ### Documentation * Simplifies YAML for `redirect_to` (#185) ## 0.15.0 / 2019-03-23 ### Development Fixes * chore(deps): rubocop-jekyll 0.3 (#187) ### Bug Fixes * Allow testing and using with Jekyll 4.x (#196) ## 0.14.0 / 2018-06-29 ### Minor Enhancements * Run javascript at first to avoid splash (#158) ### Development Fixes * Use Rubocop 0.57 * Target Ruby 2.3 * Test against Ruby 2.5 (#173) ## 0.13.0 / 2017-12-03 * Test against same version of Ruby that GitHub Pages uses (#132) ### Development Fixes * Rubocop (#141) * Fix tests for jekyll 3.5.x (#160) * Rubocop: autocorrect (#165) ### Minor Enhancements * HTML encode ellipsis (#142) * Added no-index to template (#152) * Define path with __dir__ (#161) ### Major Enhancements * Create redirects.json file (#147) ### Documentation * Update README.md (#167) ## 0.12.1 / 2017-01-12 ### Development Fixes * Stop testing Ruby 1.9 (#133) ### Minor Enhancements * Use send to monkey patch to support Ruby < 2.2.0 (#136) * set `page.output` to empty string instead of nil (#137) ## 0.12.0 / 2017-01-02 ### Major Enhancements * Support for custom redirect templates * Use Jekyll's `absolute_url` filter to generate canonical URLs (now respecting `baseurl`) * Rely more heavily on Jekyll's native Page, permalink, and extension handling logic ### Minor Enhancementse * redirect_to Pages should not have a layout. (#115) * Require Jekyll >= 3.3 ### Development Enhancements * Push redirect logic to the redirect page model (#131) * Add Rubocop and enforce Jekyll coding standards * Tests no longer build and write the entire site between each example * Removed all the `is_*`? and `has_*`? helpers from the generator ## 0.11.0 / 2016-07-06 * Redirect page should not have any layout (#106) * Include absolute path in canonical url (#109) * Add tag and language (#100) * Ensure redirect_to links produce an HTML file. (#111) ## 0.10.0 / 2016-03-16 * Ensure output extension is assigned (#96) ## 0.9.1 / 2015-12-11 * Enforce double-quote strings to pass htmlhint (#83) * Stringify all values coming from `site.github` (#89) ## 0.9.0 / 2015-10-28 * Support Jekyll 3 stable (#76) * Test against Jekyll 3, 2, and GitHub Pages (#72) ## 0.8.0 / 2015-05-20 * Exclude redirect pages from sitemap (#69) ## 0.7.0 / 2015-03-16 * Remove spaces in redirect page (#62) * Only parse through documents/pages/posts (#56) * Simplified `has_alt_urls?` and `has_redirect_to_url?` conditions (#52) * Add support for Jekyll 3. (#59) ## 0.6.2 / 2014-09-12 * Fixed error where `redirect_to` `Document`s were not being output properly (#46) ## 0.6.1 / 2014-09-08 * Fixed error when the `site.github` config key is not a `Hash` (#43) ## 0.6.0 / 2014-08-22 * Support redirecting to/from collection documents (#40) ## 0.5.0 / 2014-08-10 ### Minor Enhancements * Support `redirect_to` property (#32) * Automatically prefix redirects with the `baseurl` or GitHub URL. (#26) ### Bug Fixes * Remove unnecessary `Array#flatten` (#34) ### Development Fixes * Use `be_truthy` instead of `be_true`. (#33) ## 0.4.0 / 2014-05-06 ### Major Enhancements * Upgrade to Jekyll 2.0 (#27) ### Minor Enhancements * Shorten resulting HTML to make redirects quicker (#20) ### Development Fixes * Use SVG Travis badge in README (#21) ## 0.3.1 / 2014-01-22 ### Bug Fixes * Add `safe true` to the `Jekyll::Generator` so it can be run in safe mode (#12) ## 0.3.0 / 2014-01-15 ### Major Enhancements * `redirect_from` items are now proper permalinks rooted in site source (#8) ### Development Fixes * Add forgotten `s` to `gems` in README.md (#7) ## 0.2.0 / 2014-01-04 ### Minor Enhancements * Allow user to set one or many `redirect_from` URLs * Rename from `jekyll-alt-urls` to `jekyll-redirect-from` (props to @benbalter) * Namespace now its own module: `JekyllRedirectFrom` (#3) ### Development Fixes * Add history file * Add specs (#3) * Add TravisCI badge (#4) ## 0.1.0 / 2013-12-15 * Birthday! jekyll-redirect-from-0.16.0/Gemfile0000644000004100000410000000025113614127107017153 0ustar www-datawww-data# frozen_string_literal: true source "https://rubygems.org" gemspec gem "github-pages" if ENV["GH_PAGES"] gem "jekyll", ENV["JEKYLL_VERSION"] if ENV["JEKYLL_VERSION"] jekyll-redirect-from-0.16.0/LICENSE.txt0000644000004100000410000000213313614127107017504 0ustar www-datawww-dataCopyright (c) 2013-present Parker Moore and jekyll-redirect-from contributors MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.