Class: Abqari::Indieweb::Fetcher
- Inherits:
-
Object
- Object
- Abqari::Indieweb::Fetcher
- Defined in:
- lib/abqari/indieweb.rb
Overview
Fetcher — pulls received webmentions from webmention.io and exposes
them keyed by the target URL. The fetcher caches the full JF2
response under vendor/webmentions/mentions.json and uses an ETag
header so subsequent builds typically get a 304 and reuse the cache.
Layouts query this via site.webmentions_for(page.url), which
returns an array of mention hashes (or [] when none).
Constant Summary collapse
- API_BASE =
webmention.io's public mentions endpoint.
targetfiltering happens client-side: pulling all mentions for the domain in one paginated fetch is cheaper than one HTTP call per post. 'https://webmention.io/api/mentions.jf2'- MAX_RESPONSE_BYTES =
Plenty of headroom for high-volume sites — typical hobby sites pull a few hundred mentions per build, well under this cap.
4 * 1024 * 1024
- PAGE_SIZE =
200
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #cache_path ⇒ Object
- #enabled? ⇒ Boolean
- #etag_path ⇒ Object
-
#fetch ⇒ Object
Run the fetch.
-
#initialize(site) ⇒ Fetcher
constructor
A new instance of Fetcher.
-
#webmention_io_token ⇒ Object
ENV fallback so the API token can live in a CI secret instead of committed site.yml.
Constructor Details
#initialize(site) ⇒ Fetcher
Returns a new instance of Fetcher.
81 82 83 84 |
# File 'lib/abqari/indieweb.rb', line 81 def initialize(site) @site = site @cfg = Indieweb.config_for(site) end |
Instance Method Details
#cache_dir ⇒ Object
97 98 99 |
# File 'lib/abqari/indieweb.rb', line 97 def cache_dir File.join(@site.site_root, 'vendor', 'webmentions') end |
#cache_path ⇒ Object
101 102 103 |
# File 'lib/abqari/indieweb.rb', line 101 def cache_path File.join(cache_dir, 'mentions.json') end |
#enabled? ⇒ Boolean
86 87 88 |
# File 'lib/abqari/indieweb.rb', line 86 def enabled? Indieweb.enabled?(@site) && !webmention_io_token.empty? end |
#etag_path ⇒ Object
105 106 107 |
# File 'lib/abqari/indieweb.rb', line 105 def etag_path File.join(cache_dir, 'etag') end |
#fetch ⇒ Object
Run the fetch. Idempotent on the cache layer: a 304 just reuses
the on-disk copy. Populates site.data['webmentions'] as a
{ target_url => [mention, ...] } hash so the post layout's
lookup is O(1).
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/abqari/indieweb.rb', line 113 def fetch unless enabled? @site.data['webmentions'] = {} return end FileUtils.mkdir_p(cache_dir) mentions = load_or_refresh index = index_by_target(mentions) @site.data['webmentions'] = index Log.info "Webmentions: #{mentions.size} cached mention(s) across #{index.size} target URL(s)" end |
#webmention_io_token ⇒ Object
ENV fallback so the API token can live in a CI secret instead of committed site.yml. Config value wins when set.
92 93 94 95 |
# File 'lib/abqari/indieweb.rb', line 92 def webmention_io_token value = @cfg['webmention_io_token'].to_s value.empty? ? ENV['ABQARI_WEBMENTION_IO_TOKEN'].to_s : value end |