File: jekyll-data.rb

package info (click to toggle)
ruby-jekyll-data 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 420 kB
  • sloc: ruby: 909; sh: 95; makefile: 10
file content (52 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true

require "jekyll"
require "jekyll-data/version"

module JekyllData
  autoload :Reader,             "jekyll-data/reader"
  autoload :ThemedSiteDrop,     "jekyll-data/themed_site_drop"
  autoload :ThemeDataReader,    "jekyll-data/theme_data_reader"
  autoload :ThemeConfiguration, "jekyll-data/theme_configuration"
end

# Monkey-patches
require_relative "jekyll/build_options"
require_relative "jekyll/data_path"
require_relative "jekyll/theme_drop"

# ----------------------------------------------------------------------------
# Modify the current site instance only if it uses a gem-based theme.
#
# if a '_config.yml' is present at the root of theme-gem, it is evaluated and
# the extracted hash data is incorprated into the site's config hash.
#
# *Jekyll 4.0 has this feature incorporated in its core.*
# ----------------------------------------------------------------------------
unless Jekyll::VERSION.start_with?("4")
  Jekyll::Hooks.register :site, :after_reset do |site|
    if site.theme
      file = site.in_theme_dir("_config.yml")
      JekyllData::ThemeConfiguration.reconfigure(site) if File.exist?(file)
    end
  end
end

# ---------------------------------------------------------------------------
# Replace Jekyll::Reader with a subclass JekyllData::Reader only if the
# site uses a gem-based theme.
#
# If a _config.yml exists at the root of the theme-gem, output its path.
# Placed here inorder to avoid outputting the path after every regeneration.
#
# *Jekyll 4.0 detects a theme-configuration natively.*
# ---------------------------------------------------------------------------
Jekyll::Hooks.register :site, :after_init do |site|
  if site.theme
    unless Jekyll::VERSION.start_with?("4")
      file = site.in_theme_dir("_config.yml")
      Jekyll.logger.info "Theme Config file:", file if File.exist?(file)
    end
    site.reader = JekyllData::Reader.new(site)
  end
end