Permalink
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...
2 parents 1d42b39 + bad2d17 commit 94aa73d04671d3d1bd7c9680223d2e819f63cfa1 @henrik henrik committed Apr 26, 2009
Showing with 235 additions and 87 deletions.
  1. +5 −14 README.textile
  2. +2 −6 bin/jekyll
  3. +54 −0 features/permalinks.feature
  4. +0 −20 features/site_configuration.feature
  5. +2 −2 lib/jekyll.rb
  6. +43 −22 lib/jekyll/post.rb
  7. +1 −2 lib/jekyll/site.rb
  8. +93 −2 test/test_post.rb
  9. +35 −19 test/test_tags.rb
View
@@ -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
@@ -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
@@ -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"
@@ -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
@@ -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
@@ -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,21 +112,51 @@ 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)
# e.g. /2008/11/05/my-awesome-post
#
# 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
@@ -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
Oops, something went wrong.

0 comments on commit 94aa73d

Please sign in to comment.