Class: Bridgetown::PluginContentReader

Inherits:
Object
  • Object
show all
Defined in:
lib/bridgetown-core/readers/plugin_content_reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, manifest) ⇒ PluginContentReader

Returns a new instance of PluginContentReader.

Parameters:



9
10
11
12
13
14
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 9

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

Instance Attribute Details

#content_dirObject (readonly)

Returns the value of attribute content_dir.



5
6
7
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5

def content_dir
  @content_dir
end

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5

def manifest
  @manifest
end

#siteObject (readonly)

Returns the value of attribute site.



5
6
7
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 5

def site
  @site
end

Instance Method Details

#add_to(content_type, klass) ⇒ Object



42
43
44
45
46
47
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 42

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

#readObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 16

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

#read_content_file(path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/bridgetown-core/readers/plugin_content_reader.rb', line 30

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

  @content_files << if FrontMatter::Loaders.front_matter?(path)
                      site.collections.pages.read_resource(path, manifest:)
                    else
                      Bridgetown::StaticFile.new(site, content_dir, "/#{dir}", name)
                    end
  add_to(site.static_files, Bridgetown::StaticFile)
end