lib/frontman/resource.rb in frontman-ssg-0.0.4 vs lib/frontman/resource.rb in frontman-ssg-0.1.0

- old
+ new

@@ -1,6 +1,6 @@ -# typed: true +# typed: false # frozen_string_literal: true require 'frontman/renderers/renderer_resolver' require 'frontman/custom_struct' require 'frontman/context' @@ -63,22 +63,20 @@ def setup_destination destination_without_extension, dest_file_extensions = strip_extensions( @destination_path ) - if destination_without_extension == 'index' - destination_without_extension = '' - end + destination_without_extension = '' if destination_without_extension == 'index' is_index_page = destination_without_extension.end_with?('/index') @extension = dest_file_extensions.first - if (@extension == 'html' || extension.nil?) && !is_index_page - @destination_path = destination_without_extension + '/index.html' - else - @destination_path = destination_without_extension + '.' + @extension - end + @destination_path = if (@extension == 'html' || extension.nil?) && !is_index_page + destination_without_extension + '/index.html' + else + destination_without_extension + '.' + @extension + end @path = "/#{@destination_path.chomp('index.html')}" .gsub('//', '/') end sig { void } @@ -104,11 +102,11 @@ @rendered_content = nil @content = File.read(@file_path) @data = {}.to_ostruct - if %w[erb html haml md txt].include?(@extension) + if Frontman::RendererResolver.instance.valid_extension?(@extension) @data, @content = YAML::FrontMatter.extract(@content).to_ostruct end @data = @data.to_h.merge(data.to_h).to_ostruct unless data.nil? @@ -166,12 +164,10 @@ Frontman::App.instance.current_tree = sitemap_tree end # If we have no layout to render and already cache the rendered content # we can return it directly - if layout_from_extra_data.nil? && !@rendered_content.nil? - return @rendered_content - end + return @rendered_content if layout_from_extra_data.nil? && !@rendered_content.nil? content = @content # We create a new context for each file getting rendered context = Frontman::Context.new