Class: Jekyll::Excerpt

### Home Classes Methods

### In Files

- lib/jekyll/excerpt.rb

### Parent

Object

### Methods

- ::new
- #data
- #extract_excerpt
- #id
- #include?
- #inspect
- #path
- #to_liquid
- #to_s

### Included Modules

- Jekyll::Convertible

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::Excerpt

### Attributes

content[RW]
ext[RW]
output[RW]
post[RW]

### Public Class Methods

new(post) click to toggle source

Initialize this Post instance.

site - The Site. base - The String path to the dir containing the post file. name - The String filename of the post file.

Returns the new Post.

    # File lib/jekyll/excerpt.rb, line 15
    def initialize(post)
      self.post = post
      self.content = extract_excerpt(post.content)
    end

### Public Instance Methods

data() click to toggle source

Fetch YAML front-matter data from related post, without layout key

Returns Hash of post data

    # File lib/jekyll/excerpt.rb, line 33
    def data
      @data ||= post.data.dup
      @data.delete("layout")
      @data
    end

id() click to toggle source

The UID for this post (useful in feeds). e.g. /2008/11/05/my-awesome-post

Returns the String UID.

    # File lib/jekyll/excerpt.rb, line 57
    def id
      File.join(post.dir, post.slug, "#excerpt")
    end

include?(something) click to toggle source

Check if excerpt includes a string

Returns true if the string passed in

    # File lib/jekyll/excerpt.rb, line 49
    def include?(something)
      (self.output && self.output.include?(something)) || self.content.include?(something)
    end

inspect() click to toggle source

Returns the shorthand String identifier of this Post.

    # File lib/jekyll/excerpt.rb, line 66
    def inspect
      "<Excerpt: #{self.id}>"
    end

path() click to toggle source

'Path' of the excerpt.

Returns the path for the post this excerpt belongs to with excerpt appended

    # File lib/jekyll/excerpt.rb, line 42
    def path
      File.join(post.path, "#excerpt")
    end

to_liquid() click to toggle source

    # File lib/jekyll/excerpt.rb, line 26
    def to_liquid
      post.to_liquid(Post::EXCERPT_ATTRIBUTES_FOR_LIQUID)
    end

to_s() click to toggle source

    # File lib/jekyll/excerpt.rb, line 61
    def to_s
      self.output || self.content
    end

### Protected Instance Methods

extract_excerpt(post_content) click to toggle source

Internal: Extract excerpt from the content

By default excerpt is your first paragraph of a post: everything before the first two new lines:

    ---
    title: Example
    ---

    First paragraph with [link][1].

    Second paragraph.

    [1]: http://example.com/

This is fairly good option for Markdown and Textile files. But might cause problems for HTML posts (which is quite unusual for Jekyll). If default excerpt delimiter is not good for you, you might want to set your own via configuration option `excerpt_separator`. For example, following is a good alternative for HTML posts:

    # file: _config.yml
    excerpt_separator: "<!-- more -->"

Notice that all markdown-style link references will be appended to the excerpt. So the example post above will have this excerpt source:

    First paragraph with [link][1].

    [1]: http://example.com/

Excerpts are rendered same time as content is rendered.

Returns excerpt String

    # File lib/jekyll/excerpt.rb, line 106
    def extract_excerpt(post_content)
      separator     = site.config['excerpt_separator']
      head, _, tail = post_content.partition(separator)

      "" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.