Class: Jekyll::WebmentionIO::GatherWebmentions

Inherits:
Generator
  • Object
show all
Defined in:
lib/jekyll/generators/gather_webmentions.rb

Instance Method Summary collapse

Instance Method Details

#generate(site) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/jekyll/generators/gather_webmentions.rb', line 18

def generate(site)
  @site = site
  @site_url = site.config["url"].to_s

  if @site_url.include? "localhost"
    Jekyll::WebmentionIO.log "msg", "Webmentions won’t be gathered on localhost."
    return
  end

  if @site.config.dig("webmentions", "pause_lookups") == true
    WebmentionIO.log "msg", "Webmention gathering is currently paused."
    return
  end

  WebmentionIO.log "msg", "Beginning to gather webmentions of your posts. This may take a while."

  WebmentionIO.api_path = "mentions"
  # add an arbitrarily high perPage to trump pagination
  WebmentionIO.api_suffix = "&perPage=9999"

  @cached_webmentions = WebmentionIO.read_cached_webmentions "incoming"

  @lookups = WebmentionIO.read_lookup_dates

  posts = WebmentionIO.gather_documents(@site)
  posts.each do |post|
    check_for_webmentions(post)
  end

  WebmentionIO.cache_lookup_dates @lookups

  WebmentionIO.cache_webmentions "incoming", @cached_webmentions
end