Code Monkey home page Code Monkey logo

jekyll-pageless-redirects's Introduction

Jekyll Pageless Redirects

Redirect any number of pages with one file. Supports htaccess style redirects.

Note: "Pageless" indicates you don't need to create new _pages or _posts to make the redirects occur. Pages are still generated and follow the tried and true http-equiv="refresh" method of redirection. This means the plugin will work on Github pages (if you generate your site and push it to gh-pages) or anywhere else that doesn't read .htaccess files.

Usage

Install pageless_redirects.rb in your plugins directory (_plugins in vanilla Jekyll, plugins in Octopress).

To generate redirects create _redirects.yml, _redirects.htaccess, and/or _redirects.json in the Jekyll root directory. All follow the pattern alias, final destination.

Sample _redirects.yml

initial-page   : /destination-page
other-page     : http://example.org/destination-page
"another/page" : /destination-page

Result

  • Requests to /initial-page are redirected to /destination-page
  • Requests to /other-page are redirected to http://example.org/destination-page
  • Requests to /another/page are redirected to /destination-page

Sample _redirects.htaccess

Redirect /some-page /destination-page
Redirect 301 /different-page /destination-page
Redirect cool-page http://example.org/destination-page

Result

  • Requests to /some-page are redirected to /destination-page
  • Requests to /different-page are redirected to /destination-page
  • Requests to /cool-page are redirected to http://example.org/destination-page

Sample _redirects.json

{
	"some-page"        : "/destination-page",
	"yet-another-page" : "http://example.org/destination-page",
	"ninth-page"       : "/destination-page"
}

Result

  • Requests to /some-page are redirected to /destination-page
  • Requests to /yet-another-page are redirected to http://example.org/destination-page
  • Requests to /ninth-page are redirected to /destination-page

Credit

This plugin borrows heavily from Jekyll Alias Generator by Thomas Mango

License

The MIT License (MIT)

Copyright (c) 2013 Nicholas Quinlan

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.

jekyll-pageless-redirects's People

Contributors

dcac avatar janslow avatar nquinlan avatar takuti avatar ws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jekyll-pageless-redirects's Issues

Redirect not working

Edit: I get the following error when serving locally: /Library/Ruby/Gems/2.0.0/gems/jekyll-2.1.1/lib/jekyll/cleaner.rb:59: stack level too deep (SystemStackError)
Removing the plugin from _plugins fixes this.

So I have added the plugin and redirect into my Jeykll repo

Custom domain: http://samdoidge.com

I use the master branch as from the github article:
For User Pages, use the master branch in your username.github.io repository. For Project Pages, use the gh-pages branch in your project's repository.

Outcome: 404 Error

Files and directories get deleted

I thought the plugin was not working for me at all.
But when I was debugging the generator, I saw that all directories and files are generated, but deleted at the end.

Any ideas why that could happen?

Redirects from pages without a trailing slash

Hi there,

Is there anyway to set redirects from pages without a trailing slash to pages including a trailing slash? For example, if I want to make a redirect from /kb/some-article to /kb/some-article/.

works on localhost but not live

I added the plugin to the _plugins directory and created a _redirects.htaccess file in root. It works on localhost, so I committed it and push to github master, but when I test it on live it doesn't redirect. Do you know what the issue could be?

Regular Expressions in the configuration

Hi @nquinlan
Is it possible to use regexps in the config?

I would need to set up redirects like this:

Redirect /pageA /pages/pageA
Redirect /pageB /pages/pageB
Redirect /pageC /pages/pageC
...
Redirect /page-ZZZ /pages/page-ZZZ

In .htaccess it would be like this:

RedirectMatch /(.+) /pages/$1 [R=301,L]

I catch bug: Stack level too deep

.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15: stack level too deep (SystemStackError)

i got this while i try to generate _site. Any ideas?

Wrong number of arguments in `load_file` call

I was getting an error when trying to build my jekyll site:

jekyll 2.0.3 | Error: wrong number of arguments (2 for 1)

When I added a traceback with jekyll build -t I was seeing the more detailed error:

/usr/lib/ruby/1.9.1/psych.rb:296:in `load_file': wrong number of arguments (2 for 1) (ArgumentError)

The problem seemed to be stemming from the following line in jekyll-pageless-redirects:

if File.exists?(file_path)
    YAML.load_file(file_path, :safe => true).each do | new_url, old_url |
      generate_aliases( old_url, new_url )
end

where YAML.load_file is passing two arguments instead of one. I'm not sure if it's down to my version of psych (2.0.5) but changing the line to:

if File.exists?(file_path)
    YAML.load_file(file_path).each do | new_url, old_url |
      generate_aliases( old_url, new_url )
end

has fixed the issue for me

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.