Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge commit 'mojombo/master'

Conflicts:
	lib/jekyll.rb
	lib/jekyll/post.rb

Remove --permalink-date option now that an equivalent is built in.
  • Loading branch information...
commit 94aa73d04671d3d1bd7c9680223d2e819f63cfa1 2 parents 1d42b39 + bad2d17
@henrik henrik authored
View
19 README.textile
@@ -1,5 +1,9 @@
h1. Jekyll
+By Tom Preston-Werner, Nick Quaranto, and many awesome contributors!
+
+h2. Description
+
Jekyll is a simple, blog aware, static site generator. It takes a template
directory (representing the raw form of a website), runs it through Textile or
Markdown and Liquid converters, and spits out a complete, static website
@@ -226,19 +230,6 @@ Then tell Jekyll not to add '.html' when linking to blog posts, like so:
Note that this has no effect with '--permalink pretty' since that makes an index.html
file in a directory.
-
-h3. Permalink Date Format
-
-By default, unless you set the --permalink option to 'none', permalinks begin
-with the date in a 'YYYY/MM/DD' format.
-
-To customize this format, pass --permalink-date a strftime type format string.
-
- $ jekyll --permalink-date [format string]
-
-For example, to use only the year and month in the slug:
-
- $ jekyll --permalink-date %Y/%m
h2. Configuration File
@@ -630,7 +621,7 @@ your changes merged back into core is as follows:
# Do not change the version number, I will do that on my end
# If necessary, rebase your commits into logical chunks, without errors
# Push the branch up to GitHub
-# Send me (mojombo) a pull request for your branch
+# Create an issue on mojombo/grit with a description and link to your branch
h2. License
View
8 bin/jekyll
@@ -10,7 +10,7 @@ Basic Command Line Usage:
jekyll <path to write generated site> # . -> <path>
jekyll <path to source> <path to write generated site> # <path> -> <path>
- Configuration is read from '<source>/_config.yaml' but can be overriden
+ Configuration is read from '<source>/_config.yml' but can be overriden
using the following options:
HELP
@@ -60,10 +60,6 @@ opts = OptionParser.new do |opts|
options['multiviews'] = true
end
- opts.on("--permalink-date [FORMAT]", 'A strftime type format string. No times. (default format %Y/%m/%d)') do |format|
- options['permalink_date'] = format unless format.nil?
- end
-
opts.on("--sass", "Use Sass from haml gem for CSS generation") do
options['sass'] = true
end
@@ -157,4 +153,4 @@ if options['server']
trap("INT") { s.shutdown }
t.join()
-end
+end
View
54 features/permalinks.feature
@@ -0,0 +1,54 @@
+Feature: Fancy permalinks
+ As a hacker who likes to blog
+ I want to be able to set permalinks
+ In order to make my blog URLs awesome
+
+ Scenario: Use none permalink schema
+ Given I have a _posts directory
+ And I have the following post:
+ | title | date | content |
+ | None Permalink Schema | 3/27/2009 | Totally nothing. |
+ And I have a configuration file with "permalink" set to "none"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Totally nothing." in "_site/none-permalink-schema.html"
+
+ Scenario: Use pretty permalink schema
+ Given I have a _posts directory
+ And I have the following post:
+ | title | date | content |
+ | Pretty Permalink Schema | 3/27/2009 | Totally wordpress. |
+ And I have a configuration file with "permalink" set to "pretty"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Totally wordpress." in "_site/2009/03/27/pretty-permalink-schema/index.html"
+
+ Scenario: Use custom permalink schema with prefix
+ Given I have a _posts directory
+ And I have the following post:
+ | title | category | date | content |
+ | Custom Permalink Schema | stuff | 3/27/2009 | Totally custom. |
+ And I have a configuration file with "permalink" set to "/blog/:year/:month/:day/:title"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Totally custom." in "_site/blog/2009/03/27/custom-permalink-schema/index.html"
+
+ Scenario: Use custom permalink schema with category
+ Given I have a _posts directory
+ And I have the following post:
+ | title | category | date | content |
+ | Custom Permalink Schema | stuff | 3/27/2009 | Totally custom. |
+ And I have a configuration file with "permalink" set to "/:categories/:title.html"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Totally custom." in "_site/stuff/custom-permalink-schema.html"
+
+ Scenario: Use custom permalink schema with squished date
+ Given I have a _posts directory
+ And I have the following post:
+ | title | category | date | content |
+ | Custom Permalink Schema | stuff | 3/27/2009 | Totally custom. |
+ And I have a configuration file with "permalink" set to "/:month-:day-:year/:title.html"
+ When I run jekyll
+ Then the _site directory should exist
+ And I should see "Totally custom." in "_site/03-27-2009/custom-permalink-schema.html"
View
20 features/site_configuration.feature
@@ -32,26 +32,6 @@ Feature: Site configuration
Then the _site directory should exist
And I should see "<a href='http://google.com'>Google</a>" in "_site/index.html"
- Scenario: Use none permalink schema
- Given I have a _posts directory
- And I have the following post:
- | title | date | content |
- | None Permalink Schema | 3/27/2009 | Totally nothing. |
- And I have a configuration file with "permalink" set to "none"
- When I run jekyll
- Then the _site directory should exist
- And I should see "Totally nothing." in "_site/none-permalink-schema.html"
-
- Scenario: Use pretty permalink schema
- Given I have a _posts directory
- And I have the following post:
- | title | date | content |
- | Pretty Permalink Schema | 3/27/2009 | Totally wordpress. |
- And I have a configuration file with "permalink" set to "pretty"
- When I run jekyll
- Then the _site directory should exist
- And I should see "Totally wordpress." in "_site/2009/03/27/pretty-permalink-schema/index.html"
-
Scenario: Highlight code with pygments
Given I have an "index.html" file that contains "{% highlight ruby %} puts 'Hello world!' {% endhighlight %}"
And I have a configuration file with "pygments" set to "true"
View
4 lib/jekyll.rb
@@ -27,7 +27,7 @@
require 'jekyll/albino'
module Jekyll
- # Default options. Overriden by values in _config.yaml or command-line opts.
+ # Default options. Overriden by values in _config.yml or command-line opts.
# Strings are used instead of symbols for YAML compatibility.
DEFAULTS = {
'auto' => false,
@@ -62,7 +62,7 @@ def self.configuration(override)
# then, we need to know where to look for _config.yml
source = override['source'] || Jekyll::DEFAULTS['source']
- # Get configuration from <source>/_config.yaml
+ # Get configuration from <source>/_config.yml
config = {}
config_file = File.join(source, '_config.yml')
begin
View
65 lib/jekyll/post.rb
@@ -20,9 +20,12 @@ def self.valid?(name)
name =~ MATCHER
end
- attr_accessor :site
- attr_accessor :date, :slug, :ext, :categories, :tags, :topics, :published
- attr_accessor :data, :content, :output
+ attr_accessor :site, :date, :slug, :ext, :topics, :tags, :published, :data, :content, :output
+ attr_writer :categories
+
+ def categories
+ @categories ||= []
+ end
# Initialize this Post instance.
# +site+ is the Site
@@ -97,16 +100,7 @@ def process(name)
#
# Returns <String>
def dir
- if permalink
- permalink.to_s.split("/")[0..-2].join("/") + '/'
- else
- prefix = self.categories.empty? ? '' : '/' + self.categories.join('/')
- if [:date, :pretty].include?(self.site.permalink_style)
- prefix + date.strftime(self.site.permalink_date || "/%Y/%m/%d/")
- else
- prefix + '/'
- end
- end
+ File.dirname(generated_path)
end
# The full path and filename of the post.
@@ -118,13 +112,43 @@ def permalink
self.data && self.data['permalink']
end
- # The generated relative url of this post
+ def template
+ case self.site.permalink_style
+ when :pretty
+ "/:categories/:year/:month/:day/:title"
+ when :none
+ "/:categories/:title.html"
+ when :date
+ "/:categories/:year/:month/:day/:title.html"
+ else
+ self.site.permalink_style.to_s
+ end
+ end
+
+ # The generated relative path of this post
# e.g. /2008/11/05/my-awesome-post.html
#
# Returns <String>
+ def generated_path
+ return permalink if permalink
+
+ @generated_path ||= {
+ "year" => date.strftime("%Y"),
+ "month" => date.strftime("%m"),
+ "day" => date.strftime("%d"),
+ "title" => slug,
+ "categories" => categories.sort.join('/')
+ }.inject(template) { |result, token|
+ result.gsub(/:#{token.first}/, token.last)
+ }.gsub("//", "/")
+ end
+
+ # The generated relative url of this post
+ # e.g. /2008/11/05/my-awesome-post
+ #
+ # Returns <String>
def url
- ext = (site.permalink_style == :pretty || site.config['multiviews']) ? '' : '.html'
- permalink || self.id + ext
+ site.config['multiviews'] ? generated_path.sub(/\.html$/, '') : generated_path
end
# The UID for this post (useful in feeds)
@@ -132,7 +156,7 @@ def url
#
# Returns <String>
def id
- self.dir + self.slug
+ File.join(self.dir, self.slug)
end
# The post title
@@ -209,14 +233,11 @@ def render(layouts, site_payload)
def write(dest)
FileUtils.mkdir_p(File.join(dest, dir))
- path = File.join(dest, self.url)
+ path = File.join(dest, self.generated_path)
- if self.site.permalink_style == :pretty
+ if template[/\.html$/].nil?
FileUtils.mkdir_p(path)
path = File.join(path, "index.html")
- else
- # Ensure .html extension even if URL doesn't have it, e.g. with --multiviews.
- path.sub!(/(\.html)?$/, '.html')
end
File.open(path, 'w') do |f|
View
3  lib/jekyll/site.rb
@@ -2,7 +2,7 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :collated_posts, :categories, :tags
- attr_accessor :source, :dest, :lsi, :pygments, :pygments_cache, :permalink_style, :permalink_date,
+ attr_accessor :source, :dest, :lsi, :pygments, :pygments_cache, :permalink_style,
:sass, :post_defaults
# Initialize the site
@@ -18,7 +18,6 @@ def initialize(config)
self.pygments = config['pygments']
self.pygments_cache = config['pygments_cache']
self.permalink_style = config['permalink'].to_sym
- self.permalink_date = config['permalink_date'] && config['permalink_date'].sub(%r{\A/?(.*)/?\Z}, '/\1/')
self.post_defaults = config['post_defaults'] || {}
self.reset
View
95 test/test_post.rb
@@ -25,6 +25,7 @@ def do_render(post)
assert !Post.valid?("blah")
end
+
context "processing posts" do
setup do
@post = Post.allocate
@@ -41,6 +42,8 @@ def do_render(post)
assert_equal Time.parse("2008-10-19"), @post.date
assert_equal "foo-bar", @post.slug
assert_equal ".textile", @post.ext
+ assert_equal "/2008/10/19", @post.dir
+ assert_equal "/2008/10/19/foo-bar", @post.id
end
should "create url based on date and title" do
@@ -49,16 +52,94 @@ def do_render(post)
assert_equal "/2008/10/19/foo-bar.html", @post.url
end
- should "respect permalink" do
+ should "respect permalink in yaml front matter" do
file = "2008-12-03-permalinked-post.textile"
@post.process(file)
@post.read_yaml(@source, file)
assert_equal "my_category/permalinked-post", @post.permalink
- assert_equal "my_category/", @post.dir
+ assert_equal "my_category", @post.dir
assert_equal "my_category/permalinked-post", @post.url
end
+ context "with site wide permalink" do
+ setup do
+ @post.categories = []
+ end
+
+ context "with unspecified (date) style" do
+ setup do
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
+ assert_equal "/2008/10/19/foo-bar.html", @post.url
+ end
+ end
+
+ context "with unspecified (date) style and a category" do
+ setup do
+ @post.categories << "beer"
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
+ assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
+ end
+ end
+
+ context "with unspecified (date) style and categories" do
+ setup do
+ @post.categories << "food"
+ @post.categories << "beer"
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
+ assert_equal "/beer/food/2008/10/19/foo-bar.html", @post.url
+ end
+ end
+
+ context "with none style" do
+ setup do
+ @post.site.permalink_style = :none
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:categories/:title.html", @post.template
+ assert_equal "/foo-bar.html", @post.url
+ end
+ end
+
+ context "with pretty style" do
+ setup do
+ @post.site.permalink_style = :pretty
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/:categories/:year/:month/:day/:title", @post.template
+ assert_equal "/2008/10/19/foo-bar", @post.url
+ end
+ end
+
+ context "with prefix style and no extension" do
+ setup do
+ @post.site.permalink_style = "/prefix/:title"
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/prefix/:title", @post.template
+ assert_equal "/prefix/foo-bar", @post.url
+ end
+ end
+ end
+
should "read yaml front-matter" do
@post.read_yaml(@source, @real_file)
@@ -144,6 +225,16 @@ def do_render(post)
assert File.exists?(File.join(dest_dir, '2008', '10', '18', 'foo-bar.html'))
end
+ should "write properly without html extension" do
+ post = setup_post("2008-10-18-foo-bar.textile")
+ post.site.permalink_style = ":title"
+ do_render(post)
+ post.write(dest_dir)
+
+ assert File.directory?(dest_dir)
+ assert File.exists?(File.join(dest_dir, 'foo-bar', 'index.html'))
+ end
+
should "insert data" do
post = setup_post("2008-11-21-complex.textile")
do_render(post)
View
54 test/test_tags.rb
@@ -1,35 +1,51 @@
require File.dirname(__FILE__) + '/helper'
class TestTags < Test::Unit::TestCase
- context "tagging" do
- setup do
- @content = <<CONTENT
+
+ def create_post(code)
+ stub(Jekyll).configuration do
+ Jekyll::DEFAULTS.merge({'pygments' => true})
+ end
+ site = Site.new(Jekyll.configuration)
+ info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
+
+ content = <<CONTENT
---
-layout: post
title: This is a test
-
---
-This document results in a markdown error with maruku
-{% highlight ruby %}
-puts "hi"
+This document results in a markdown error with maruku
-puts "bye"
+{% highlight text %}
+#{code}
{% endhighlight %}
-
CONTENT
+
+ @result = Liquid::Template.parse(content).render({}, info)
+ @result = site.markdown(@result)
+ end
+
+ context "post content has highlight tag" do
+ setup do
+ create_post("test")
+ end
+
+ should "not cause a markdown error" do
+ assert_no_match /markdown\-html\-error/, @result
+ end
+
+ should "render markdown with pygments line handling" do
+ assert_match %{<pre>test\n</pre>}, @result
+ end
+ end
+
+ context "post content has highlight tag with UTF character" do
+ setup do
+ create_post("Æ")
end
should "render markdown with pygments line handling" do
- stub(Jekyll).configuration do
- Jekyll::DEFAULTS.merge({'pygments' => true})
- end
- site = Site.new(Jekyll.configuration)
- info = { :filters => [Jekyll::Filters], :registers => { :site => site } }
-
- result = Liquid::Template.parse(@content).render({}, info)
- result = site.markdown(result)
- assert_no_match(/markdown\-html\-error/,result)
+ assert_match %{<pre>Æ\n</pre>}, @result
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.