Class: GitHubPages::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/github-pages/configuration.rb

Overview

Sets and manages Jekyll configuration defaults and overrides

Constant Summary collapse

DEFAULT_PLUGINS =

Backward compatability of constants

GitHubPages::Plugins::DEFAULT_PLUGINS
PLUGIN_WHITELIST =
GitHubPages::Plugins::PLUGIN_WHITELIST
DEVELOPMENT_PLUGINS =
GitHubPages::Plugins::DEVELOPMENT_PLUGINS
THEMES =
GitHubPages::Plugins::THEMES
DEFAULTS =

Default, user overwritable options

{
  "jailed" => false,
  "plugins" => GitHubPages::Plugins::DEFAULT_PLUGINS,
  "future" => true,
  "theme" => "jekyll-theme-primer",
  "markdown" => "kramdown",
  "kramdown" => {
    "input" => "GFM",
    "hard_wrap" => false,
    "gfm_quirks" => "paragraph_end",
    "syntax_highlighter_opts" => {
      "default_lang" => "plaintext",
    },
  },
  "exclude" => ["CNAME"],
}.freeze
PRODUCTION_DEFAULTS =

User-overwritable defaults used only in production for practical reasons

Jekyll::Utils.deep_merge_hashes DEFAULTS, {
  "sass" => {
    "style" => "compressed",
  },
}.freeze
OVERRIDES =

Options which GitHub Pages sets, regardless of the user-specified value

The following values are also overridden by GitHub Pages, but are not overridden locally, for practical purposes:

  • source

  • destination

  • jailed

  • verbose

  • incremental

  • GH_ENV

{
  "lsi" => false,
  "safe" => true,
  "plugins_dir" => SecureRandom.hex,
  "whitelist" => GitHubPages::Plugins::PLUGIN_WHITELIST,
  "highlighter" => "rouge",
  "kramdown" => {
    "template" => "",
    "math_engine" => "mathjax",
    "syntax_highlighter" => "rouge",
  },
  "gist" => {
    "noscript" => false,
  },
}.freeze

Class Method Summary collapse

Class Method Details

.defaults_for_envObject



82
83
84
85
# File 'lib/github-pages/configuration.rb', line 82

def defaults_for_env
  defaults = development? ? DEFAULTS : PRODUCTION_DEFAULTS
  Jekyll::Utils.deep_merge_hashes Jekyll::Configuration::DEFAULTS, defaults
end

.development?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/github-pages/configuration.rb', line 78

def development?
  Jekyll.env == "development"
end

.disable_whitelist?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/github-pages/configuration.rb', line 74

def disable_whitelist?
  development? && !ENV["DISABLE_WHITELIST"].to_s.empty?
end

.effective_config(user_config) ⇒ Object

Given a user’s config, determines the effective configuration by building a user configuration sandwhich with our overrides overriding the user’s specified values which themselves override our defaults.

Returns the effective Configuration

Note: this is a highly modified version of Jekyll#configuration



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/github-pages/configuration.rb', line 94

def effective_config(user_config)
  # Merge user config into defaults
  config = Jekyll::Utils.deep_merge_hashes(defaults_for_env, user_config)
    .fix_common_issues
    .add_default_collections

  # Allow theme to be explicitly disabled via "theme: null"
  config["theme"] = user_config["theme"] if user_config.key?("theme")

  migrate_theme_to_remote_theme(config)
  exclude_cname(config)

  # Merge overwrites into user config
  config = Jekyll::Utils.deep_merge_hashes config, OVERRIDES

  restrict_and_config_markdown_processor(config)

  configure_plugins(config)

  config
end

.processed(site) ⇒ Object



70
71
72
# File 'lib/github-pages/configuration.rb', line 70

def processed(site)
  site.instance_variable_set :@_github_pages_processed, true
end

.processed?(site) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/github-pages/configuration.rb', line 66

def processed?(site)
  site.instance_variable_get(:@_github_pages_processed) == true
end

.set(site) ⇒ Object

Set the site’s configuration. Implemented as an ‘after_reset` hook. Equivalent #set! function contains the code of interest. This function guards against double-processing via the value in #processed.



119
120
121
122
123
124
125
# File 'lib/github-pages/configuration.rb', line 119

def set(site)
  return if processed? site

  debug_print_versions
  set!(site)
  processed(site)
end

.set!(site) ⇒ Object

Set the site’s configuration with all the proper defaults and overrides. Should be called by #set to protect against multiple processings.



129
130
131
# File 'lib/github-pages/configuration.rb', line 129

def set!(site)
  site.config = effective_config(site.config)
end