Class: JekyllHighlightCards::Commands::FreezeArchives

Inherits:
Jekyll::Command
  • Object
show all
Defined in:
lib/jekyll-highlight-cards/commands/freeze_archives.rb

Overview

Opt-in Jekyll subcommand: jekyll freeze-archives

Scans site source for archive-eligible linkcard / polaroid tags that lack an encoded archive, looks up Internet Archive, and surgically inserts successful hits into source. Does not run during jekyll build.

Defined Under Namespace

Classes: Runner

Class Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ void

This method returns an undefined value.

Register the freeze-archives Mercenary subcommand

Parameters:

  • prog (Mercenary::Program)

    the Jekyll CLI program



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/jekyll-highlight-cards/commands/freeze_archives.rb', line 18

def init_with_program(prog)
  prog.command(:"freeze-archives") do |c|
    c.syntax "freeze-archives [options]"
    c.description "Freeze Internet Archive URLs into highlight-card source tags"

    c.option "dry_run", "--dry-run", "Report planned edits without writing files"
    c.option "save", "--save", "Enable SavePageNow when CDX has no snapshot"
    c.option "config", "--config CONFIG_FILE[,CONFIG_FILE2,...]", Array,
             "Custom configuration file"
    c.option "source", "-s", "--source SOURCE", "Custom source directory"

    c.action do |_args, options|
      process(options)
    end
  end
end

.process(options) ⇒ Hash

Run freeze-archives against a configured site

Parameters:

  • options (Hash)

    Mercenary/Jekyll options (+dry_run+, save, source, …)

Returns:

  • (Hash)

    summary counts :frozen, :skipped, :miss, :written



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jekyll-highlight-cards/commands/freeze_archives.rb', line 39

def process(options)
  previous_save = ENV.fetch("JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_SAVE", nil)
  previous_log_level = Jekyll.logger.level
  ENV["JEKYLL_HIGHLIGHT_CARDS_ARCHIVE_SAVE"] = "1" if options["save"]

  site = Jekyll::Site.new(configuration_from_options(options))
  # Hand-run tool: keep progress visible even if the site sets quiet: true
  Jekyll.logger.log_level = :info unless options["quiet"]
  site.read

  summary = Runner.new(
    dry_run: options["dry_run"],
    logger: Jekyll.logger
  ).run(site)

  Jekyll.logger.info "freeze-archives:",
                     "frozen=#{summary[:frozen]} skipped=#{summary[:skipped]} " \
                     "miss=#{summary[:miss]} written=#{summary[:written]}"
  summary
ensure
  restore_save_env(previous_save, options)
  Jekyll.logger.log_level = previous_log_level if previous_log_level
end