When I write a new post on Octopress, I share the link of it to somewhere doesn’t support hyperlinks. Since people can’t click the link, they should copy and paste or just type it letter by letter. I wanted to make it easier, so I maded short url for every post.
There is a Jekyll plugin that generates redirect pages for posts with aliases. Octopress is based on Jekyll and this plugin has no compatibility problem. Its source is on GitHub, so I just added it as submodule:
$ git submodule add [email protected]:tsmango/jekyll_alias_generator plugins/jekyll_alias_generator
_config.yml, you may have this line:
Then it reads
plugins directory and
plugins/jekyll_alias_generator/_plugins/ directory is also loaded, so you can use and manage it!
This plugin checks
alias inside every post’s YAML Front Matter. Just place the path of the alias:
--- layout: post title: "How to Add Redirects to Post URL on Octopress" alias: /p/20140523 ---
Multiple aliases are also available:
--- layout: post title: "How to Add Redirects to Post URL on Octopress" alias: [/one-alias/index.html, /another-alias/index.html] ---
rake generate, the plugin generates static html file at
<!DOCTYPE html> <html> <head> <link rel="canonical" href="/2014/05/23/how-to-add-redirects-to-post-url-on-octopress/"/> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="refresh" content="0;url=/2014/05/23/how-to-add-redirects-to-post-url-on-octopress/" /> </head> </html>