Class: Jekyll::AgentMarkdown::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/agent_markdown/configuration.rb

Defined Under Namespace

Modules: CollectionNames

Constant Summary collapse

DEFAULTS =
{
  "posts" => true,
  "pages" => false,
  "collections" => [].freeze,
  "llms_txt" => true,
  "llms_full_txt" => false,
  "include_descriptions" => false,
  "include_document_header" => false,
  "include_author" => true,
  "include_dates" => true,
  "sort" => "desc"
}.freeze
ALLOWED_SETTINGS =
DEFAULTS.keys.freeze
FALSE_STRINGS =
%w[false no off].freeze
SORT_ORDERS =
%w[asc desc].freeze

Class Method Summary collapse

Class Method Details

.absolute_http_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
68
69
70
# File 'lib/jekyll/agent_markdown/configuration.rb', line 61

def absolute_http_url?(url)
  uri = URI.parse(url) if url.is_a?(String)
  uri.is_a?(URI::HTTP) &&
    !uri.host.to_s.empty? &&
    uri.userinfo.nil? &&
    uri.query.nil? &&
    uri.fragment.nil?
rescue URI::InvalidURIError
  false
end

.collection_names(settings) ⇒ Object



48
49
50
# File 'lib/jekyll/agent_markdown/configuration.rb', line 48

def collection_names(settings)
  settings.fetch("collections", DEFAULTS.fetch("collections"))
end

.defaultsObject



26
# File 'lib/jekyll/agent_markdown/configuration.rb', line 26

def defaults = DEFAULTS.dup

.disabled?(value) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/jekyll/agent_markdown/configuration.rb', line 57

def disabled?(value)
  value == false || (value.is_a?(String) && FALSE_STRINGS.include?(value.strip.downcase))
end

.enabled?(settings, key) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/jekyll/agent_markdown/configuration.rb', line 40

def enabled?(settings, key)
  !disabled?(settings.fetch(key, DEFAULTS.fetch(key)))
end

.enabled_value?(value, name:) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/jekyll/agent_markdown/configuration.rb', line 52

def enabled_value?(value, name:)
  validate_value!(name, value)
  !disabled?(value)
end

.for(site) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jekyll/agent_markdown/configuration.rb', line 28

def for(site)
  settings = site.config["agent_markdown"]
  return {} if settings.nil? || settings == true
  return false if disabled?(settings)

  unless settings.is_a?(Hash)
    raise Jekyll::Errors::FatalException, "agent_markdown must be a Hash, true, or false"
  end

  normalized_settings(settings)
end

.sort_order(settings) ⇒ Object



44
45
46
# File 'lib/jekyll/agent_markdown/configuration.rb', line 44

def sort_order(settings)
  settings.fetch("sort", DEFAULTS.fetch("sort"))
end