Module: JekyllHighlightCards::ArchiveHelper

Included in:
Commands::FreezeArchives::Runner, FreezeArchives::MarkupAnalyzer, 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

.noarchive_regexp_cacheObject

Returns the value of attribute noarchive_regexp_cache.



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

def noarchive_regexp_cache
  @noarchive_regexp_cache
end

Instance Method Details

#archive_enabled?Boolean

Check if archiving is enabled via environment variables

Returns:

  • (Boolean)

    true if archiving is enabled



43
44
45
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 43

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



50
51
52
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 50

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

#archive_url_for(url, site: nil) ⇒ String?

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

Parameters:

  • url (String)

    the original URL to archive

  • site (Jekyll::Site, nil) (defaults to: nil)

    optional site for highlight_cards.noarchive patterns

Returns:

  • (String, nil)

    the archive URL, or nil if not found



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

def archive_url_for(url, site: nil)
  return nil unless archiveable_url?(url, site: site)

  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



57
58
59
60
# File 'lib/jekyll-highlight-cards/archive_helper.rb', line 57

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