Class: Lifer::URIStrategy::PrettyYYYYMMDD

Inherits:
Lifer::URIStrategy show all
Defined in:
lib/lifer/uri_strategy/pretty_yyyy_mm_dd.rb

Overview

This URI strategy ensures that entries with dates in the filename (i.e. ‘1990-12-12-my-trip-to-hamilton.md`) will always be have output filenames without the date included. It also follows the “pretty” URI strategy of outputting each file to an `index` file in a subdirectory.

For example:

1990-12-12-my-trip-to-hamilton.md ---> my-trip-to-hamilton/index.html

Constant Summary collapse

DATE_SEPARATORS =

We expect date separators to fall into this regular expression.

"[\-\._]{1}"
DATE_REGEXP =

The date regular expression we expect entry filenames to follow.

/\d{4}#{DATE_SEPARATORS}\d{1,2}#{DATE_SEPARATORS}\d{1,2}#{DATE_SEPARATORS}/

Instance Attribute Summary

Attributes inherited from Lifer::URIStrategy

#root

Instance Method Summary collapse

Methods inherited from Lifer::URIStrategy

#initialize

Constructor Details

This class inherits a constructor from Lifer::URIStrategy

Instance Method Details

#output_file(entry) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/lifer/uri_strategy/pretty_yyyy_mm_dd.rb', line 23

def output_file(entry)
  basename = File.basename entry.file,
    Lifer::Utilities.file_extension(entry.file)

  Pathname entry.file.to_s
    .gsub(/#{root}[\/]{0,1}/, "")
    .gsub(/#{basename}(\..+)/, "#{basename}/index.#{file_extension(entry)}")
    .gsub(DATE_REGEXP, "")
end