Optimize Page#dir with a private method (#8489)

Merge pull request 8489
This commit is contained in:
Ashwin Maroli 2020-12-02 22:57:33 +05:30 committed by GitHub
parent 686165af12
commit c80ccbebf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 6 deletions

View File

@ -64,12 +64,7 @@ module Jekyll
#
# Returns the String destination directory.
def dir
if url.end_with?("/")
url
else
url_dir = File.dirname(url)
url_dir.end_with?("/") ? url_dir : "#{url_dir}/"
end
url.end_with?("/") ? url : url_dir
end
# The full path and filename of the post. Defined in the YAML of the post
@ -211,5 +206,12 @@ module Jekyll
data["excerpt"] ||= Jekyll::PageExcerpt.new(self)
end
def url_dir
@url_dir ||= begin
value = File.dirname(url)
value.end_with?("/") ? value : "#{value}/"
end
end
end
end