Sha256: d1f8b8c53ecd94b07e09c0dc2e350fd3bba9e10796597a4105b99244a8d2a84b

Contents?: true

Size: 1.25 KB

Versions: 28

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Jekyll
  class ThemeAssetsReader
    attr_reader :site
    def initialize(site)
      @site = site
    end

    def read
      return unless site.theme && site.theme.assets_path

      Find.find(site.theme.assets_path) do |path|
        next if File.directory?(path)
        if File.symlink?(path)
          Jekyll.logger.warn "Theme reader:", "Ignored symlinked asset: #{path}"
        else
          read_theme_asset(path)
        end
      end
    end

    private
    def read_theme_asset(path)
      base = site.theme.root
      dir = File.dirname(path.sub("#{site.theme.root}/", ""))
      name = File.basename(path)

      if Utils.has_yaml_header?(path)
        append_unless_exists site.pages,
          Jekyll::Page.new(site, base, dir, name)
      else
        append_unless_exists site.static_files,
          Jekyll::StaticFile.new(site, base, "/#{dir}", name)
      end
    end

    def append_unless_exists(haystack, new_item)
      if haystack.any? { |file| file.relative_path == new_item.relative_path }
        Jekyll.logger.debug "Theme:",
          "Ignoring #{new_item.relative_path} in theme due to existing file " \
          "with that path in site."
        return
      end

      haystack << new_item
    end
  end
end

Version data entries

28 entries across 28 versions & 2 rubygems

Version Path
jekyll-3.10.0 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.5 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.4 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.3 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.2 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.1 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.9.0 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.7 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.6 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.5 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.6.3 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.4 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.7.4 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.3 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.2 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.1 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.0 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.0.pre.rc2 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.8.0.pre.rc1 lib/jekyll/readers/theme_assets_reader.rb
jekyll-3.7.3 lib/jekyll/readers/theme_assets_reader.rb