A Jekyll plugin to pull the page title from the first few words of the first line of the content if a title isn't set.
If you have a Jekyll page that doesn't have a title specified in the YAML Front Matter, this plugin instructs Jekyll to use that first few words of the content as the page's title.
Because lots of plugins and templates rely on page.title
. This doesn't play nicely with micro blogging which doesn't require a title.
gem 'jekyll-titles-from-content'
plugins:
- jekyll-titles-from-content
Note: If you are using a Jekyll version less than 3.5.0, use the gems
key instead of plugins
.
Configuration options are optional and placed in _config.yml
under the titles_from_content
key. They default to:
titles_from_content:
enabled: true # Easily toggle the plugin from your configuration.
words: 5 # The number of words to use for the title.
collections: false # Apply the plugin to collections. Posts are collections.
dotdotdot: "" # The character(s) you'd like to append to truncated titles.
If you want to enable this plugin for collection items, set the collections
option to true
.
Since collection items (including posts) already have a title inferred from their filename, this option changes the behavior of this plugin to override the inferred title.
Even if the plugin is enabled (e.g., via the :jekyll_plugins
group in your Gemfile) you can disable it by setting the enabled
key to false
.
This plugin is heavily inspired by the jekyll-titles-from-headings plugin.