-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: docsearch * fix: mypy * fix: python version for netlify * fix: docsearch on all pages Change the config options for DocSearch and add them both to the local context and global context. I think, it didn't work before because the `app.builder.globalcontext` is only initialized after `html-page-context` for the first page. * fix: update packages * fix: mypy * fix: link styles * fix: no jquery When using DocSearch, don't include `jquery` and `underscore` and all the other JavaScript libraries from Sphinx. * fix: scrollspy and search JS * fix: simplify templates - add 'sr-only' labels to buttons - remove unused 'search-pane' button and remove extra 'buttons' file now that the close button is only used once.
- Loading branch information
Showing
38 changed files
with
727 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"""Add Algolia DocSearch to Sphinx. | ||
This Sphinx extension adds DocSearch to your Sphinx project. | ||
:copyright: Kai Welke. | ||
:license: MIT | ||
""" | ||
import os | ||
from pathlib import Path | ||
from typing import Any, Dict | ||
|
||
from docutils.nodes import Node | ||
from dotenv import load_dotenv | ||
from sphinx.application import Sphinx | ||
from sphinx.util import progress_message | ||
|
||
from . import __version__ | ||
|
||
|
||
@progress_message("Set up DocSearch") | ||
def setup_docsearch( | ||
app: Sphinx, | ||
pagename: str, | ||
templatename: str, | ||
context: Dict[str, Any], | ||
doctree: Node, | ||
) -> None: | ||
"""Set up DocSearch. | ||
Config can be provided via environment variables, a `.env.` file, | ||
or the Sphinx configuration file. | ||
""" | ||
# load `.env` file into environment | ||
load_dotenv(dotenv_path=(Path(app.confdir) / ".env")) | ||
|
||
docsearch_config = { | ||
"container": ( | ||
os.getenv("DOCSEARCH_CONTAINER") | ||
or app.config.docsearch_config.get("container", "#docsearch") | ||
), | ||
"api_key": ( | ||
os.getenv("DOCSEARCH_API_KEY") or app.config.docsearch_config.get("api_key") | ||
), | ||
"index_name": ( | ||
os.getenv("DOCSEARCH_INDEX_NAME") | ||
or app.config.docsearch_config.get("index_name") | ||
), | ||
} | ||
|
||
# if we want to use `docsearch` we don't need any other JS file from Sphinx | ||
if app.config.html_awesome_docsearch: | ||
context["script_files"] = [] | ||
|
||
context["docsearch"] = app.config.html_awesome_docsearch | ||
# update local context for rendering the `layout.html` templates for every page | ||
context["docsearch_config"] = docsearch_config | ||
# update the global context for writing the `docsearch_config.js` file | ||
app.builder.globalcontext["docsearch_config"] = docsearch_config # type: ignore [union-attr] # noqa: B950,E501 | ||
|
||
|
||
def setup(app: Sphinx) -> Dict[str, Any]: | ||
"""Register the extension.""" | ||
app.add_css_file("docsearch.css", priority=150) | ||
app.connect("html-page-context", setup_docsearch) | ||
|
||
return { | ||
"version": __version__, | ||
"parallel_read_safe": True, | ||
"parallel_write_safe": True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{#- | ||
Template for the search box in the header. | ||
-#} | ||
|
||
{%- if docsearch %} | ||
<div id="{{ docsearch_config.container[1:] }}"></div> | ||
{%- else -%} | ||
<form | ||
id="searchbox" | ||
action="{{ pathto('search') }}" | ||
data-action="click->search#focusSearchInput" | ||
method="get" | ||
class="flex print:hidden justify-between items-center leading-14 sm:leading-18 md:ml-4 bg-gray-dark text-gray-300 focus-within:bg-gray-50 focus-within:text-gray-800 focus-within:absolute focus-within:inset-x-0 focus-within:top-0 md:focus-within:w-full md:focus-within:static"> | ||
|
||
<button | ||
class="text-inherit h-14 w-14 sm:h-18 sm:w-18" | ||
aria-label="{{ _('Get search results') }}" | ||
tabindex="-1" | ||
> | ||
<svg aria-hidden="true" class="fill-current stroke-current h-8 w-8" stroke-width="0.5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0016 9.5 6.5 6.5 0 109.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg> | ||
</button> | ||
|
||
<input | ||
name="q" | ||
id="search-input" | ||
data-search-target="searchInput" | ||
type="search" | ||
aria-label="Search the docs" | ||
placeholder="{{ _('Search the docs') }}" | ||
class="pr-2 bg-transparent text-inherit focus:outline-none w-0 md:w-auto focus:w-full transition-all duration-100" | ||
/> | ||
</form> | ||
{%- endif -%} |
Oops, something went wrong.