From 0634b3691399ebccdd19f9792080679992f2c2dc Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Thu, 30 Jan 2020 16:51:51 +0530 Subject: [PATCH] Quicker categories for documents without superdirs When a document's special directory (e.g. `_posts` for a post) is located at the root of the site's `collections_dir`, its `categories_from_path` is always empty. --- lib/jekyll/document.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/jekyll/document.rb b/lib/jekyll/document.rb index 847b2b9b0bc..fab0d79f497 100644 --- a/lib/jekyll/document.rb +++ b/lib/jekyll/document.rb @@ -414,9 +414,13 @@ def respond_to_missing?(method, *) # # Returns nothing. def categories_from_path(special_dir) - superdirs = relative_path.sub(Document.superdirs_regex(special_dir), "") - superdirs = superdirs.split(File::SEPARATOR) - superdirs.reject! { |c| c.empty? || c == special_dir || c == basename } + if relative_path.start_with?(special_dir) + superdirs = [] + else + superdirs = relative_path.sub(Document.superdirs_regex(special_dir), "") + superdirs = superdirs.split(File::SEPARATOR) + superdirs.reject! { |c| c.empty? || c == special_dir || c == basename } + end merge_data!({ "categories" => superdirs }, :source => "file path") end