Revert "Incrementally rebuild when a data file is changed (#8771)" (#9170)

Merge pull request 9170
This commit is contained in:
Ashwin Maroli
2022-10-26 22:08:14 +05:30
committed by GitHub
parent 04123c0cad
commit 5367a0261d
11 changed files with 5 additions and 315 deletions

View File

@@ -45,8 +45,6 @@ module Jekyll
autoload :Collection, "jekyll/collection"
autoload :Configuration, "jekyll/configuration"
autoload :Convertible, "jekyll/convertible"
autoload :DataEntry, "jekyll/data_entry"
autoload :DataHash, "jekyll/data_hash"
autoload :Deprecator, "jekyll/deprecator"
autoload :Document, "jekyll/document"
autoload :EntryFilter, "jekyll/entry_filter"

View File

@@ -1,83 +0,0 @@
# frozen_string_literal: true
module Jekyll
class DataEntry
attr_accessor :context
attr_reader :data
# Create a Jekyll wrapper for given parsed data object.
#
# site - The current Jekyll::Site instance.
# abs_path - Absolute path to the data source file.
# parsed_data - Parsed representation of data source file contents.
#
# Returns nothing.
def initialize(site, abs_path, parsed_data)
@site = site
@path = abs_path
@data = parsed_data
end
# Liquid representation of current instance is the parsed data object.
#
# Mark as a dependency for regeneration here since every renderable object primarily uses the
# parsed data object while the parent resource is being rendered by Liquid. Accessing the data
# object directly via Ruby interface `#[]()` is outside the scope of regeneration.
#
# FIXME: Marking as dependency on every call is non-ideal. Optimize at later day.
#
# Returns the parsed data object.
def to_liquid
add_regenerator_dependencies if incremental_build?
@data
end
# -- Overrides to maintain backwards compatibility --
# Any missing method will be forwarded to the underlying data object stored in the instance
# variable `@data`.
def method_missing(method, *args, &block)
@data.respond_to?(method) ? @data.send(method, *args, &block) : super
end
def respond_to_missing?(method, *)
@data.respond_to?(method) || super
end
def <=>(other)
data <=> (other.is_a?(self.class) ? other.data : other)
end
def ==(other)
data == (other.is_a?(self.class) ? other.data : other)
end
# Explicitly defined to bypass re-routing from `method_missing` hook for greater performance.
#
# Returns string representation of parsed data object.
def inspect
@data.inspect
end
private
def incremental_build?
@incremental = @site.config["incremental"] if @incremental.nil?
@incremental
end
def add_regenerator_dependencies
page = context.registers[:page]
return unless page&.key?("path")
absolute_path = \
if page["collection"]
@site.in_source_dir(@site.config["collections_dir"], page["path"])
else
@site.in_source_dir(page["path"])
end
@site.regenerator.add_dependency(absolute_path, @path)
end
end
end

View File

@@ -1,61 +0,0 @@
# frozen_string_literal: true
module Jekyll
# A class that behaves very similar to Ruby's `Hash` class yet different in how it is handled by
# Liquid. This class emulates Hash by delegation instead of inheritance to minimize overridden
# methods especially since some Hash methods returns another Hash instance instead of the
# subclass instance.
class DataHash
#
# Delegate given (zero-arity) method(s) to the Hash object stored in instance variable
# `@registry`.
# NOTE: Avoiding the use of `Forwardable` module's `def_delegators` for preventing unnecessary
# creation of interim objects on multiple calls.
def self.delegate_to_registry(*symbols)
symbols.each { |sym| define_method(sym) { @registry.send(sym) } }
end
private_class_method :delegate_to_registry
# -- core instance methods --
attr_accessor :context
def initialize
@registry = {}
end
def [](key)
@registry[key].tap do |value|
value.context = context if value.respond_to?(:context=)
end
end
# `Hash#to_liquid` returns the Hash instance itself.
# Mimic that behavior by returning `self` instead of returning the `@registry` variable value.
def to_liquid
self
end
# -- supplementary instance methods to emulate Hash --
delegate_to_registry :freeze, :inspect
def merge(other, &block)
merged_registry = @registry.merge(other, &block)
dup.tap { |d| d.instance_variable_set(:@registry, merged_registry) }
end
def merge!(other, &block)
@registry.merge!(other, &block)
self
end
def method_missing(method, *args, &block)
@registry.send(method, *args, &block)
end
def respond_to_missing?(method, *)
@registry.respond_to?(method)
end
end
end

View File

@@ -7,6 +7,7 @@ module Jekyll
mutable false
delegate_method_as :site_data, :data
delegate_methods :time, :pages, :static_files, :tags, :categories
private delegate_method_as :config, :fallback_data
@@ -23,12 +24,6 @@ module Jekyll
(key != "posts" && @obj.collections.key?(key)) || super
end
def data
@obj.site_data.tap do |value|
value.context = @context if value.respond_to?(:context=)
end
end
def posts
@site_posts ||= @obj.posts.docs.sort { |a, b| b <=> a }
end

View File

@@ -6,7 +6,7 @@ module Jekyll
def initialize(site, in_source_dir: nil)
@site = site
@content = DataHash.new
@content = {}
@entry_filter = EntryFilter.new(site)
@in_source_dir = in_source_dir || @site.method(:in_source_dir)
@source_dir = @in_source_dir.call("/")
@@ -24,8 +24,6 @@ module Jekyll
@content
end
# rubocop:disable Metrics/AbcSize
# Read and parse all .yaml, .yml, .json, .csv and .tsv
# files under <dir> and add them to the <data> variable.
#
@@ -45,14 +43,13 @@ module Jekyll
next if @entry_filter.symlink?(path)
if File.directory?(path)
read_data_to(path, data[sanitize_filename(entry)] = DataHash.new)
read_data_to(path, data[sanitize_filename(entry)] = {})
else
key = sanitize_filename(File.basename(entry, ".*"))
data[key] = DataEntry.new(site, path, read_data_file(path))
data[key] = read_data_file(path)
end
end
end
# rubocop:enable Metrics/AbcSize
# Determines how to read a data file.
#

View File

@@ -47,14 +47,7 @@ module Jekyll
end
def mergable?(value)
case value
when Hash, Drops::Drop, DataHash
true
when DataEntry
mergable?(value.data)
else
false
end
value.is_a?(Hash) || value.is_a?(Drops::Drop)
end
def duplicable?(obj)