Only display results from one subdirectory path

Hi folks,

I’m using the jekyll plugin https://community.algolia.com/jekyll-algolia/ to push my content up to Algolia.

I have a website with a number of sub directories (/pricing, /docs, /blog…); all the content is pushed up just fine.

What I’m unable to do is limit the search to documents under /docs. Everything else shouldn’t be searchable.

What I’ve tried:

I’ve also looked around the algolia docs and googled but haven’t found anything.

One possible workaround is to use the excluded_files filter for the jekyll plugin and just exclude all the directories except /docs. I’d rather do an include because that is more maintainable long term.

Any other suggestions?

Thanks!

Relevant code is here:

What you’d want to do is indeed add a new configuration variable which is included_paths (you’ll need to make sure you handle include & exclude combined correctly) and handle the logic correctly there (probably exclude first and then check if in included_paths at the end)

Thank you! I’ll fork it and give that a try.

In case anyone stumbles on this in the future, it’s actually far easier to write a custom hook using the instructions here: https://community.algolia.com/jekyll-algolia/hooks.html#should-be-excluded

Here’s what my hook looks like:

module Jekyll
  module Algolia
    module Hooks
      def self.should_be_excluded?(filepath)
        return false if filepath =~ %r{^docs}
        true
      end
    end
  end
end

2 Likes

Thanks for sharing @dan4!

1 Like