Search code examples
serverjekyllwebrick

How underscored directories are filtered in Jekyll/Webrick?


Update: Check my answer below.


I just realized that in Jekyll Webrick server, directories starting with underscores(_includes, _layouts etc.) can't be accessed and are not listed when jekyll serve --show-dir-listing option is turned on. I wonder how Jekyll does that, as Webricks shows underscored directories on default. I did a quick search in the source code, I checked lib/jekyll/commands/serve.rb and similar files, but could not find the exact reason. It might be something related to fancy_listing?

Example: enter image description here It is there!:

enter image description here


Solution

  • Update: I found the relevant code in jekyll/reader.rb, which has a filter function and it is defined in jekyll/entry_filter.rb! :) Here is the code:

    • First a regex is defined:
     SPECIAL_LEADING_CHAR_REGEX = %r!\A#{Regexp.union([".", "_", "#", "~"])}!o.freeze
    
    • Then special?function is defined:
    def special?(entry)
      SPECIAL_LEADING_CHAR_REGEX.match?(entry) ||
          SPECIAL_LEADING_CHAR_REGEX.match?(File.basename(entry))
    end
    
    • And special?function is used in the filter function to detect and filter those files matching the regex.

    • And the Readerclass is using this filtering function in various places.

      To be honest, I still did not get how jekyll bring those things together but I think I'll try to figure them out myself.