Skip to content

Instantly share code, notes, and snippets.

@inky
Created July 6, 2011 17:46
Show Gist options
  • Save inky/1067860 to your computer and use it in GitHub Desktop.
Save inky/1067860 to your computer and use it in GitHub Desktop.
Jekyll plugin to selectively allow blog posts to use PHP.
Jekyll plugin to selectively allow blog posts to use PHP.
Copy php_posts.rb to your _plugins folder. Set 'php: yes' on a post, and
Jekyll will generate an 'index.php' file for it (rather than 'index.html').
This has only been tested with the following permalink format:
/:year/:title/
# Extending the Post class.
# See https://github.com/mojombo/jekyll/blob/master/lib/jekyll/post.rb
module Jekyll
class Post
# Rewrite to allow posts with .php extensions.
# Just set 'php: yes' in the YAML front matter.
def destination(dest)
# The url needs to be unescaped in order to preserve the correct filename
path = File.join(dest, CGI.unescape(self.url))
fn = (self.data['php']) ? 'index.php' : 'index.html'
path = File.join(path, fn) if template[/\.html$/].nil?
path
end
end
end
@garyrozanc
Copy link

This only works with permalinks set to "pretty" can you get this to work with permalinks set to "none"?

@garyrozanc
Copy link

Any chance you could update this to work with 3.2.1? The plugin stopped working with version 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment