Mike Slinn
Mike Slinn

jekyll_basename_dirname

Published 2020-10-03. Last modified 2023-05-18.
Time to read: 1 minutes.

This page is part of the jekyll_plugins collection, categorized under Jekyll.

Jekyll_basename_dirname is a Jekyll plugin that provides 3 filters that return portions of a string: basename, dirname and basename_without_extension.

  • basename – Filters a string containing a path, returning the filename and extension.
  • dirname – Filters a string containing a path, returning the portion before the filename and extension.
  • basename_without_extension – Filters a string containing a path, returning the filename without the extension.

Installation

Jekyll_basename_dirname is packaged as a Ruby gem. Add the following line to your Jekyll project’s Gemfile.

Gemfile
group :jekyll_plugins do 
  gem 'jekyll_basename_dirname'
end 

Install the jekyll_basename_dirname gem in the usual manner:

Shell
$ bundle

Syntax

{{ "blah/blah/filename.ext" | dirname }} => blah/blah
{{ "blah/blah/filename.ext" | basename }} => filename.ext
{{ "blah/blah/filename.ext" | basename_without_extension  }} => filename