mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Clean up the mechanism for disabling Javascript search.
This commit is contained in:
parent
0d01ca1dcf
commit
e490c2e12d
@ -78,7 +78,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
searchindex_filename = 'searchindex.js'
|
searchindex_filename = 'searchindex.js'
|
||||||
add_permalinks = True
|
add_permalinks = True
|
||||||
embedded = False # for things like HTML help or Qt help: suppresses sidebar
|
embedded = False # for things like HTML help or Qt help: suppresses sidebar
|
||||||
|
search = True # for things like HTML help and Apple help: suppress search
|
||||||
|
|
||||||
# This is a class attribute because it is mutated by Sphinx.add_javascript.
|
# This is a class attribute because it is mutated by Sphinx.add_javascript.
|
||||||
script_files = ['_static/jquery.js', '_static/underscore.js',
|
script_files = ['_static/jquery.js', '_static/underscore.js',
|
||||||
'_static/doctools.js']
|
'_static/doctools.js']
|
||||||
@ -247,14 +248,16 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
|
|
||||||
def prepare_writing(self, docnames):
|
def prepare_writing(self, docnames):
|
||||||
# create the search indexer
|
# create the search indexer
|
||||||
from sphinx.search import IndexBuilder, languages
|
self.indexer = None
|
||||||
lang = self.config.html_search_language or self.config.language
|
if self.search:
|
||||||
if not lang or lang not in languages:
|
from sphinx.search import IndexBuilder, languages
|
||||||
lang = 'en'
|
lang = self.config.html_search_language or self.config.language
|
||||||
self.indexer = IndexBuilder(self.env, lang,
|
if not lang or lang not in languages:
|
||||||
self.config.html_search_options,
|
lang = 'en'
|
||||||
self.config.html_search_scorer)
|
self.indexer = IndexBuilder(self.env, lang,
|
||||||
self.load_indexer(docnames)
|
self.config.html_search_options,
|
||||||
|
self.config.html_search_scorer)
|
||||||
|
self.load_indexer(docnames)
|
||||||
|
|
||||||
self.docwriter = HTMLWriter(self)
|
self.docwriter = HTMLWriter(self)
|
||||||
self.docsettings = OptionParser(
|
self.docsettings = OptionParser(
|
||||||
@ -484,12 +487,12 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self.handle_page(pagename, {}, template)
|
self.handle_page(pagename, {}, template)
|
||||||
|
|
||||||
# the search page
|
# the search page
|
||||||
if self.name != 'htmlhelp':
|
if self.search:
|
||||||
self.info(' search', nonl=1)
|
self.info(' search', nonl=1)
|
||||||
self.handle_page('search', {}, 'search.html')
|
self.handle_page('search', {}, 'search.html')
|
||||||
|
|
||||||
# the opensearch xml file
|
# the opensearch xml file
|
||||||
if self.config.html_use_opensearch and self.name != 'htmlhelp':
|
if self.config.html_use_opensearch and self.search:
|
||||||
self.info(' opensearch', nonl=1)
|
self.info(' opensearch', nonl=1)
|
||||||
fn = path.join(self.outdir, '_static', 'opensearch.xml')
|
fn = path.join(self.outdir, '_static', 'opensearch.xml')
|
||||||
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
|
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
|
||||||
@ -579,9 +582,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
copyfile(jsfile, path.join(self.outdir, '_static',
|
copyfile(jsfile, path.join(self.outdir, '_static',
|
||||||
'translations.js'))
|
'translations.js'))
|
||||||
|
|
||||||
# add context items for search function used in searchtools.js_t
|
|
||||||
ctx = self.globalcontext.copy()
|
ctx = self.globalcontext.copy()
|
||||||
ctx.update(self.indexer.context_for_searchtool())
|
|
||||||
|
# add context items for search function used in searchtools.js_t
|
||||||
|
if self.indexer is not None:
|
||||||
|
ctx.update(self.indexer.context_for_searchtool())
|
||||||
|
|
||||||
# then, copy over theme-supplied static files
|
# then, copy over theme-supplied static files
|
||||||
if self.theme:
|
if self.theme:
|
||||||
@ -801,7 +806,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
copyfile(self.env.doc2path(pagename), source_name)
|
copyfile(self.env.doc2path(pagename), source_name)
|
||||||
|
|
||||||
def handle_finish(self):
|
def handle_finish(self):
|
||||||
self.finish_tasks.add_task(self.dump_search_index)
|
if self.indexer:
|
||||||
|
self.finish_tasks.add_task(self.dump_search_index)
|
||||||
self.finish_tasks.add_task(self.dump_inventory)
|
self.finish_tasks.add_task(self.dump_inventory)
|
||||||
|
|
||||||
def dump_inventory(self):
|
def dump_inventory(self):
|
||||||
|
@ -173,6 +173,9 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
|||||||
# don't add sidebar etc.
|
# don't add sidebar etc.
|
||||||
embedded = True
|
embedded = True
|
||||||
|
|
||||||
|
# don't generate search index or include search page
|
||||||
|
search = False
|
||||||
|
|
||||||
lcid = 0x409
|
lcid = 0x409
|
||||||
encoding = 'cp1252'
|
encoding = 'cp1252'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user