mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add OpenSearch capability.
This commit is contained in:
parent
03a6960911
commit
a7d088d75b
5
CHANGES
5
CHANGES
@ -64,8 +64,11 @@ New features added
|
|||||||
the default templates.
|
the default templates.
|
||||||
- Templates now have an XHTML doctype, to be consistent with docutils'
|
- Templates now have an XHTML doctype, to be consistent with docutils'
|
||||||
HTML output.
|
HTML output.
|
||||||
|
- You can now create an OpenSearch description file with the
|
||||||
|
``html_use_opensearch`` config value.
|
||||||
|
|
||||||
Thanks to Jacob Kaplan-Moss, Talin and Sebastian Wiesner for suggestions.
|
Thanks to Jacob Kaplan-Moss, Talin, Jeroen Ruigrok van der Werven and
|
||||||
|
Sebastian Wiesner for suggestions.
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
1
TODO
1
TODO
@ -9,7 +9,6 @@ Sphinx
|
|||||||
- option for compact module index
|
- option for compact module index
|
||||||
- HTML section numbers?
|
- HTML section numbers?
|
||||||
- split the general index?
|
- split the general index?
|
||||||
- add OpenSearch
|
|
||||||
- "seealso" links to external examples, see http://svn.python.org/projects/sandbox/trunk/seealso/ and http://effbot.org/zone/idea-seealso.htm
|
- "seealso" links to external examples, see http://svn.python.org/projects/sandbox/trunk/seealso/ and http://effbot.org/zone/idea-seealso.htm
|
||||||
- "often used" combo box in sidebar
|
- "often used" combo box in sidebar
|
||||||
- source file cross-references?
|
- source file cross-references?
|
||||||
|
@ -227,7 +227,13 @@ that use Sphinx' HTMLWriter class.
|
|||||||
.. confval:: html_copy_source
|
.. confval:: html_copy_source
|
||||||
|
|
||||||
If true, the reST sources are included in the HTML build as
|
If true, the reST sources are included in the HTML build as
|
||||||
:file:`_sources/{name}`.
|
:file:`_sources/{name}`. The default is ``True``.
|
||||||
|
|
||||||
|
.. confval:: html_use_opensearch
|
||||||
|
|
||||||
|
If true, an `OpenSearch <http://opensearch.org>` description file will be
|
||||||
|
output, and all pages will contain a ``<link>`` tag referring to it.
|
||||||
|
The default is ``False``.
|
||||||
|
|
||||||
.. confval:: html_translator_class
|
.. confval:: html_translator_class
|
||||||
|
|
||||||
|
@ -330,6 +330,7 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
copyright = self.config.copyright,
|
copyright = self.config.copyright,
|
||||||
style = self.config.html_style,
|
style = self.config.html_style,
|
||||||
use_modindex = self.config.html_use_modindex,
|
use_modindex = self.config.html_use_modindex,
|
||||||
|
use_opensearch = self.config.html_use_opensearch,
|
||||||
builder = self.name,
|
builder = self.name,
|
||||||
parents = [],
|
parents = [],
|
||||||
titles = {},
|
titles = {},
|
||||||
@ -468,6 +469,11 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
self.info(' '+pagename, nonl=1)
|
self.info(' '+pagename, nonl=1)
|
||||||
self.handle_page(pagename, {}, template)
|
self.handle_page(pagename, {}, template)
|
||||||
|
|
||||||
|
if self.config.html_use_opensearch:
|
||||||
|
self.info(' opensearch', nonl=1)
|
||||||
|
fn = path.join(self.outdir, '_static', 'opensearch.xml')
|
||||||
|
self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
|
||||||
|
|
||||||
self.info()
|
self.info()
|
||||||
|
|
||||||
# copy image files
|
# copy image files
|
||||||
@ -544,7 +550,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
def get_target_uri(self, docname, typ=None):
|
def get_target_uri(self, docname, typ=None):
|
||||||
return docname + '.html'
|
return docname + '.html'
|
||||||
|
|
||||||
def handle_page(self, pagename, addctx, templatename='page.html'):
|
def handle_page(self, pagename, addctx, templatename='page.html',
|
||||||
|
outfilename=None):
|
||||||
ctx = self.globalcontext.copy()
|
ctx = self.globalcontext.copy()
|
||||||
ctx['current_page_name'] = pagename
|
ctx['current_page_name'] = pagename
|
||||||
|
|
||||||
@ -561,7 +568,8 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
ctx.update(addctx)
|
ctx.update(addctx)
|
||||||
|
|
||||||
output = self.templates.render(templatename, ctx)
|
output = self.templates.render(templatename, ctx)
|
||||||
outfilename = path.join(self.outdir, os_path(pagename) + '.html')
|
if not outfilename:
|
||||||
|
outfilename = path.join(self.outdir, os_path(pagename) + '.html')
|
||||||
ensuredir(path.dirname(outfilename)) # normally different from self.outdir
|
ensuredir(path.dirname(outfilename)) # normally different from self.outdir
|
||||||
try:
|
try:
|
||||||
f = codecs.open(outfilename, 'w', 'utf-8')
|
f = codecs.open(outfilename, 'w', 'utf-8')
|
||||||
@ -606,12 +614,14 @@ class PickleHTMLBuilder(StandaloneHTMLBuilder):
|
|||||||
return docname[:-5] # up to sep
|
return docname[:-5] # up to sep
|
||||||
return docname + SEP
|
return docname + SEP
|
||||||
|
|
||||||
def handle_page(self, pagename, ctx, templatename='page.html'):
|
def handle_page(self, pagename, ctx, templatename='page.html',
|
||||||
|
outfilename=None):
|
||||||
ctx['current_page_name'] = pagename
|
ctx['current_page_name'] = pagename
|
||||||
sidebarfile = self.config.html_sidebars.get(pagename, '')
|
sidebarfile = self.config.html_sidebars.get(pagename, '')
|
||||||
if sidebarfile:
|
if sidebarfile:
|
||||||
ctx['customsidebar'] = path.join(self.srcdir, sidebarfile)
|
ctx['customsidebar'] = path.join(self.srcdir, sidebarfile)
|
||||||
outfilename = path.join(self.outdir, os_path(pagename) + '.fpickle')
|
if not outfilename:
|
||||||
|
outfilename = path.join(self.outdir, os_path(pagename) + '.fpickle')
|
||||||
ensuredir(path.dirname(outfilename))
|
ensuredir(path.dirname(outfilename))
|
||||||
f = open(outfilename, 'wb')
|
f = open(outfilename, 'wb')
|
||||||
try:
|
try:
|
||||||
|
@ -55,6 +55,7 @@ class Config(object):
|
|||||||
html_additional_pages = ({}, False),
|
html_additional_pages = ({}, False),
|
||||||
html_use_modindex = (True, False),
|
html_use_modindex = (True, False),
|
||||||
html_copy_source = (True, False),
|
html_copy_source = (True, False),
|
||||||
|
html_use_opensearch = (False, False),
|
||||||
|
|
||||||
# HTML help options
|
# HTML help options
|
||||||
htmlhelp_basename = ('pydoc', False),
|
htmlhelp_basename = ('pydoc', False),
|
||||||
|
@ -126,6 +126,10 @@ html_last_updated_fmt = '%%b %%d, %%Y'
|
|||||||
# If true, the reST sources are included in the HTML build as _sources/<name>.
|
# If true, the reST sources are included in the HTML build as _sources/<name>.
|
||||||
#html_copy_source = True
|
#html_copy_source = True
|
||||||
|
|
||||||
|
# If true, an OpenSearch description file will be output, and all pages will
|
||||||
|
# contain a <link> tag referring to it.
|
||||||
|
#html_use_opensearch = False
|
||||||
|
|
||||||
# Output file base name for HTML help builder.
|
# Output file base name for HTML help builder.
|
||||||
htmlhelp_basename = '%(project)sdoc'
|
htmlhelp_basename = '%(project)sdoc'
|
||||||
|
|
||||||
|
@ -62,6 +62,11 @@
|
|||||||
<script type="text/javascript" src="{{ pathto('_static/interface.js', 1) }}"></script>
|
<script type="text/javascript" src="{{ pathto('_static/interface.js', 1) }}"></script>
|
||||||
<script type="text/javascript" src="{{ pathto('_static/doctools.js', 1) }}"></script>
|
<script type="text/javascript" src="{{ pathto('_static/doctools.js', 1) }}"></script>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
{%- if use_opensearch %}
|
||||||
|
<link rel="search" type="application/opensearchdescription+xml"
|
||||||
|
title="Search within {{ docstitle }}"
|
||||||
|
href="{{ pathto('_static/opensearch.xml', 1) }}"/>
|
||||||
|
{%- endif %}
|
||||||
{%- block rellinks %}
|
{%- block rellinks %}
|
||||||
{%- if hasdoc('about') %}
|
{%- if hasdoc('about') %}
|
||||||
<link rel="author" title="About these documents" href="{{ pathto('about') }}" />
|
<link rel="author" title="About these documents" href="{{ pathto('about') }}" />
|
||||||
|
13
sphinx/templates/opensearch.xml
Normal file
13
sphinx/templates/opensearch.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
|
||||||
|
<ShortName>{{ project }}</ShortName>
|
||||||
|
<LongName>{{ docstitle }}</LongName>
|
||||||
|
<Description>Search {{ docstitle }}</Description>
|
||||||
|
<InputEncoding>utf-8</InputEncoding>
|
||||||
|
<Url type="text/html" method="get" template="{{ pathto('search') }}?">
|
||||||
|
<Param name="q" value="{searchTerms}" />
|
||||||
|
<Param name="check_keywords" value="yes" />
|
||||||
|
<Param name="area" value="default" />
|
||||||
|
</Url>
|
||||||
|
{% block extra %}{# Put e.g. an <Image> element here. #}{% endblock %}
|
||||||
|
</OpenSearchDescription>
|
Loading…
Reference in New Issue
Block a user