Module: Basename

Defined in:
basename.rb

Overview

Jekyll filters for working with paths.

Author:

  • Copyright 2020 Michael Slinn

License:

  • SPDX-License-Identifier: Apache-2.0

Instance Method Summary collapse

Instance Method Details

#basename(filepath) ⇒ String

Filters a string containing a path.

Examples:

Extracts "filename.ext" from the path

{{ "blah/blah/filename.ext" | basename }}

Returns:

  • (String)

    the filename extracted from the path, including the filetype.



12
13
14
# File 'basename.rb', line 12

def basename(filepath)
  File.basename(filepath)
end

#basename_without_extension(filepath) ⇒ Object

Filters a string containing a path.

Examples:

Extracts "filename" from the path.

{{ "blah/blah/filename.ext" | basename_without_extension }}

Returns:

  • the filename without the extension.



28
29
30
# File 'basename.rb', line 28

def basename_without_extension(filepath)
  File.basename(filepath).split('.')[0...-1].join('.')
end

#dirname(filepath) ⇒ String

Filters a string containing a path.

Examples:

Extracts "blah/blah" from the path.

{{ "blah/blah/filename.ext" | dirname }}

Returns:

  • (String)

    the portion of th path before the filename and extension.



20
21
22
# File 'basename.rb', line 20

def dirname(filepath)
  File.dirname(filepath)
end