lib/cloudcannon-jekyll/generators/collections.rb in cloudcannon-jekyll-3.0.2 vs lib/cloudcannon-jekyll/generators/collections.rb in cloudcannon-jekyll-3.1.0

- old
+ new

@@ -22,11 +22,12 @@ @split_drafts = group_by_category_folder(all_drafts, 'drafts') end def generate_collections_config collections = @site.config['collections'] || {} - collections_config = @config['collections_config']&.dup || {} + input_collections_config = @config['collections_config'] || {} + collections_config = input_collections_config.reject { |_, v| v == false } return collections_config if @config['collections_config_override'] if collections.is_a?(Array) collections = collections.each_with_object({}) { |key, memo| memo[key] = {} } @@ -54,10 +55,12 @@ end collection_keys = (defaults.keys + collections.keys).uniq collection_keys.each do |key| + next if input_collections_config[key] == false + processed = (defaults[key] || {}) .merge(collections[key] || {}) .merge(collections_config[key] || {}) processed['output'] ||= false @@ -69,10 +72,12 @@ collections_config[key] = processed end @split_posts.each_key do |key| + next if input_collections_config[key] == false + posts_path = @split_posts[key]&.first&.relative_path&.sub(%r{(^|/)_posts.*}, '\1_posts') next unless posts_path defaults = { 'auto_discovered' => !collections_config.key?(key), @@ -82,10 +87,12 @@ collections_config[key] = defaults.merge(collections_config[key] || {}) end @split_drafts.each_key do |key| + next if input_collections_config[key] == false + drafts_path = @split_drafts[key]&.first&.relative_path&.sub(%r{(^|/)_drafts.*}, '\1_drafts') next unless drafts_path defaults = { 'auto_discovered' => !collections_config.key?(key), @@ -111,10 +118,14 @@ collections = {} collections_config.each_key do |key| next if key == 'data' + collections[key] ||= [] + + next if collections_config.dig(key, 'parser') == false + collections[key] = if key == 'posts' || key.end_with?('/posts') @split_posts[key] elsif key == 'drafts' || key.end_with?('/drafts') @split_drafts[key] else @@ -165,17 +176,15 @@ :pages end end def legacy_document_data(doc) - data = doc.data.merge( - { - categories: doc.categories, - tags: doc.tags, - date: doc.date - } - ) + legacy_data = {} + legacy_data['categories'] = doc.categories if doc.respond_to?(:categories) + legacy_data['tags'] = doc.tags if doc.respond_to?(:tags) + legacy_data['date'] = doc.date if doc.respond_to?(:date) + data = doc.data.merge(legacy_data) data['slug'] = doc.slug if doc.respond_to?(:slug) data end def legacy_doc?(doc)