Module: Roda::RodaPlugins::SSG::RequestMethods
- Defined in:
- bridgetown-core/lib/roda/plugins/ssg.rb
Instance Method Summary collapse
-
#segments_for_path(path) ⇒ Object
TODO: this could be refactored a bit for clarity.
-
#ssg ⇒ Object
Instance Method Details
#segments_for_path(path) ⇒ Object
TODO: this could be refactored a bit for clarity
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'bridgetown-core/lib/roda/plugins/ssg.rb', line 45 def segments_for_path(path) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity segments = [] path.split("/").each do |seg| next if seg.empty? || seg == "." seg == ".." ? segments.pop : segments << seg end path = File.join(roda_class.opts[:ssg_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 |
#ssg ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'bridgetown-core/lib/roda/plugins/ssg.rb', line 26 def ssg return unless is_get? path = PARSER.unescape(real_remaining_path) return if path.include?("\0") # @type [Rack::Files] server = roda_class.opts[:ssg_server] path = File.join(server.root, *segments_for_path(path)) return unless File.file?(path) status, headers, body = server.serving(self, path) response_headers = response.headers response_headers.replace(headers) halt [status, response_headers, body] end |