Class: Jekyll::L10n::RegenerationChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-l10n/jekyll/regeneration_checker.rb

Overview

Regeneration Checker - Optimizes incremental builds by skipping unchanged pages

This class implements incremental build optimization for localized pages. When Jekyll’s incremental build mode is enabled, it checks whether a specific locale variant of a page needs to be regenerated based on source modification times.

The checker compares modification times of:

  • Source page file

  • Page-specific PO translation file

  • Compendium (shared translations) PO file

  • Jekyll configuration (_config.yml)

If any of these are newer than the output HTML, the page is regenerated. This significantly speeds up rebuilds when only a few files have changed.

Examples:

Usage

checker = RegenerationChecker.new(site)
if checker.should_regenerate?(page, 'es')
  # Create localized_page and add to site.pages
end

Instance Method Summary collapse

Constructor Details

#initialize(site, locales_dir = DEFAULT_LOCALES_DIR) ⇒ RegenerationChecker

Initialize the regeneration checker

Parameters:

  • site (Jekyll::Site)

    The Jekyll site object

  • locales_dir (String) (defaults to: DEFAULT_LOCALES_DIR)

    Directory containing PO files (defaults to DEFAULT_LOCALES_DIR = “_locales”)



38
39
40
41
42
43
# File 'lib/jekyll-l10n/jekyll/regeneration_checker.rb', line 38

def initialize(site, locales_dir = DEFAULT_LOCALES_DIR)
  @site = site
  @locales_dir = locales_dir
  @source = SiteConfigAccessor.source(@site)
  @destination = @site&.config&.dig('destination') || ''
end

Instance Method Details

#should_regenerate?(page, locale) ⇒ Boolean

Determine if a localized page variant should be regenerated

Returns true if:

  • Incremental builds are disabled (always regenerate)

  • Output file doesn’t exist yet

  • Source page has been modified since output was generated

  • PO translation files have been modified since output was generated

  • Jekyll configuration has been modified since output was generated

Returns false if incremental builds are enabled and output is up-to-date.

Parameters:

  • page (Jekyll::Page)

    The source page to check

  • locale (String)

    The locale code for the variant (e.g., ‘es’, ‘fr’)

Returns:

  • (Boolean)

    true if the page should be regenerated, false if output is current



59
60
61
62
63
64
65
66
67
68
# File 'lib/jekyll-l10n/jekyll/regeneration_checker.rb', line 59

def should_regenerate?(page, locale)
  return true unless incremental_enabled?
  return true unless dest_path_exists?(page, locale)

  dest_mtime = File.mtime(dest_path(page, locale))

  source_modified?(page, dest_mtime) ||
    po_files_modified?(page, locale, dest_mtime) ||
    config_modified?(dest_mtime)
end