Class: Lifer::URIStrategy

Inherits:
Object
  • Object
show all
Includes:
Shared::FinderMethods
Defined in:
lib/lifer/uri_strategy.rb,
lib/lifer/uri_strategy/root.rb,
lib/lifer/uri_strategy/pretty_root.rb

Overview

A URI strategy is used by collections and builders to determine the output path of each entry. Depending on the strategy used, the output URI can be very different. For example, given:

Input file: 2020-01-01-my-trip-to-greece.md

The output could be many things depending on the configured URI strategy:

Output file: https://example.com/my-trip-to-greece.html
Output file: https://example.com/2020/my-trip-to-greece/index.html
Output file: https://example.com/my-trip-to-greece-foo-bar-foo.html

URI strategies are configured per collection.

Direct Known Subclasses

Pretty, PrettyRoot, PrettyYYYYMMDD, Root, Simple

Defined Under Namespace

Classes: Pretty, PrettyRoot, PrettyYYYYMMDD, Root, Simple

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root:) ⇒ URIStrategy

Returns a new instance of URIStrategy.



24
25
26
# File 'lib/lifer/uri_strategy.rb', line 24

def initialize(root:)
  @root = root
end

Class Attribute Details

.nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/lifer/uri_strategy.rb', line 19

def name
  @name
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



22
23
24
# File 'lib/lifer/uri_strategy.rb', line 22

def root
  @root
end

Instance Method Details

#output_file(entry) ⇒ String

This method should always return the path to the file in the format specified by the current URI strategy. For example, if the URI strategy was to indexify every entry (the “pretty” strategy), input to output would look like:

entry-name.md ---> entry-name/index.html

Returns:

  • (String)

    The path to the built output file.

Raises:

  • (NotImplementedError)

    This method must be implemented on each subclass.



38
39
40
# File 'lib/lifer/uri_strategy.rb', line 38

def output_file(entry)
  raise NotImplementedError, I18n.t("shared.not_implemented_method")
end

This method should sometimes return the path to the file in the format specified by the current URI strategy. Of course, this depends on what the URI stategy is. For “pretty” strategies, the permalink may differ from the output filename. For example, the output file may point to

entry-name/index.html

While the permalink like points to:

entry-name

Returns:

  • (String)

    The permalink to the built output file.

Raises:

  • (NotImplementedError)

    This method must be implemented on each subclass.



56
57
58
# File 'lib/lifer/uri_strategy.rb', line 56

def permalink(entry)
  raise NotImplementedError, I18n.t("shared.not_implemented_error")
end