Sha256: 47145eac8c76dc391b99f5a3aae73b28c210b7c6dafa5b4d8c2893149e4af1de

Contents?: true

Size: 848 Bytes

Versions: 9

Compression:

Stored size: 848 Bytes

Contents

# frozen_string_literal: true

require "roda/plugins/public"

Roda::RodaPlugins::Public::RequestMethods.module_eval do
  SPLIT = Regexp.union(*[File::SEPARATOR, File::ALT_SEPARATOR].compact) # rubocop:disable Lint/ConstantDefinitionInBlock
  def public_path_segments(path) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
    segments = []

    path.split(SPLIT).each do |seg|
      next if seg.empty? || seg == "."

      seg == ".." ? segments.pop : segments << seg
    end

    path = ::File.join(roda_class.opts[:public_root], *segments)
    unless ::File.file?(path)
      path = ::File.join(path, "index.html")
      if ::File.file?(path)
        segments << "index.html"
      else
        segments[segments.size - 1] = "#{segments.last}.html"
      end
    end

    segments
  rescue IndexError
    nil
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bridgetown-core-1.0.0.alpha10 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha9 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha8 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha7 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha6 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha5 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha4 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha3 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.0.0.alpha2 lib/bridgetown-core/rack/static_indexes.rb