Class: Zer0ImageGenerator::Command

Inherits:
Jekyll::Command
  • Object
show all
Defined in:
lib/zer0_image_generator/command.rb

Overview

jekyll preview-images — a thin launcher for the vendored single-file Python engine (preview_generator.py, same directory). The Ruby layer only translates Mercenary options back into the engine's argv and execs python3: all behavior (config resolution, credentials, providers, front matter) lives in the engine so the gem and the standalone file can never drift.

Jekyll's global switches already claim -s/-d/-p/-v at the program level, so conflicting engine shorts are exposed long-form here; the engine's own CLI keeps the full short surface for direct python3 use.

Constant Summary collapse

ENGINE =
File.expand_path("preview_generator.py", __dir__)
SWITCHES =

[engine flag, mercenary args] — booleans pass bare, values pass through.

[
  ["--dry-run",          [:dry_run, "--dry-run", "Preview what would be generated (no changes)"]],
  ["--verbose",          [:verbose, "--verbose", "Enable verbose output"]],
  ["--file",             [:file, "-f", "--file FILE", "Process a specific file only"]],
  ["--collection",       [:collection, "--collection NAME", "Process one collection, or 'all'"]],
  ["--provider",         [:provider, "--provider NAME", "Renderer: openai, xai, stability, gemini, local"]],
  ["--model",            [:model, "--model NAME", "Override the provider's image model"]],
  ["--output-dir",       [:output_dir, "--output-dir DIR", "Image output directory"]],
  ["--force",            [:force, "--force", "Regenerate even when a preview exists"]],
  ["--list-missing",     [:list_missing, "--list-missing", "Only list files with missing previews"]],
  ["--parallel",         [:parallel, "-j", "--parallel N", "Concurrent workers (default 4)"]],
  ["--enhance",          [:enhance, "-e", "--enhance", "Enhance existing images (OpenAI images/edits)"]],
  ["--enhance-prompt",   [:enhance_prompt, "--enhance-prompt TEXT", "Custom enhancement prompt (implies --enhance)"]],
  ["--enhance-model",    [:enhance_model, "--enhance-model NAME", "Enhancement model (default: gpt-image-2)"]],
  ["--enhance-quality",  [:enhance_quality, "--enhance-quality Q", "low|medium|high|auto"]],
  ["--enhance-fidelity", [:enhance_fidelity, "--enhance-fidelity F", "high|low (implies --enhance)"]],
  ["--enhance-format",   [:enhance_format, "--enhance-format FMT", "png|jpeg|webp (implies --enhance)"]],
  ["--prompt-engine",    [:prompt_engine, "--prompt-engine ENGINE", "claude (analyzes the article) or template"]],
  ["--review",           [:review, "--review ENGINE", "claude (vision-reviews the render) or none"]],
  ["--rasterizer",       [:rasterizer, "--rasterizer TOOL", "auto|rsvg|inkscape|magick|playwright|none"]],
  ["--style",            [:style, "--style TEXT", "Override the image style prompt"]],
  ["--assets-prefix",    [:assets_prefix, "--assets-prefix PREFIX", "Assets prefix for path normalization"]],
  ["--no-auto-prefix",   [:no_auto_prefix, "--no-auto-prefix", "Disable automatic assets-prefix prepending"]],
  ["--batch",            [:batch, "--batch N", "Limit number of files processed"]],
  ["--log-file",         [:log_file, "--log-file FILE", "Also write log output to a file"]],
  ["--collections-dir",  [:collections_dir, "--collections-dir DIR", "Directory holding _<collection> dirs"]],
  ["--front-matter-key", [:front_matter_key, "--front-matter-key KEY", "Front-matter key (default preview; seo-tag sites: image)"]],
  ["--authors-file",     [:authors_file, "--authors-file FILE", "Author-overrides YAML ('' disables)"]],
].freeze
BOOLEANS =
%w[--dry-run --verbose --force --list-missing --enhance --no-auto-prefix].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.init_with_program(prog) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zer0_image_generator/command.rb', line 51

def init_with_program(prog)
  prog.command(:"preview-images") do |c|
    c.syntax "preview-images [options]"
    c.description "Generate AI preview/social images (Claude directs & reviews; " \
                  "OpenAI/xAI/Stability/Gemini/local renders)"
    SWITCHES.each { |_flag, merc| c.option(*merc) }

    c.action do |_args, options|
      new.run(options)
    end
  end
end

Instance Method Details

#build_argv(options) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/zer0_image_generator/command.rb', line 73

def build_argv(options)
  SWITCHES.each_with_object([]) do |(flag, merc), argv|
    value = options[merc.first.to_s]
    next if value.nil? || value == false

    if BOOLEANS.include?(flag)
      argv << flag
    else
      argv << flag << value.to_s
    end
  end
end

#run(options) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/zer0_image_generator/command.rb', line 65

def run(options)
  python = ENV["PYTHON"] || "python3"
  ensure_python!(python)
  argv = build_argv(options)
  Jekyll.logger.info "preview-images:", "#{python} #{ENGINE} #{argv.join(' ')}"
  exec(python, ENGINE, *argv)
end