Module: Bridgetown::Site::Content
- Included in:
- Bridgetown::Site
- Defined in:
- lib/bridgetown-core/concerns/site/content.rb
Overview
Content is king!
Instance Method Summary collapse
- #add_generated_page(generated_page) ⇒ Object
- #categories ⇒ Object
-
#collection_names ⇒ Array<String>
An array of collection names.
-
#collections ⇒ HashWithDotAccess::Hash{String, Symbol => Collection}, HashWithDotAccess::Hash
The list of collections labels and their corresponding Collection instances.
-
#frontend_manifest ⇒ Hash
Loads and memoizes the parsed frontend bundler manifest file (if available).
-
#metadata ⇒ HashWithDotAccess::Hash
Returns the contents of the site metadata file or a blank hash.
-
#resources ⇒ Array<Bridgetown::Resource::Base>
(also: #contents)
Get all loaded resources.
- #resources_grouped_by_taxonomy(taxonomy) ⇒ Object
- #resources_to_write ⇒ Object
-
#site_payload ⇒ Hash
(also: #to_liquid)
The Hash payload containing site-wide data.
-
#static_files_to_write ⇒ Array<StaticFile>
Get the static files to be written.
- #tags ⇒ Object
- #taxonomies ⇒ Object
- #taxonomy_types ⇒ Array<Bridgetown::Resource::TaxonomyType>
Instance Method Details
#add_generated_page(generated_page) ⇒ Object
110 111 112 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 110 def add_generated_page(generated_page) generated_pages << generated_page end |
#categories ⇒ Object
25 26 27 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 25 def categories taxonomies.category end |
#collection_names ⇒ Array<String>
An array of collection names.
65 66 67 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 65 def collection_names Array(config.collections&.keys) end |
#collections ⇒ HashWithDotAccess::Hash{String, Symbol => Collection}, HashWithDotAccess::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.
54 55 56 57 58 59 60 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 54 def collections @collections ||= collection_names.each_with_object( HashWithDotAccess::Hash.new ) do |name, hsh| hsh[name] = Bridgetown::Collection.new(self, name) end end |
#frontend_manifest ⇒ Hash
Loads and memoizes the parsed frontend bundler manifest file (if available)
116 117 118 119 120 121 122 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 116 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 |
#metadata ⇒ HashWithDotAccess::Hash
Returns the contents of the site metadata file or a blank hash
31 32 33 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 31 def signals["site_metadata"] ||= HashWithDotAccess::Hash.new end |
#resources ⇒ Array<Bridgetown::Resource::Base> Also known as: contents
Get all loaded resources.
88 89 90 91 92 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 88 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
8 9 10 11 12 13 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 8 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_write ⇒ Object
96 97 98 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 96 def resources_to_write resources.select(&:write?) end |
#site_payload ⇒ Hash Also known as: to_liquid
The Hash payload containing site-wide data.
38 39 40 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 38 def site_payload Bridgetown::Drops::UnifiedPayloadDrop.new self end |
#static_files_to_write ⇒ Array<StaticFile>
Get the static files to be written
106 107 108 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 106 def static_files_to_write static_files.select(&:write?) end |
#tags ⇒ Object
21 22 23 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 21 def taxonomies.tag end |
#taxonomies ⇒ Object
15 16 17 18 19 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 15 def taxonomies taxonomy_types.transform_values do |taxonomy| resources_grouped_by_taxonomy(taxonomy) end end |
#taxonomy_types ⇒ Array<Bridgetown::Resource::TaxonomyType>
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bridgetown-core/concerns/site/content.rb', line 70 def taxonomy_types @taxonomy_types ||= config.taxonomies.to_dot_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 end |