Module: JekyllHighlightCards::ArchiveHelper

Included in:
LinkcardTag, PolaroidTag
Defined in:
lib/jekyll-highlight-cards/archive_helper.rb

Overview

Internet Archive integration for automatic URL archival

Provides methods for looking up existing archives and submitting URLs to the Internet Archive's Wayback Machine. Results are cached per-site-build to avoid redundant API calls.

Examples:

Enable archiving

export JEKYLL_HIGHLIGHT_CARDS_ARCHIVE=1

Enable auto-submission

export JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_SAVE=1

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.archive_cacheObject

Returns the value of attribute archive_cache.



20
21
22
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 20

def archive_cache
  @archive_cache
end

Instance Method Details

#archive_enabled?Boolean

Check if archiving is enabled via environment variables

Returns:

  • (Boolean)

    true if archiving is enabled



40
41
42
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 40

def archive_enabled?
  ENV["JEKYLL_HIGHLIGHT_CARDS_ARCHIVE"] == "1" || archive_save_enabled?
end

#archive_save_enabled?Boolean

Check if SavePageNow submission is enabled

Returns:

  • (Boolean)

    true if submission is enabled



47
48
49
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 47

def archive_save_enabled?
  ENV["JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_SAVE"] == "1"
end

#archive_url_for(url) ⇒ String?

Get archive URL for a given URL, with caching and optional submission

Parameters:

  • url (String)

    the original URL to archive

Returns:

  • (String, nil)

    the archive URL, or nil if not found



27
28
29
30
31
32
33
34
35
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 27

def archive_url_for(url)
  ArchiveHelper.archive_cache[url] ||= begin
    archive_url = lookup_archive(url)

    archive_url = submit_archive(url) || archive_url if archive_save_enabled?

    archive_url
  end
end

#archive_user_agentString

Get User-Agent string for archive HTTP requests

Returns:

  • (String)

    User-Agent header value



54
55
56
57
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 54

def archive_user_agent
  ENV["JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_UA"] ||
    "jekyll:highlight-cards (+#{ENV.fetch("JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_CONTACT", "mailto:unknown")})"
end