search_auto_exclude.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. #
  2. # This is a Sphinx documentation tool extension which allows to
  3. # automatically exclude from full-text search index document
  4. # which are not referenced via toctree::. It's intended to be
  5. # used with toctrees conditional on only:: directive, with the
  6. # idea being that if you didn't include it in the ToC, you don't
  7. # want the docs being findable by search either (for example,
  8. # because these docs contain information not pertinent to a
  9. # particular product configuration).
  10. #
  11. # This extension depends on "eager_only" extension and won't work
  12. # without it.
  13. #
  14. # Copyright (c) 2016 Paul Sokolovsky
  15. # Licensed under the terms of BSD license, see LICENSE file.
  16. #
  17. import sphinx
  18. org_StandaloneHTMLBuilder_index_page = None
  19. def StandaloneHTMLBuilder_index_page(self, pagename, doctree, title):
  20. if pagename not in self.env.files_to_rebuild:
  21. if pagename != self.env.config.master_doc and 'orphan' not in self.env.metadata[pagename]:
  22. print("Excluding %s from full-text index because it's not referenced in ToC" % pagename)
  23. return
  24. return org_StandaloneHTMLBuilder_index_page(self, pagename, doctree, title)
  25. def setup(app):
  26. global org_StandaloneHTMLBuilder_index_page
  27. org_StandaloneHTMLBuilder_index_page = sphinx.builders.html.StandaloneHTMLBuilder.index_page
  28. sphinx.builders.html.StandaloneHTMLBuilder.index_page = StandaloneHTMLBuilder_index_page