Sphinx プロジェクトで、プロジェクトの _static ディレクトリ内のドキュメントがプロジェクトの検索結果に表示されないようにするにはどうすればよいですか?
1 に答える
3
特定のディレクトリ内のファイルを検索インデックスから除外するための構成オプションはありません。
ただし、IndexBuilder.feed()
メソッドを変更することでそれを行うことができます。このメソッドへの引数の 1 つはdoctree
(Docutilsdocument
クラスのインスタンス) です。処理中の .rst ドキュメントへのパスは の値ですdoctree.attributes['source']
。
次のモンキー パッチをconf.pyに追加します。
from sphinx.search import IndexBuilder, WordCollector
def feed(self, filename, title, doctree):
"""Feed a doctree to the index."""
# Patch: if '_static' is in the path, don't use the file to
# populate the search index
source = doctree.attributes["source"]
if "_static" in source:
return
self._titles[filename] = title
visitor = WordCollector(doctree, self.lang)
doctree.walk(visitor)
def add_term(word, stem=self.lang.stem):
word = stem(word)
if self.lang.word_filter(word):
self._mapping.setdefault(word, set()).add(filename)
for word in self.lang.split(title):
add_term(word)
for word in visitor.found_words:
add_term(word)
IndexBuilder.feed = feed
Sphinx 1.1.3 でテスト済み。
于 2012-10-02T15:07:44.390 に答える