code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def whitelist @whitelist ||= [site.config["whitelist"]].flatten end
Build an array of allowed plugin gem names. Returns an array of strings, each string being the name of a gem name that is allowed to be used.
whitelist
ruby
jekyll/jekyll
lib/jekyll/plugin_manager.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/plugin_manager.rb
MIT
def require_plugin_files unless site.safe plugins_path.each do |plugin_search_path| plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb")) Jekyll::External.require_with_graceful_fail(plugin_files) end end end
Require all .rb files if safe mode is off Returns nothing.
require_plugin_files
ruby
jekyll/jekyll
lib/jekyll/plugin_manager.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/plugin_manager.rb
MIT
def plugins_path if site.config["plugins_dir"].eql? Jekyll::Configuration::DEFAULTS["plugins_dir"] [site.in_source_dir(site.config["plugins_dir"])] else Array(site.config["plugins_dir"]).map { |d| File.expand_path(d) } end end
Public: Setup the plugin search path Returns an Array of plugin search paths
plugins_path
ruby
jekyll/jekyll
lib/jekyll/plugin_manager.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/plugin_manager.rb
MIT
def read @site.layouts = LayoutReader.new(site).read read_directories read_included_excludes sort_files! CollectionReader.new(site).read ThemeAssetsReader.new(site).read read_data end
Read Site data from disk and load it into internal data structures. Returns nothing.
read
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def read_data @site.data = DataReader.new(site).read(site.config["data_dir"]) return unless site.theme&.data_path theme_data = DataReader.new( site, :in_source_dir => site.method(:in_theme_dir) ).read(site.theme.data_path) @site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data) end
Read and merge the data files. If a theme is specified and it contains data, it will be read. Site data will overwrite theme data with the same key using the semantics of Utils.deep_merge_hashes. Returns nothing.
read_data
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def sort_files! site.collections.each_value { |c| c.docs.sort! } site.pages.sort_by!(&:name) site.static_files.sort_by!(&:relative_path) end
Sorts posts, pages, and static files.
sort_files!
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def read_directories(dir = "") base = site.in_source_dir(dir) return unless File.directory?(base) dot_dirs = [] dot_pages = [] dot_static_files = [] dot = Dir.chdir(base) { filter_entries(Dir.entries("."), base) } dot.each do |entry| file_path = @site.in_source_dir(base, entry) if File.directory?(file_path) dot_dirs << entry elsif Utils.has_yaml_header?(file_path) dot_pages << entry else dot_static_files << entry end end retrieve_posts(dir) retrieve_dirs(base, dir, dot_dirs) retrieve_pages(dir, dot_pages) retrieve_static_files(dir, dot_static_files) end
Recursively traverse directories to find pages and static files that will become part of the site according to the rules in filter_entries. dir - The String relative path of the directory to read. Default: ''. Returns nothing.
read_directories
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def retrieve_posts(dir) return if outside_configured_directory?(dir) site.posts.docs.concat(post_reader.read_posts(dir)) site.posts.docs.concat(post_reader.read_drafts(dir)) if site.show_drafts end
Retrieves all the posts(posts/drafts) from the given directory and add them to the site and sort them. dir - The String representing the directory to retrieve the posts from. Returns nothing.
retrieve_posts
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def retrieve_dirs(_base, dir, dot_dirs) dot_dirs.each do |file| dir_path = site.in_source_dir(dir, file) rel_path = PathManager.join(dir, file) @site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path end end
Recursively traverse directories with the read_directories function. base - The String representing the site's base directory. dir - The String representing the directory to traverse down. dot_dirs - The Array of subdirectories in the dir. Returns nothing.
retrieve_dirs
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def retrieve_pages(dir, dot_pages) site.pages.concat(PageReader.new(site, dir).read(dot_pages)) end
Retrieve all the pages from the current directory, add them to the site and sort them. dir - The String representing the directory retrieve the pages from. dot_pages - The Array of pages in the dir. Returns nothing.
retrieve_pages
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def retrieve_static_files(dir, dot_static_files) site.static_files.concat(StaticFileReader.new(site, dir).read(dot_static_files)) end
Retrieve all the static files from the current directory, add them to the site and sort them. dir - The directory retrieve the static files from. dot_static_files - The static files in the dir. Returns nothing.
retrieve_static_files
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def filter_entries(entries, base_directory = nil) EntryFilter.new(site, base_directory).filter(entries) end
Filter out any files/directories that are hidden or backup files (start with "." or "#" or end with "~"), or contain site content (start with "_"), or are excluded in the site configuration, unless they are web server files such as '.htaccess'. entries - The Array of String file/directory entries to filter. base_directory - The string representing the optional base directory. Returns the Array of filtered entries.
filter_entries
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def get_entries(dir, subfolder) base = site.in_source_dir(dir, subfolder) return [] unless File.exist?(base) entries = Dir.chdir(base) { filter_entries(Dir["**/*"], base) } entries.delete_if { |e| File.directory?(site.in_source_dir(base, e)) } end
Read the entries from a particular directory for processing dir - The String representing the relative path of the directory to read. subfolder - The String representing the directory to read. Returns the list of entries to process
get_entries
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def outside_configured_directory?(dir) collections_dir = site.config["collections_dir"] !collections_dir.empty? && !dir.start_with?("/#{collections_dir}") end
Internal Determine if the directory is supposed to contain posts and drafts. If the user has defined a custom collections_dir, then attempt to read posts and drafts only from within that directory. Returns true if a custom collections_dir has been set but current directory lies outside that directory.
outside_configured_directory?
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def post_reader @post_reader ||= PostReader.new(site) end
Create a single PostReader instance to retrieve drafts and posts from all valid directories in current site.
post_reader
ruby
jekyll/jekyll
lib/jekyll/reader.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/reader.rb
MIT
def regenerate?(document) return true if disabled case document when Page regenerate_page?(document) when Document regenerate_document?(document) else source_path = document.respond_to?(:path) ? document.path : nil dest_path = document.destination(@site.dest) if document.respond_to?(:destination) source_modified_or_dest_missing?(source_path, dest_path) end end
Checks if a renderable object needs to be regenerated Returns a boolean.
regenerate?
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def add(path) return true unless File.exist?(path) metadata[path] = { "mtime" => File.mtime(path), "deps" => [], } cache[path] = true end
Add a path to the metadata Returns true, also on failure.
add
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def force(path) cache[path] = true end
Force a path to regenerate Returns true.
force
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def clear @metadata = {} clear_cache end
Clear the metadata and cache Returns nothing
clear
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def clear_cache @cache = {} end
Clear just the cache Returns nothing
clear_cache
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def source_modified_or_dest_missing?(source_path, dest_path) modified?(source_path) || (dest_path && !File.exist?(dest_path)) end
Checks if the source has been modified or the destination is missing returns a boolean
source_modified_or_dest_missing?
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def modified?(path) return true if disabled? # objects that don't have a path are always regenerated return true if path.nil? # Check for path in cache return cache[path] if cache.key? path if metadata[path] # If we have seen this file before, # check if it or one of its dependencies has been modified existing_file_modified?(path) else # If we have not seen this file before, add it to the metadata and regenerate it add(path) end end
Checks if a path's (or one of its dependencies) mtime has changed Returns a boolean.
modified?
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def add_dependency(path, dependency) return if metadata[path].nil? || disabled unless metadata[path]["deps"].include? dependency metadata[path]["deps"] << dependency add(dependency) unless metadata.include?(dependency) end regenerate? dependency end
Add a dependency of a path Returns nothing.
add_dependency
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def write_metadata unless disabled? Jekyll.logger.debug "Writing Metadata:", ".jekyll-metadata" File.binwrite(metadata_file, Marshal.dump(metadata)) end end
Write the metadata to disk Returns nothing.
write_metadata
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def metadata_file @metadata_file ||= site.in_source_dir(".jekyll-metadata") end
Produce the absolute path of the metadata file Returns the String path of the file.
metadata_file
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def disabled? self.disabled = !site.incremental? if disabled.nil? disabled end
Check if metadata has been disabled Returns a Boolean (true for disabled, false for enabled).
disabled?
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def read_metadata @metadata = if !disabled? && File.file?(metadata_file) content = File.binread(metadata_file) begin Marshal.load(content) rescue TypeError SafeYAML.load(content) rescue ArgumentError => e Jekyll.logger.warn("Failed to load #{metadata_file}: #{e}") {} end else {} end end
Read metadata from the metadata file, if no file is found, initialize with an empty hash Returns the read metadata.
read_metadata
ruby
jekyll/jekyll
lib/jekyll/regenerator.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/regenerator.rb
MIT
def payload @payload ||= site.site_payload end
Fetches the payload used in Liquid rendering. It can be written with #payload=(new_payload) Falls back to site.site_payload if no payload is set. Returns a Jekyll::Drops::UnifiedPayloadDrop
payload
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def layouts @layouts || site.layouts end
The list of layouts registered for this Renderer. It can be written with #layouts=(new_layouts) Falls back to site.layouts if no layouts are registered. Returns a Hash of String => Jekyll::Layout identified as basename without the extension name.
layouts
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def converters @converters ||= site.converters.select { |c| c.matches(document.extname) }.tap(&:sort!) end
Determine which converters to use based on this document's extension. Returns Array of Converter instances.
converters
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def output_ext @output_ext ||= (permalink_ext || converter_output_ext) end
Determine the extname the outputted file should have Returns String the output extname including the leading period.
output_ext
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def run Jekyll.logger.debug "Rendering:", document.relative_path assign_pages! assign_current_document! assign_highlighter_options! assign_layout_data! Jekyll.logger.debug "Pre-Render Hooks:", document.relative_path document.trigger_hooks(:pre_render, payload) render_document end
Prepare payload and render the document Returns String rendered document output
run
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def render_document info = { :registers => { :site => site, :page => payload["page"] }, :strict_filters => liquid_options["strict_filters"], :strict_variables => liquid_options["strict_variables"], } output = document.content if document.render_with_liquid? Jekyll.logger.debug "Rendering Liquid:", document.relative_path output = render_liquid(output, payload, info, document.path) end Jekyll.logger.debug "Rendering Markup:", document.relative_path output = convert(output.to_s) document.content = output Jekyll.logger.debug "Post-Convert Hooks:", document.relative_path document.trigger_hooks(:post_convert) output = document.content if document.place_in_layout? Jekyll.logger.debug "Rendering Layout:", document.relative_path output = place_in_layouts(output, payload, info) end output end
Render the document. Returns String rendered document output rubocop: disable Metrics/AbcSize, Metrics/MethodLength
render_document
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def convert(content) converters.reduce(content) do |output, converter| converter.convert output rescue StandardError => e Jekyll.logger.error "Conversion error:", "#{converter.class} encountered an error while " \ "converting '#{document.relative_path}':" Jekyll.logger.error("", e.to_s) raise e end end
rubocop: enable Metrics/AbcSize, Metrics/MethodLength Convert the document using the converters which match this renderer's document. Returns String the converted content.
convert
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def render_liquid(content, payload, info, path = nil) template = site.liquid_renderer.file(path).parse(content) template.warnings.each do |e| Jekyll.logger.warn "Liquid Warning:", LiquidRenderer.format_error(e, path || document.relative_path) end template.render!(payload, info) # rubocop: disable Lint/RescueException rescue Exception => e Jekyll.logger.error "Liquid Exception:", LiquidRenderer.format_error(e, path || document.relative_path) raise e end
Render the given content with the payload and info content - payload - info - path - (optional) the path to the file, for use in ex Returns String the content, rendered by Liquid.
render_liquid
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def invalid_layout?(layout) !document.data["layout"].nil? && layout.nil? && !(document.is_a? Jekyll::Excerpt) end
rubocop: enable Lint/RescueException Checks if the layout specified in the document actually exists layout - the layout to check Returns Boolean true if the layout is invalid, false if otherwise
invalid_layout?
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def place_in_layouts(content, payload, info) output = content.dup layout = layouts[document.data["layout"].to_s] validate_layout(layout) used = Set.new([layout]) # Reset the payload layout data to ensure it starts fresh for each page. payload["layout"] = nil while layout output = render_layout(output, layout, info) add_regenerator_dependencies(layout) next unless (layout = site.layouts[layout.data["layout"]]) break if used.include?(layout) used << layout end output end
Render layouts and place document content inside. Returns String rendered content
place_in_layouts
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def validate_layout(layout) return unless invalid_layout?(layout) Jekyll.logger.warn "Build Warning:", "Layout '#{document.data["layout"]}' requested " \ "in #{document.relative_path} does not exist." end
Checks if the layout specified in the document actually exists layout - the layout to check Returns nothing
validate_layout
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def render_layout(output, layout, info) payload["content"] = output payload["layout"] = Utils.deep_merge_hashes(layout.data, payload["layout"] || {}) render_liquid( layout.content, payload, info, layout.path ) end
Render layout content into document.output Returns String rendered content
render_layout
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def assign_pages! payload["page"] = document.to_liquid payload["paginator"] = (document.pager.to_liquid if document.respond_to?(:pager)) end
Set page content to payload and assign pager if document has one. Returns nothing
assign_pages!
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def assign_current_document! payload["site"].current_document = document end
Set related posts to payload if document is a post. Returns nothing
assign_current_document!
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def assign_highlighter_options! payload["highlighter_prefix"] = converters.first.highlighter_prefix payload["highlighter_suffix"] = converters.first.highlighter_suffix end
Set highlighter prefix and suffix Returns nothing
assign_highlighter_options!
ruby
jekyll/jekyll
lib/jekyll/renderer.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/renderer.rb
MIT
def initialize(config) # Source and destination may not be changed after the site has been created. @source = File.expand_path(config["source"]).freeze @dest = File.expand_path(config["destination"]).freeze self.config = config @cache_dir = in_source_dir(config["cache_dir"]) @filter_cache = {} @reader = Reader.new(self) @profiler = Profiler.new(self) @regenerator = Regenerator.new(self) @liquid_renderer = LiquidRenderer.new(self) Jekyll.sites << self reset setup Jekyll::Hooks.trigger :site, :after_init, self end
Public: Initialize a new Site. config - A Hash containing site configuration details.
initialize
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def process return profiler.profile_process if config["profile"] reset read generate render cleanup write end
Public: Read, process, and write this Site to output. Returns nothing.
process
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def reset self.time = if config["time"] Utils.parse_date(config["time"].to_s, "Invalid time in _config.yml.") else Time.now end self.layouts = {} self.inclusions = {} self.pages = [] self.static_files = [] self.data = {} @post_attr_hash = {} @site_data = nil @collections = nil @documents = nil @docs_to_write = nil @regenerator.clear_cache @liquid_renderer.reset @site_cleaner = nil frontmatter_defaults.reset raise ArgumentError, "limit_posts must be a non-negative number" if limit_posts.negative? Jekyll::Cache.clear_if_config_changed config Jekyll::Hooks.trigger :site, :after_reset, self nil end
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength Reset Site details. Returns nothing
reset
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def setup ensure_not_in_dest plugin_manager.conscientious_require self.converters = instantiate_subclasses(Jekyll::Converter) self.generators = instantiate_subclasses(Jekyll::Generator) end
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize Load necessary libraries, plugins, converters, and generators. Returns nothing.
setup
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def ensure_not_in_dest dest_pathname = Pathname.new(dest) Pathname.new(source).ascend do |path| if path == dest_pathname raise Errors::FatalException, "Destination directory cannot be or contain the Source directory." end end end
Check that the destination dir isn't the source dir or a directory parent to the source dir.
ensure_not_in_dest
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def collections @collections ||= collection_names.each_with_object({}) do |name, hsh| hsh[name] = Jekyll::Collection.new(self, name) end end
The list of collections and their corresponding Jekyll::Collection instances. If config['collections'] is set, a new instance is created for each item in the collection, a new hash is returned otherwise. Returns a Hash containing collection name-to-instance pairs.
collections
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def collection_names case config["collections"] when Hash config["collections"].keys when Array config["collections"] when nil [] else raise ArgumentError, "Your `collections` key must be a hash or an array." end end
The list of collection names. Returns an array of collection names from the configuration, or an empty array if the `collections` key is not set.
collection_names
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def read reader.read limit_posts! Jekyll::Hooks.trigger :site, :post_read, self nil end
Read Site data from disk and load it into internal data structures. Returns nothing.
read
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def generate generators.each do |generator| start = Time.now generator.generate(self) Jekyll.logger.debug "Generating:", "#{generator.class} finished in #{Time.now - start} seconds." end nil end
Run each of the Generators. Returns nothing.
generate
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def render relative_permalinks_are_deprecated payload = site_payload Jekyll::Hooks.trigger :site, :pre_render, self, payload render_docs(payload) render_pages(payload) Jekyll::Hooks.trigger :site, :post_render, self, payload nil end
Render the site to the destination. Returns nothing.
render
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def cleanup site_cleaner.cleanup! nil end
Remove orphaned files and empty directories in destination. Returns nothing.
cleanup
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def write Jekyll::Commands::Doctor.conflicting_urls(self) each_site_file do |item| item.write(dest) if regenerator.regenerate?(item) end regenerator.write_metadata Jekyll::Hooks.trigger :site, :post_write, self nil end
Write static files, pages, and posts. Returns nothing.
write
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def post_attr_hash(post_attr) # Build a hash map based on the specified post attribute ( post attr => # array of posts ) then sort each array in reverse order. @post_attr_hash[post_attr] ||= begin hash = Hash.new { |h, key| h[key] = [] } posts.docs.each do |p| p.data[post_attr]&.each { |t| hash[t] << p } end hash.each_value { |posts| posts.sort!.reverse! } hash end end
Construct a Hash of Posts indexed by the specified Post attribute. post_attr - The String name of the Post attribute. Examples post_attr_hash('categories') # => { 'tech' => [<Post A>, <Post B>], # 'ruby' => [<Post B>] } Returns the Hash: { attr => posts } where attr - One of the values for the requested attribute. posts - The Array of Posts with the given attr value.
post_attr_hash
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def site_data @site_data ||= (config["data"] || data) end
Prepare site data for site payload. The method maintains backward compatibility if the key 'data' is already used in _config.yml. Returns the Hash to be hooked to site.data.
site_data
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def site_payload Drops::UnifiedPayloadDrop.new self end
The Hash payload containing site-wide data. Returns the Hash: { "site" => data } where data is a Hash with keys: "time" - The Time as specified in the configuration or the current time if none was specified. "posts" - The Array of Posts, sorted chronologically by post date and then title. "pages" - The Array of all Pages. "html_pages" - The Array of HTML Pages. "categories" - The Hash of category values and Posts. See Site#post_attr_hash for type info. "tags" - The Hash of tag values and Posts. See Site#post_attr_hash for type info.
site_payload
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def find_converter_instance(klass) @find_converter_instance ||= {} @find_converter_instance[klass] ||= converters.find do |converter| converter.instance_of?(klass) end || \ raise("No Converters found for #{klass}") end
Get the implementation class for the given Converter. Returns the Converter instance implementing the given Converter. klass - The Class of the Converter to fetch.
find_converter_instance
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def instantiate_subclasses(klass) klass.descendants.select { |c| !safe || c.safe }.tap do |result| result.sort! result.map! { |c| c.new(config) } end end
klass - class or module containing the subclasses. Returns array of instances of subclasses of parameter. Create array of instances of the subclasses of the class or module passed in as argument.
instantiate_subclasses
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def relative_permalinks_are_deprecated if config["relative_permalinks"] Jekyll.logger.abort_with "Since v3.0, permalinks for pages " \ "in subfolders must be relative to the " \ "site source directory, not the parent " \ "directory. Check https://jekyllrb.com/docs/upgrading/ " \ "for more info." end end
Warns the user if permanent links are relative to the parent directory. As this is a deprecated function of Jekyll. Returns
relative_permalinks_are_deprecated
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def documents collections.each_with_object(Set.new) do |(_, collection), set| set.merge(collection.docs).merge(collection.files) end.to_a end
Get all the documents Returns an Array of all Documents
documents
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def frontmatter_defaults @frontmatter_defaults ||= FrontmatterDefaults.new(self) end
Returns the FrontmatterDefaults or creates a new FrontmatterDefaults if it doesn't already exist. Returns The FrontmatterDefaults
frontmatter_defaults
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def incremental?(override = {}) override["incremental"] || config["incremental"] end
Whether to perform a full rebuild without incremental regeneration Returns a Boolean: true for a full rebuild, false for normal build
incremental?
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def publisher @publisher ||= Publisher.new(self) end
Returns the publisher or creates a new publisher if it doesn't already exist. Returns The Publisher
publisher
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def in_source_dir(*paths) paths.reduce(source) do |base, path| Jekyll.sanitized_path(base, path) end end
Public: Prefix a given path with the source directory. paths - (optional) path elements to a file or directory within the source directory Returns a path which is prefixed with the source directory.
in_source_dir
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def in_theme_dir(*paths) return nil unless theme paths.reduce(theme.root) do |base, path| Jekyll.sanitized_path(base, path) end end
Public: Prefix a given path with the theme directory. paths - (optional) path elements to a file or directory within the theme directory Returns a path which is prefixed with the theme root directory.
in_theme_dir
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def in_dest_dir(*paths) paths.reduce(dest) do |base, path| Jekyll.sanitized_path(base, path) end end
Public: Prefix a given path with the destination directory. paths - (optional) path elements to a file or directory within the destination directory Returns a path which is prefixed with the destination directory.
in_dest_dir
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def in_cache_dir(*paths) paths.reduce(cache_dir) do |base, path| Jekyll.sanitized_path(base, path) end end
Public: Prefix a given path with the cache directory. paths - (optional) path elements to a file or directory within the cache directory Returns a path which is prefixed with the cache directory.
in_cache_dir
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def collections_path dir_str = config["collections_dir"] @collections_path ||= dir_str.empty? ? source : in_source_dir(dir_str) end
Public: The full path to the directory that houses all the collections registered with the current site. Returns the source directory or the absolute path to the custom collections_dir
collections_path
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def inspect "#<#{self.class} @source=#{@source}>" end
Public Returns the object as a debug String.
inspect
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def site_cleaner @site_cleaner ||= Cleaner.new(self) end
Returns the Cleaner or creates a new Cleaner if it doesn't already exist. Returns The Cleaner
site_cleaner
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def configure_cache Jekyll::Cache.cache_dir = in_source_dir(config["cache_dir"], "Jekyll/Cache") if safe || config["disable_disk_cache"] Jekyll::Cache.disable_disk_cache! else hide_cache_dir_from_git end end
Disable Marshaling cache to disk in Safe Mode
configure_cache
ruby
jekyll/jekyll
lib/jekyll/site.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/site.rb
MIT
def mtimes @mtimes ||= {} end
The cache of last modification times [path] -> mtime.
mtimes
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def initialize(site, base, dir, name, collection = nil) @site = site @base = base @dir = dir @name = name @collection = collection @relative_path = File.join(*[@dir, @name].compact) @extname = File.extname(@name) @type = @collection&.label&.to_sym end
Initialize a new StaticFile. site - The Site. base - The String path to the <source>. dir - The String path between <source> and the file. name - The String filename of the file. rubocop: disable Metrics/ParameterLists
initialize
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def path @path ||= if !@collection.nil? && !@site.config["collections_dir"].empty? File.join(*[@base, @site.config["collections_dir"], @dir, @name].compact) else File.join(*[@base, @dir, @name].compact) end end
rubocop: enable Metrics/ParameterLists Returns source file path.
path
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def destination(dest) @destination ||= {} @destination[dest] ||= @site.in_dest_dir(dest, Jekyll::URL.unescape_path(url)) end
Obtain destination path. dest - The String path to the destination dir. Returns destination file path.
destination
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def modified? self.class.mtimes[path] != mtime end
Is source path modified? Returns true if modified since last write.
modified?
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def write? publishable = defaults.fetch("published", true) return publishable unless @collection publishable && @collection.write? end
Whether to write the file to the filesystem Returns true unless the defaults for the destination path from _config.yml contain `published: false`.
write?
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def write(dest) dest_path = destination(dest) return false if File.exist?(dest_path) && !modified? self.class.mtimes[path] = mtime FileUtils.mkdir_p(File.dirname(dest_path)) FileUtils.rm(dest_path) if File.exist?(dest_path) copy_file(dest_path) true end
Write the static file to the destination directory (if modified). dest - The String path to the destination dir. Returns false if the file was not modified since last time (no-op).
write
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def basename @basename ||= File.basename(name, extname).gsub(%r!\.*\z!, "") end
Generate "basename without extension" and strip away any trailing periods. NOTE: `String#gsub` removes all trailing periods (in comparison to `String#chomp`)
basename
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def cleaned_relative_path @cleaned_relative_path ||= begin cleaned = relative_path[0..-extname.length - 1] cleaned.gsub!(%r!\.*\z!, "") cleaned.sub!(@collection.relative_directory, "") if @collection cleaned end end
Similar to Jekyll::Document#cleaned_relative_path. Generates a relative path with the collection's directory removed when applicable and additionally removes any multiple periods in the string. NOTE: `String#gsub!` removes all trailing periods (in comparison to `String#chomp!`) Examples: When `relative_path` is "_methods/site/my-cool-avatar...png": cleaned_relative_path # => "/site/my-cool-avatar" Returns the cleaned relative path of the static file.
cleaned_relative_path
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def url @url ||= begin base = if @collection.nil? cleaned_relative_path else Jekyll::URL.new( :template => @collection.url_template, :placeholders => placeholders ) end.to_s.chomp("/") base << extname end end
Applies a similar URL-building technique as Jekyll::Document that takes the collection's URL template into account. The default URL template can be overridden in the collection's configuration in _config.yml.
url
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def defaults @defaults ||= @site.frontmatter_defaults.all url, type end
Returns the front matter defaults defined for the file's URL and/or type as defined in _config.yml.
defaults
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def inspect "#<#{self.class} @relative_path=#{relative_path.inspect}>" end
Returns a debug string on inspecting the static file. Includes only the relative path of the object.
inspect
ruby
jekyll/jekyll
lib/jekyll/static_file.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/static_file.rb
MIT
def initialize(options) @template = options[:template] @placeholders = options[:placeholders] || {} @permalink = options[:permalink] if (@template || @permalink).nil? raise ArgumentError, "One of :template or :permalink must be supplied." end end
options - One of :permalink or :template must be supplied. :template - The String used as template for URL generation, for example "/:path/:basename:output_ext", where a placeholder is prefixed with a colon. :placeholders - A hash containing the placeholders which will be replaced when used inside the template. E.g. { "year" => Time.now.strftime("%Y") } would replace the placeholder ":year" with the current year. :permalink - If supplied, no URL will be generated from the template. Instead, the given permalink will be used as URL.
initialize
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def to_s sanitize_url(generated_permalink || generated_url) end
The generated relative URL of the resource Returns the String URL
to_s
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def generated_permalink (@generated_permalink ||= generate_url(@permalink)) if @permalink end
Generates a URL from the permalink Returns the _unsanitized String URL
generated_permalink
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def generated_url @generated_url ||= generate_url(@template) end
Generates a URL from the template Returns the unsanitized String URL
generated_url
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def generate_url(template) if @placeholders.is_a? Drops::UrlDrop generate_url_from_drop(template) else generate_url_from_hash(template) end end
Internal: Generate the URL by replacing all placeholders with their respective values in the given template Returns the unsanitized String URL
generate_url
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def possible_keys(key) if key.end_with?("_") [key, key.chomp("_")] else [key] end end
We include underscores in keys to allow for 'i_month' and so forth. This poses a problem for keys which are followed by an underscore but the underscore is not part of the key, e.g. '/:month_:day'. That should be :month and :day, but our key extraction regexp isn't smart enough to know that so we have to make it an explicit possibility.
possible_keys
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def sanitize_url(str) "/#{str}".gsub("..", "/").tap do |result| result.gsub!("./", "") result.squeeze!("/") end end
Returns a sanitized String URL, stripping "../../" and multiples of "/", as well as the beginning "/" so we can enforce and ensure it.
sanitize_url
ruby
jekyll/jekyll
lib/jekyll/url.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/url.rb
MIT
def titleize_slug(slug) slug.split("-").map!(&:capitalize).join(" ") end
Takes a slug and turns it into a simple title.
titleize_slug
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def deep_merge_hashes(master_hash, other_hash) deep_merge_hashes!(master_hash.dup, other_hash) end
Non-destructive version of deep_merge_hashes! See that method. Returns the merged hashes.
deep_merge_hashes
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def deep_merge_hashes!(target, overwrite) merge_values(target, overwrite) merge_default_proc(target, overwrite) duplicate_frozen_values(target) target end
Merges a master hash with another hash, recursively. master_hash - the "parent" hash whose values will be overridden other_hash - the other hash whose values will be persisted after the merge This code was lovingly stolen from some random gem: http://gemjack.com/gems/tartan-0.1.1/classes/Hash.html Thanks to whoever made it.
deep_merge_hashes!
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def pluralized_array_from_hash(hash, singular_key, plural_key) array = [] value = value_from_singular_key(hash, singular_key) value ||= value_from_plural_key(hash, plural_key) array << value array.flatten! array.compact! array end
Read array from the supplied hash favouring the singular key and then the plural key, and handling any nil entries. hash - the hash to read from singular_key - the singular key plural_key - the plural key Returns an array
pluralized_array_from_hash
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def symbolize_hash_keys(hash) transform_keys(hash) { |key| key.to_sym rescue key } end
Apply #to_sym to all keys in the hash hash - the hash to which to apply this transformation Returns a new hash with symbolized keys
symbolize_hash_keys
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def stringify_hash_keys(hash) transform_keys(hash) { |key| key.to_s rescue key } end
Apply #to_s to all keys in the Hash hash - the hash to which to apply this transformation Returns a new hash with stringified keys
stringify_hash_keys
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def parse_date(input, msg = "Input could not be parsed.") @parse_date_cache ||= {} @parse_date_cache[input] ||= Time.parse(input).localtime rescue ArgumentError raise Errors::InvalidDateError, "Invalid date '#{input}': #{msg}" end
Parse a date/time and throw an error if invalid input - the date/time to parse msg - (optional) the error message to show the user Returns the parsed date if successful, throws a FatalException if not
parse_date
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def has_yaml_header?(file) File.open(file, "rb", &:readline).match? %r!\A---\s*\r?\n! rescue EOFError false end
Determines whether a given file has Returns true if the YAML front matter is present. rubocop: disable Naming/PredicateName
has_yaml_header?
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT
def has_liquid_construct?(content) return false if content.nil? || content.empty? content.include?("{%") || content.include?("{{") end
Determine whether the given content string contains Liquid Tags or Variables Returns true is the string contains sequences of `{%` or `{{`
has_liquid_construct?
ruby
jekyll/jekyll
lib/jekyll/utils.rb
https://github.com/jekyll/jekyll/blob/master/lib/jekyll/utils.rb
MIT