Sha256: 6fb18f822ad18fbcce1cda2a59bbd92067ebc8f689a32d8e9e6ce6147253d826

Contents?: true

Size: 1.36 KB

Versions: 34

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Bridgetown
  class PluginContentReader
    attr_reader :site, :content_dir

    def initialize(site, plugin_content_dir)
      @site = site
      @content_dir = plugin_content_dir
      @content_files = Set.new
    end

    def read
      return unless content_dir

      Find.find(content_dir) do |path|
        next if File.directory?(path)

        if File.symlink?(path)
          Bridgetown.logger.warn "Plugin content reader:", "Ignored symlinked asset: #{path}"
        else
          read_content_file(path)
        end
      end
    end

    def read_content_file(path)
      dir = File.dirname(path.sub("#{content_dir}/", ""))
      name = File.basename(path)

      @content_files << if Utils.has_yaml_header?(path)
                          Bridgetown::Page.new(site, content_dir, dir, name, from_plugin: true)
                        else
                          Bridgetown::StaticFile.new(site, content_dir, "/#{dir}", name)
                        end

      add_to(site.pages, Bridgetown::Page)
      add_to(site.static_files, Bridgetown::StaticFile)
    end

    def add_to(content_type, klass)
      existing_paths = content_type.map(&:relative_path).compact
      @content_files.select { |item| item.is_a?(klass) }.each do |item|
        content_type << item unless existing_paths.include?(item.relative_path)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
bridgetown-core-0.21.5 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.4 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.3 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.2 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.1 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.0 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.0.beta4 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.0.beta3 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.0.beta2 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.21.0.beta1 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.20.0 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.19.3 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.19.2 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.19.1 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.19.0 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.18.6 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.18.5 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.18.4 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.18.3 lib/bridgetown-core/readers/plugin_content_reader.rb
bridgetown-core-0.18.2 lib/bridgetown-core/readers/plugin_content_reader.rb