flask/docs/conf.py

98 lines
3.2 KiB
Python
Raw Normal View History

2019-09-24 21:35:10 +08:00
import packaging.version
from pallets_sphinx_themes import get_version
from pallets_sphinx_themes import ProjectLink
# Project --------------------------------------------------------------
2019-09-24 21:35:10 +08:00
project = "Flask"
copyright = "2010 Pallets"
author = "Pallets"
release, version = get_version("Flask")
# General --------------------------------------------------------------
default_role = "code"
extensions = [
2019-09-24 21:35:10 +08:00
"sphinx.ext.autodoc",
"sphinx.ext.extlinks",
2019-09-24 21:35:10 +08:00
"sphinx.ext.intersphinx",
"sphinxcontrib.log_cabinet",
"sphinx_tabs.tabs",
"pallets_sphinx_themes",
]
autodoc_member_order = "bysource"
2021-05-11 13:45:42 +08:00
autodoc_typehints = "description"
autodoc_preserve_defaults = True
extlinks = {
"issue": ("https://github.com/pallets/flask/issues/%s", "#%s"),
"pr": ("https://github.com/pallets/flask/pull/%s", "#%s"),
}
intersphinx_mapping = {
2019-09-24 21:35:10 +08:00
"python": ("https://docs.python.org/3/", None),
"werkzeug": ("https://werkzeug.palletsprojects.com/", None),
"click": ("https://click.palletsprojects.com/", None),
"jinja": ("https://jinja.palletsprojects.com/", None),
2019-09-24 21:35:10 +08:00
"itsdangerous": ("https://itsdangerous.palletsprojects.com/", None),
"sqlalchemy": ("https://docs.sqlalchemy.org/", None),
2020-08-07 19:01:42 +08:00
"wtforms": ("https://wtforms.readthedocs.io/", None),
2022-07-25 10:35:28 +08:00
"blinker": ("https://blinker.readthedocs.io/", None),
}
# HTML -----------------------------------------------------------------
2019-09-24 21:35:10 +08:00
html_theme = "flask"
html_theme_options = {"index_sidebar_logo": False}
html_context = {
2019-09-24 21:35:10 +08:00
"project_links": [
2021-02-25 02:09:15 +08:00
ProjectLink("Donate", "https://palletsprojects.com/donate"),
ProjectLink("PyPI Releases", "https://pypi.org/project/Flask/"),
2019-09-24 21:35:10 +08:00
ProjectLink("Source Code", "https://github.com/pallets/flask/"),
ProjectLink("Issue Tracker", "https://github.com/pallets/flask/issues/"),
2021-02-25 02:09:15 +08:00
ProjectLink("Chat", "https://discord.gg/pallets"),
]
}
2019-09-24 21:35:10 +08:00
html_sidebars = {
2021-05-21 12:03:02 +08:00
"index": ["project.html", "localtoc.html", "searchbox.html", "ethicalads.html"],
"**": ["localtoc.html", "relations.html", "searchbox.html", "ethicalads.html"],
}
2021-05-21 12:03:02 +08:00
singlehtml_sidebars = {"index": ["project.html", "localtoc.html", "ethicalads.html"]}
2019-09-24 21:35:10 +08:00
html_static_path = ["_static"]
2023-04-21 02:34:48 +08:00
html_favicon = "_static/shortcut-icon.png"
html_logo = "_static/flask-vertical.png"
2020-04-05 00:43:06 +08:00
html_title = f"Flask Documentation ({version})"
html_show_sourcelink = False
# Local Extensions -----------------------------------------------------
2019-09-24 21:35:10 +08:00
def github_link(name, rawtext, text, lineno, inliner, options=None, content=None):
app = inliner.document.settings.env.app
release = app.config.release
2019-09-24 21:35:10 +08:00
base_url = "https://github.com/pallets/flask/tree/"
2019-09-24 21:35:10 +08:00
if text.endswith(">"):
words, text = text[:-1].rsplit("<", 1)
words = words.strip()
else:
words = None
2019-09-24 21:35:10 +08:00
if packaging.version.parse(release).is_devrelease:
2021-05-12 06:18:41 +08:00
url = f"{base_url}main/{text}"
else:
2020-04-05 00:43:06 +08:00
url = f"{base_url}{release}/{text}"
if words is None:
words = url
from docutils.nodes import reference
from docutils.parsers.rst.roles import set_classes
2019-09-24 21:35:10 +08:00
options = options or {}
set_classes(options)
node = reference(rawtext, words, refuri=url, **options)
return [node], []
def setup(app):
2019-09-24 21:35:10 +08:00
app.add_role("gh", github_link)