module Bridgetown::Site::Configurable
Public Instance Methods
Returns a base path from which the site is served (aka `/cool-site`) or `/` if served from root.
@param strip_slash_only [Boolean] set to true if you wish “/” to be returned as “” @return [String]
# File lib/bridgetown-core/concerns/site/configurable.rb, line 41 def base_path(strip_slash_only: false) (config[:base_path] || config[:baseurl]).yield_self do |path| strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path end end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 47 def baseurl Bridgetown::Deprecator.deprecation_message "Site#baseurl is now Site#base_path" base_path(strip_slash_only: true).presence end
The full path to the directory that houses all the registered collections
for the current site. If `@collections_path` is specified use its value. If `@collections` is not specified and `config["collections_dir"]` is specified, prepend it with {#source} and assign it to {#collections_path}. If `@collections` is not specified and `config["collections_dir"]` is not specified, assign {#source} to `@collections_path`
@return [String] Returns the full path to the collections directory @see config @see source @see collections_path
@see in_source_dir
# File lib/bridgetown-core/concerns/site/configurable.rb, line 157 def collections_path dir_str = config["collections_dir"] @collections_path ||= dir_str.empty? ? source : in_source_dir(dir_str) end
Set the site's configuration. This handles side-effects caused by
changing values in the configuration.
@param config [Configuration]
An instance of {Configuration}, containing the new configuration.
@return [Configuration]
The processed instance of {Configuration}
# File lib/bridgetown-core/concerns/site/configurable.rb, line 14 def config=(config) @config = config.clone # Source and destination may not be changed after the site has been created. @root_dir = File.expand_path(config["root_dir"]).freeze @source = File.expand_path(config["source"]).freeze @dest = File.expand_path(config["destination"]).freeze configure_cache configure_component_paths configure_include_paths configure_file_read_opts self.permalink_style = (config["permalink"] || "pretty").to_sym @config end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 52 def defaults_reader @defaults_reader ||= Bridgetown::DefaultsReader.new(self) end
Returns the current instance of {FrontmatterDefaults} or
creates a new instance {FrontmatterDefaults} if it doesn't already exist.
@return [FrontmatterDefaults]
Returns an instance of {FrontmatterDefaults}
# File lib/bridgetown-core/concerns/site/configurable.rb, line 61 def frontmatter_defaults @frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self) end
Prefix a path or paths with the {#cache_dir} directory.
@see Bridgetown.sanitized_path
@param paths [Array<String>]
An array of paths to prefix with the {#cache_dir} directory using the {Bridgetown.sanitized_path} method.
@return [Array<String>] Return an array of updated paths if multiple paths given.
# File lib/bridgetown-core/concerns/site/configurable.rb, line 134 def in_cache_dir(*paths) paths.reduce(cache_dir) do |base, path| Bridgetown.sanitized_path(base, path) end end
Prefix a path or paths with the {#dest} directory.
@see Bridgetown.sanitized_path
@param paths [Array<String>]
An array of paths to prefix with the destination directory using the {Bridgetown.sanitized_path} method.
@return [Array<String>] Return an array of updated paths if multiple paths given.
# File lib/bridgetown-core/concerns/site/configurable.rb, line 120 def in_dest_dir(*paths) paths.reduce(dest) do |base, path| Bridgetown.sanitized_path(base, path) end end
Prefix a path or paths with the {#root_dir} directory.
@see Bridgetown.sanitized_path
@param paths [Array<String>]
An array of paths to prefix with the root_dir directory using the {Bridgetown.sanitized_path} method.
@return [Array<String>] Return an array of updated paths if multiple paths given.
# File lib/bridgetown-core/concerns/site/configurable.rb, line 93 def in_root_dir(*paths) paths.reduce(root_dir) do |base, path| Bridgetown.sanitized_path(base, path.to_s) end end
Prefix a path or paths with the {#source} directory.
@see Bridgetown.sanitized_path
@param paths [Array<String>]
An array of paths to prefix with the source directory using the {Bridgetown.sanitized_path} method.
@return [Array<String>] Return an array of updated paths if multiple paths given.
# File lib/bridgetown-core/concerns/site/configurable.rb, line 106 def in_source_dir(*paths) paths.reduce(source) do |base, path| Bridgetown.sanitized_path(base, path.to_s) end end
Whether to perform a full rebuild without incremental regeneration.
If either `override["incremental"]` or `config["incremental"]` are true, fully rebuild the site. If not, incrementally build the site.
@param [Hash] override
An override hash to override the current config value
@option override [Boolean] “incremental” Whether to incrementally build @return [Boolean] true for full rebuild, false for normal build
# File lib/bridgetown-core/concerns/site/configurable.rb, line 73 def incremental?(override = {}) override["incremental"] || config["incremental"] end
Returns the current instance of {Publisher} or creates a new instance of
{Publisher} if one doesn't exist.
@return [Publisher] Returns an instance of {Publisher}
# File lib/bridgetown-core/concerns/site/configurable.rb, line 81 def publisher @publisher ||= Bridgetown::Publisher.new(self) end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 32 def uses_resource? config[:content_engine] == "resource" end
Private Instance Methods
Disable Marshaling cache to disk in Safe Mode
# File lib/bridgetown-core/concerns/site/configurable.rb, line 165 def configure_cache @cache_dir = in_root_dir(config["cache_dir"]).freeze Bridgetown::Cache.cache_dir = File.join(cache_dir, "Bridgetown/Cache") Bridgetown::Cache.disable_disk_cache! if config["disable_disk_cache"] end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 171 def configure_component_paths # Loop through plugins paths first plugin_components_load_paths = Bridgetown::PluginManager.source_manifests .map(&:components).compact local_components_load_paths = config["components_dir"].yield_self do |dir| dir.is_a?(Array) ? dir : [dir] end local_components_load_paths.map! do |dir| if !!(dir =~ %r!^\.\.?\/!) # allow ./dir or ../../dir type options File.expand_path(dir.to_s, root_dir) else in_source_dir(dir.to_s) end end @components_load_paths = plugin_components_load_paths + local_components_load_paths end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 195 def configure_file_read_opts self.file_read_opts = {} file_read_opts[:encoding] = config["encoding"] if config["encoding"] self.file_read_opts = Bridgetown::Utils.merged_file_read_opts(self, {}) end
# File lib/bridgetown-core/concerns/site/configurable.rb, line 191 def configure_include_paths @includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s)) end