Sha256: cbb8a335d2d080de7c23914865a94f4609bd35d3a6de11dcbc9e915802398166

Contents?: true

Size: 888 Bytes

Versions: 10

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

require "roda/plugins/public"

# TODO: extract out to a standalone Roda plugin
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

10 entries across 10 versions & 1 rubygems

Version Path
bridgetown-core-1.3.4 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.3 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.2 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.1 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.0 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.0.beta3 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.0.beta2 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.3.0.beta1 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.2.0 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.2.0.beta5 lib/bridgetown-core/rack/static_indexes.rb