Class: Jekyll::L10n::ExtractionConfigLoader
- Inherits:
-
Object
- Object
- Jekyll::L10n::ExtractionConfigLoader
- Defined in:
- lib/jekyll-l10n/extraction/config_loader.rb
Overview
Loads and validates extraction configuration for files during build.
ExtractionConfigLoader finds extraction configuration for generated HTML files by matching them against Jekyll site pages. It validates whether extraction is enabled and configured for a file, loads page-specific settings, and identifies files to skip (localized page variants).
Key responsibilities:
- Match generated HTML files to Jekyll site pages
- Validate that extraction is enabled for a file
- Load page-specific extraction configuration
- Identify localized page variants to skip
- Extract CSS selectors for element exclusion
Instance Method Summary collapse
-
#extract_exclude_selectors(config) ⇒ Array<String>
Extract CSS selectors for element exclusion from configuration.
-
#find_page_config_for_file(file_path) ⇒ Hash?
Find page configuration for a file.
-
#initialize(site, dest) ⇒ ExtractionConfigLoader
constructor
Initialize a new ExtractionConfigLoader.
-
#load_page_config(file_path) ⇒ PageLocalesConfig
Load extraction configuration for a file.
-
#skip_localized_page?(file_path) ⇒ Boolean
Check if a file is a localized page variant that should be skipped.
-
#valid_for_extraction?(file_path) ⇒ Boolean
Check if a file is valid for extraction.
Constructor Details
#initialize(site, dest) ⇒ ExtractionConfigLoader
Initialize a new ExtractionConfigLoader.
33 34 35 36 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 33 def initialize(site, dest) @site = site @dest = dest end |
Instance Method Details
#extract_exclude_selectors(config) ⇒ Array<String>
Extract CSS selectors for element exclusion from configuration.
Returns CSS selectors of elements to exclude from extraction (e.g., script, style, code blocks). Defaults to sensible defaults if not configured.
111 112 113 114 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 111 def extract_exclude_selectors(config) config.data.dig('with_locales_data', 'extraction', 'exclude_selectors') || ['script', 'style', 'code.language-plaintext', 'pre code'] end |
#find_page_config_for_file(file_path) ⇒ Hash?
Find page configuration for a file.
Matches a generated file path to a Jekyll page with extraction enabled. Returns the page's front matter data, or nil if no match found.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 72 def find_page_config_for_file(file_path) @site.pages.each do |page| next unless page.data['with_locales'] == true page_output = page.output_ext ? page.destination('') : page.destination('/') next unless file_path.end_with?(page_output.sub(%r{/$}, '/index.html')) return page.data end nil end |
#load_page_config(file_path) ⇒ PageLocalesConfig
Load extraction configuration for a file.
Finds the Jekyll page matching this file and returns its localization configuration wrapped in PageLocalesConfig.
60 61 62 63 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 60 def load_page_config(file_path) page_config = find_page_config_for_file(file_path) PageLocalesConfig.new(page_config) end |
#skip_localized_page?(file_path) ⇒ Boolean
Check if a file is a localized page variant that should be skipped.
Localized pages are generated copies in locale subdirectories that shouldn't be re-extracted (extraction happens on original pages only). Since commit 3d2d4cd, country-subtag locales (e.g. es_ES) are written to BCP 47 hyphenated, lowercased URL directories (e.g. es-es/). Each configured locale is normalized through LocaleUrlFormatter.to_url_segment before comparison so both language-only (es) and country-subtag (es_ES → es-es) locales are correctly recognized.
97 98 99 100 101 102 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 97 def skip_localized_page?(file_path) relative_path = file_path.sub(@dest, '') all_locales = SiteConfigAccessor.all_configured_locales(@site) all_locales.any? { |locale| relative_path.start_with?("/#{LocaleUrlFormatter.to_url_segment(locale)}/") } end |
#valid_for_extraction?(file_path) ⇒ Boolean
Check if a file is valid for extraction.
Matches the file to a Jekyll page and verifies extraction is enabled for that page in the configuration.
45 46 47 48 49 50 51 |
# File 'lib/jekyll-l10n/extraction/config_loader.rb', line 45 def valid_for_extraction?(file_path) page_config = find_page_config_for_file(file_path) return false unless page_config config = PageLocalesConfig.new(page_config) config.enabled? && config.extract_on_build? end |