Skip to content

Commit

Permalink
Correct feedback, clarify order of precedence
Browse files Browse the repository at this point in the history
  • Loading branch information
MattSturgeon committed Jul 19, 2017
1 parent 737461c commit 6107d9f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/jekyll/commands/serve/servlet.rb
Expand Up @@ -19,30 +19,30 @@ def initialize(server, root, callbacks)
# Add the ability to tap file.html the same way that Nginx does on our
# Docker images (or on GitHub Pages.) The difference is that we might end
# up with a different preference on which comes first.
#
# Order of precedence:
# /file -> /file/index.html -> /file.html -> fancy-indexing -> 404.html

def search_file(req, res, basename)
# /file.* -> /file.html
# First see if we can find /file normally, if not try /file.html
super || super(req, res, "#{basename}.html")
end

def search_index_file(req, res)
# /file/index.html -> /file.html

# First, let's see if the our super method can figure it out.
# (i.e Check for index.html files in the res.filename directory)
# First, let's see if our super method can find an index file.
file = super

unless file
# Ok, I guess that didn't work, I guess there's no basename/index.html
# Let's look for basename.html instead...
# Ok, looks like there's no index file in the directory.
# Let's look for directory.html instead...

# Split the basename from the path (res.filename)
i = res.filename.rindex "\/"
basename = res.filename[i..-1]
res.filename = res.filename[0, i]

# Try and find a file named dirname.html in the parent directory.
file = search_file(req, res, basename + ".html")
file = search_file(req, res, "#{basename}.html")

# If we didn't find a file, revert our changes to res.filename.
res.filename << basename unless file
Expand Down

0 comments on commit 6107d9f

Please sign in to comment.