Sha256: 10776f4553f542b34d7ef47a9349dd1fcff634074b5d63c054108a9999de6818

Contents?: true

Size: 896 Bytes

Versions: 4

Compression:

Stored size: 896 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

4 entries across 4 versions & 1 rubygems

Version Path
bridgetown-core-1.2.0.beta4 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.2.0.beta3 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.2.0.beta2 lib/bridgetown-core/rack/static_indexes.rb
bridgetown-core-1.2.0.beta1 lib/bridgetown-core/rack/static_indexes.rb