Class: Jekyll::WebmentionIO::Config
- Inherits:
-
Object
- Object
- Jekyll::WebmentionIO::Config
- Defined in:
- lib/jekyll/config.rb
Defined Under Namespace
Modules: HtmlProofer, UriPolicy Classes: BadUriPolicy, JsConfig, SyndicationRule
Constant Summary collapse
- TIMEFRAMES =
{ 'last_week' => 'weekly', 'last_month' => 'monthly', 'last_year' => 'yearly', }.freeze
- DEFAULT_API_URL =
The default base URL for the Webmention.io API. Exposed as a config key so the endpoint can be pointed elsewhere (e.g. a local stand-in during integration testing) instead of being hard-coded in the network layer.
'https://webmention.io/api'
Instance Attribute Summary collapse
-
#api_host ⇒ Object
readonly
The scheme://host origin and bare host of the configured API, derived from api_url.
-
#api_origin ⇒ Object
readonly
The scheme://host origin and bare host of the configured API, derived from api_url.
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#bad_uri_policy ⇒ Object
Returns the value of attribute bad_uri_policy.
-
#cache_folder ⇒ Object
Returns the value of attribute cache_folder.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#html_proofer_ignore ⇒ Object
Returns the value of attribute html_proofer_ignore.
-
#js ⇒ Object
Returns the value of attribute js.
-
#legacy_domains ⇒ Object
Returns the value of attribute legacy_domains.
-
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
-
#pause_lookups ⇒ Object
Returns the value of attribute pause_lookups.
-
#site_url ⇒ Object
Returns the value of attribute site_url.
-
#syndication ⇒ Object
Returns the value of attribute syndication.
-
#templates ⇒ Object
Returns the value of attribute templates.
-
#throttle_lookups ⇒ Object
Returns the value of attribute throttle_lookups.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.api_uri(url) ⇒ Object
Resolves a webmention API URL to a URI, falling back to the default endpoint when the configured value has no host.
-
.authority(uri) ⇒ Object
The host of a parsed API URI, plus the port when it isn’t the scheme’s default (so custom/local endpoints still match the full URL).
Instance Method Summary collapse
- #collections ⇒ Object
-
#documents ⇒ Object
Based on the specified configuration, return the list of documents for the site that should be processed.
-
#initialize(site = nil) ⇒ Config
constructor
A new instance of Config.
-
#last_lookup_threshold(date) ⇒ Object
The next lookup date has to be before this date to be allowed to request webmentions again.
- #parse(config = nil, site_url = '', base_url = '') ⇒ Object
-
#syndication_rule_for_uri(uri) ⇒ Object
Given a webmention endpoint, find the corresponding syndication rule Yes, this is a kind of reverse lookup so we can figure out of a given queued webmention was a result of a syndication rule.
Constructor Details
#initialize(site = nil) ⇒ Config
Returns a new instance of Config.
59 60 61 62 63 64 65 66 67 |
# File 'lib/jekyll/config.rb', line 59 def initialize(site = nil) @site = site if site.nil? parse else parse(@site.config['webmentions'], @site.config['url'].to_s, @site.config['baseurl'].to_s) end end |
Instance Attribute Details
#api_host ⇒ Object (readonly)
The scheme://host origin and bare host of the configured API, derived from api_url. Used to build the service links emitted into the page head (and the JS) so they track a custom endpoint instead of being hard-coded to webmention.io.
39 40 41 |
# File 'lib/jekyll/config.rb', line 39 def api_host @api_host end |
#api_origin ⇒ Object (readonly)
The scheme://host origin and bare host of the configured API, derived from api_url. Used to build the service links emitted into the page head (and the JS) so they track a custom endpoint instead of being hard-coded to webmention.io.
39 40 41 |
# File 'lib/jekyll/config.rb', line 39 def api_origin @api_origin end |
#api_url ⇒ Object
Returns the value of attribute api_url.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def api_url @api_url end |
#bad_uri_policy ⇒ Object
Returns the value of attribute bad_uri_policy.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def bad_uri_policy @bad_uri_policy end |
#cache_folder ⇒ Object
Returns the value of attribute cache_folder.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def cache_folder @cache_folder end |
#debug ⇒ Object
Returns the value of attribute debug.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def debug @debug end |
#html_proofer_ignore ⇒ Object
Returns the value of attribute html_proofer_ignore.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def html_proofer_ignore @html_proofer_ignore end |
#js ⇒ Object
Returns the value of attribute js.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def js @js end |
#legacy_domains ⇒ Object
Returns the value of attribute legacy_domains.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def legacy_domains @legacy_domains end |
#max_attempts ⇒ Object
Returns the value of attribute max_attempts.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def max_attempts @max_attempts end |
#pause_lookups ⇒ Object
Returns the value of attribute pause_lookups.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def pause_lookups @pause_lookups end |
#site_url ⇒ Object
Returns the value of attribute site_url.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def site_url @site_url end |
#syndication ⇒ Object
Returns the value of attribute syndication.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def @syndication end |
#templates ⇒ Object
Returns the value of attribute templates.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def templates @templates end |
#throttle_lookups ⇒ Object
Returns the value of attribute throttle_lookups.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def throttle_lookups @throttle_lookups end |
#username ⇒ Object
Returns the value of attribute username.
30 31 32 |
# File 'lib/jekyll/config.rb', line 30 def username @username end |
Class Method Details
.api_uri(url) ⇒ Object
Resolves a webmention API URL to a URI, falling back to the default endpoint when the configured value has no host.
48 49 50 51 |
# File 'lib/jekyll/config.rb', line 48 def self.api_uri(url) uri = URI.parse(url) uri.host ? uri : URI.parse(DEFAULT_API_URL) end |
.authority(uri) ⇒ Object
The host of a parsed API URI, plus the port when it isn’t the scheme’s default (so custom/local endpoints still match the full URL).
55 56 57 |
# File 'lib/jekyll/config.rb', line 55 def self.(uri) uri.port == uri.default_port ? uri.host : "#{uri.host}:#{uri.port}" end |
Instance Method Details
#collections ⇒ Object
162 163 164 |
# File 'lib/jekyll/config.rb', line 162 def collections @site.collections end |
#documents ⇒ Object
Based on the specified configuration, return the list of documents for the site that should be processed.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/jekyll/config.rb', line 138 def documents documents = @site.posts.docs.clone if @pages == true WebmentionIO.log 'info', 'Including site pages.' documents.concat @site.pages.clone end if @collections.empty? WebmentionIO.log 'info', 'Adding collections.' @site.collections.each do |name, collection| # skip _posts next if name == 'posts' if collections.include?(name) documents.concat collection.docs.clone end end end documents end |
#last_lookup_threshold(date) ⇒ Object
The next lookup date has to be before this date to be allowed to request webmentions again.
121 122 123 124 125 126 127 |
# File 'lib/jekyll/config.rb', line 121 def last_lookup_threshold(date) age = get_timeframe_from_date(date) throttle = @throttle_lookups[age] throttle.nil? ? nil : get_date_from_string(throttle) end |
#parse(config = nil, site_url = '', base_url = '') ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/jekyll/config.rb', line 69 def parse(config = nil, site_url = '', base_url = '') config ||= {} @site_url = site_url @username = config['username'] @debug = config['debug'] @api_url = config['api_url'] || DEFAULT_API_URL api_uri = self.class.api_uri(@api_url) @api_host = api_uri.host @api_origin = "#{api_uri.scheme}://#{self.class.(api_uri)}" @pause_lookups = if !@site.nil? && @site.config['serving'] WebmentionIO.log 'msg', 'Webmentions won’t be gathered when running `jekyll serve`.' true elsif !@site.nil? && @site_url.include?('localhost') WebmentionIO.log 'msg', 'Webmentions won’t be gathered on localhost.' true else config['pause_lookups'] end @cache_folder = config['cache_folder'] || '.jekyll-cache' @cache_folder = @site.in_source_dir(@cache_folder) if !@site.nil? @pages = config['pages'] @collections = config['collections'] || {} @templates = config['templates'] || {} @js = JsConfig.new(base_url, config['js'] || false) @html_proofer_ignore = HtmlProofer.get_const( config['html_proofer_ignore'] || (config['html_proofer'] ? 'templates' : nil) || 'none' ) @max_attempts = config['max_attempts'] @bad_uri_policy = BadUriPolicy.new(config) @throttle_lookups = config['throttle_lookups'] || {} @legacy_domains = config['legacy_domains'] || [] @syndication = (config['syndication'] || {}).transform_values { |entry| SyndicationRule.new(entry) } end |
#syndication_rule_for_uri(uri) ⇒ Object
Given a webmention endpoint, find the corresponding syndication rule Yes, this is a kind of reverse lookup so we can figure out of a given queued webmention was a result of a syndication rule.
132 133 134 |
# File 'lib/jekyll/config.rb', line 132 def (uri) @syndication.values.detect { |rule| rule.endpoint == uri } end |