Skip to content

Commit

Permalink
Avoid duplication in r.bridgetown implementation (#939)
Browse files Browse the repository at this point in the history
By choosing an appropriate argument to `on`, based on the
base path, we don't need a separate if statement block and
manual return.

Additionally, the nil at the end is not needed, as `on` will either throw if it handles the request, or return nil if it does not.
  • Loading branch information
jeremyevans authored Nov 18, 2024
1 parent 0ee33c7 commit f081177
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions bridgetown-core/lib/roda/plugins/bridgetown_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,11 @@ def bridgetown
scope.initialize_bridgetown_context
scope.initialize_bridgetown_root

# There are two different code paths depending on if there's a site `base_path` configured
if Bridgetown::Current.preloaded_configuration.base_path == "/"
base_path = Bridgetown::Current.preloaded_configuration.base_path.delete_prefix("/")
on(base_path.empty? ? true : base_path) do
ssg # static file server
Bridgetown::Rack::Routes.load_all scope
return
end

# Support custom base_path configurations
on(Bridgetown::Current.preloaded_configuration.base_path.delete_prefix("/")) do
ssg # static file server
Bridgetown::Rack::Routes.load_all scope
end

nil
end
end
end
Expand Down

0 comments on commit f081177

Please sign in to comment.