Class: Lifer::URIStrategy
- Inherits:
-
Object
- Object
- Lifer::URIStrategy
- 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
Defined Under Namespace
Classes: Pretty, PrettyRoot, PrettyYYYYMMDD, Root, Simple
Class Attribute Summary collapse
-
.name ⇒ Object
Returns the value of attribute name.
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root:) ⇒ URIStrategy
constructor
A new instance of URIStrategy.
-
#output_file(entry) ⇒ String
This method should always return the path to the file in the format specified by the current URI strategy.
-
#permalink(entry) ⇒ String
This method should sometimes return the path to the file in the format specified by the current URI strategy.
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
.name ⇒ Object
Returns the value of attribute name.
19 20 21 |
# File 'lib/lifer/uri_strategy.rb', line 19 def name @name end |
Instance Attribute Details
#root ⇒ Object (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
38 39 40 |
# File 'lib/lifer/uri_strategy.rb', line 38 def output_file(entry) raise NotImplementedError, I18n.t("shared.not_implemented_method") end |
#permalink(entry) ⇒ String
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
56 57 58 |
# File 'lib/lifer/uri_strategy.rb', line 56 def permalink(entry) raise NotImplementedError, I18n.t("shared.not_implemented_error") end |