Module: Bridgetown::Site::Content

Included in:
Bridgetown::Site
Defined in:
bridgetown-core/lib/bridgetown-core/concerns/site/content.rb

Overview

Content is king!

Instance Method Summary collapse

Instance Method Details

#add_generated_page(generated_page) ⇒ Object



108
109
110
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 108

def add_generated_page(generated_page)
  generated_pages << generated_page
end

#categoriesObject



23
24
25
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 23

def categories
  taxonomies.category
end

#collection_namesArray<String>

An array of collection names.

Returns:

  • (Array<String>)

    an array of collection names from the configuration, or an empty array if the config["collections"] key is not set.



63
64
65
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 63

def collection_names
  Array(config.collections&.keys)
end

#collectionsHash{String, Symbol => Collection}, Hash

The list of collections labels and their corresponding Collection instances.

If config['collections'] is set, a new instance of Collection is created for each entry in the collections configuration.

If config["collections"] is not specified, a blank hash is returned.

Returns:

  • (Hash{String, Symbol => Collection})

    A Hash containing a collection name-to-instance pairs.

  • (Hash)

    Returns a blank hash if no items found



52
53
54
55
56
57
58
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 52

def collections
  @collections ||= collection_names.each_with_object(
    HashWithDotAccess::Hash.new
  ) do |name, hsh|
    hsh[name] = Bridgetown::Collection.new(self, name)
  end
end

#frontend_manifestHash

Loads and memoizes the parsed frontend bundler manifest file (if available)

Returns:

  • (Hash)


114
115
116
117
118
119
120
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 114

def frontend_manifest
  @frontend_manifest ||= begin
    manifest_file = File.join(frontend_bundling_path, "manifest.json")

    JSON.parse(File.read(manifest_file)) if File.exist?(manifest_file)
  end
end

#metadataHashWithDotAccess::Hash

Returns the contents of the site metadata file or a blank hash

Returns:



29
30
31
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 29

def 
  signals["site_metadata"] ||= HashWithDotAccess::Hash.new
end

#resourcesArray<Bridgetown::Resource::Base> Also known as: contents

Get all loaded resources.

Returns:



86
87
88
89
90
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 86

def resources
  collections.each_with_object(Set.new) do |(_, collection), set|
    set.merge(collection.resources)
  end.to_a
end

#resources_grouped_by_taxonomy(taxonomy) ⇒ Object



6
7
8
9
10
11
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 6

def resources_grouped_by_taxonomy(taxonomy)
  data.site_taxonomies_hash ||= {}
  data.site_taxonomies_hash[taxonomy.label] ||= taxonomy.terms.transform_values do |terms|
    terms.map(&:resource).sort.reverse
  end
end

#resources_to_writeObject



94
95
96
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 94

def resources_to_write
  resources.select(&:write?)
end

#site_payloadHash Also known as: to_liquid

The Hash payload containing site-wide data.

Returns:

  • (Hash)

    Returns a hash in the structure of { “site” => data }



36
37
38
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 36

def site_payload
  Bridgetown::Drops::UnifiedPayloadDrop.new self
end

#static_files_to_writeArray<StaticFile>

Get the static files to be written

Returns:

  • (Array<StaticFile>)

    an array of files which should be written and that respond_to :write?

See Also:



104
105
106
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 104

def static_files_to_write
  static_files.select(&:write?)
end

#tagsObject



19
20
21
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 19

def tags
  taxonomies.tag
end

#taxonomiesObject



13
14
15
16
17
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 13

def taxonomies
  taxonomy_types.transform_values do |taxonomy|
    resources_grouped_by_taxonomy(taxonomy)
  end
end

#taxonomy_typesArray<Bridgetown::Resource::TaxonomyType>



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'bridgetown-core/lib/bridgetown-core/concerns/site/content.rb', line 68

def taxonomy_types
  @taxonomy_types ||= config.taxonomies.to_h do |label, |
    key = 
     = if .is_a? Hash
                     key = ["key"]
                     .reject { |k| k == "key" }
                   else
                     HashWithDotAccess::Hash.new
                   end

    [label, Bridgetown::Resource::TaxonomyType.new(
      site: self, label:, key:, metadata: 
    ),]
  end.with_dot_access
end