# Configuration file for Sphinx,
# see https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Recommended settings -----------------------------------------------------

html_theme = 'insipid'

html_permalinks_icon = '\N{SECTION SIGN}'

# -- Recommended settings for readthedocs.org ---------------------------------

# If False, source links to Bitbucket/Github/GitLab are shown
html_copy_source = False

# -- Settings for source code -------------------------------------------------

# Language used for syntax highlighting (default: 'python')
#highlight_language = 'none'

# Style of syntax highlighting
#pygments_style = 'monokai'

# -- Language settings --------------------------------------------------------

#language = 'es'

# Date format used in footer. Use empty string for (language-specific) default.
# 'sphinx_last_updated_by_git' extension provides modification dates per page.
#html_last_updated_fmt = '%Y-%m-%d %H:%M:%S %Z'

# -- Theme configuration ------------------------------------------------------

html_theme_options = {
    #'body_centered': False,
    #'body_max_width': None,
    #'breadcrumbs': True,
    #'globaltoc_collapse': False,
    #'globaltoc_includehidden': True,
    #'left_buttons': [
    #],
    #'navigation_with_keys': False,
    #'nosidebar': True,
    #'right_buttons': [
    #    'search-button.html',
    #],
    #'rightsidebar': True,
    #'show_insipid': False,
    #'sidebar_overlay_width': None,
    #'sidebar_transition': '1s ease-out',
    #'sidebarwidth': '10rem',
    #'strip_section_numbers': False,
    #'topbar_transition': '1.5s ease-out',
}

html_sidebars = {
   '**': [
       'github-badge.html',  # Custom template, see _templates/
       'home.html',
       'globaltoc.html',
       'separator.html',
       'indices.html',
   ],
   'showcase/no-sidebar': [],  # To demonstrate a page without a sidebar
}

html_static_path = ['_static']
templates_path = ['_templates']

# -- Project information ------------------------------------------------------

project = 'insipid-sphinx-theme'
#html_title = 'Insipid Sphinx Theme'
html_short_title = 'insipid'
#copyright = '<insert year and copyright holder>'
#version = '3.14'
#release = '3.14.dev2'

html_logo = 'showcase/insipid.png'
html_favicon = '_static/favicon.svg'

# -- Page footer --------------------------------------------------------------

html_show_copyright = False
#html_show_sphinx = False
#html_show_sourcelink = False

# Only relevant when html_copy_source is True
#html_sourcelink_suffix = ''

# -- Miscellaneous settings ---------------------------------------------------

# Numbered figures, tables and code-blocks
numfig = True

html_secnumber_suffix = '\N{FIGURE SPACE}'

#html_compact_lists = False

#smartquotes = False

# Generate alphabetic index
#html_use_index = False

# Separate page per starting letter
#html_split_index = True

# Generate domain indices, e.g. Python module index
#html_domain_indices = False

# The default in Sphinx 4+ is 'inline'
#html_codeblock_linenos_style = 'table'

# -- Sphinx extensions --------------------------------------------------------

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary',
    'sphinx.ext.intersphinx',
    'sphinx.ext.viewcode',
    'sphinx_last_updated_by_git',
]

intersphinx_mapping = {
    'sphinx': ('https://www.sphinx-doc.org/', None),
}

# -- Get version information from Git -----------------------------------------

try:
    from subprocess import check_output
    release = check_output(['git', 'describe', '--tags', '--always'])
    release = release.decode().strip()
except Exception:
    release = '<unknown>'

# -- Define custom directives/roles -------------------------------------------


def gh_template_role(rolename, rawtext, text, lineno, inliner,
                     options={}, content=()):
    from docutils import nodes, utils
    github_url = 'https://github.com/mgeier/insipid-sphinx-theme'
    blob_url = github_url + '/blob/' + release
    base_url = blob_url + '/src/insipid_sphinx_theme/insipid/%s'
    text = utils.unescape(text)
    full_url = base_url % text
    pnode = nodes.reference(internal=False, refuri=full_url)
    pnode += nodes.literal(text, text, classes=['file'])
    return [pnode], []


def setup(app):
    app.add_object_type(
        'confval', 'confval',
        objname='Sphinx configuration value',
        indextemplate='pair: %s; Sphinx configuration value')
    app.add_object_type(
        'theme-option', 'theme-option',
        objname='Theme option',
        indextemplate='pair: %s; Theme option')
    app.add_role('gh-template', gh_template_role)




###########################################################################
#          auto-created readthedocs.org specific configuration            #
###########################################################################


#
# The following code was added during an automated build on readthedocs.org
# It is auto created and injected for every build. The result is based on the
# conf.py.tmpl file found in the readthedocs.org codebase:
# https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl
#
# Note: this file shouldn't rely on extra dependencies.

import importlib
import sys
import os.path

# Borrowed from six.
PY3 = sys.version_info[0] == 3
string_types = str if PY3 else basestring

from sphinx import version_info

# Get suffix for proper linking to GitHub
# This is deprecated in Sphinx 1.3+,
# as each page can have its own suffix
if globals().get('source_suffix', False):
    if isinstance(source_suffix, string_types):
        SUFFIX = source_suffix
    elif isinstance(source_suffix, (list, tuple)):
        # Sphinx >= 1.3 supports list/tuple to define multiple suffixes
        SUFFIX = source_suffix[0]
    elif isinstance(source_suffix, dict):
        # Sphinx >= 1.8 supports a mapping dictionary for multiple suffixes
        SUFFIX = list(source_suffix.keys())[0]  # make a ``list()`` for py2/py3 compatibility
    else:
        # default to .rst
        SUFFIX = '.rst'
else:
    SUFFIX = '.rst'

# Add RTD Static Path. Add to the end because it overwrites previous files.
if not 'html_static_path' in globals():
    html_static_path = []
if os.path.exists('_static'):
    html_static_path.append('_static')

# Add RTD Theme only if they aren't overriding it already
using_rtd_theme = (
    (
        'html_theme' in globals() and
        html_theme in ['default'] and
        # Allow people to bail with a hack of having an html_style
        'html_style' not in globals()
    ) or 'html_theme' not in globals()
)
if using_rtd_theme:
    theme = importlib.import_module('sphinx_rtd_theme')
    html_theme = 'sphinx_rtd_theme'
    html_style = None
    html_theme_options = {}
    if 'html_theme_path' in globals():
        html_theme_path.append(theme.get_html_theme_path())
    else:
        html_theme_path = [theme.get_html_theme_path()]

if globals().get('websupport2_base_url', False):
    websupport2_base_url = 'https://readthedocs.org/websupport'
    websupport2_static_url = 'https://assets.readthedocs.org/static/'


#Add project information to the template context.
context = {
    'using_theme': using_rtd_theme,
    'html_theme': html_theme,
    'current_version': "0.2.9",
    'version_slug': "0.2.9",
    'MEDIA_URL': "https://media.readthedocs.org/",
    'STATIC_URL': "https://assets.readthedocs.org/static/",
    'PRODUCTION_DOMAIN': "readthedocs.org",
    'versions': [
    ("latest", "/en/latest/"),
    ("0.2.9", "/en/0.2.9/"),
    ("0.2.8", "/en/0.2.8/"),
    ("0.2.7", "/en/0.2.7/"),
    ("0.2.6", "/en/0.2.6/"),
    ("0.2.5", "/en/0.2.5/"),
    ("0.2.4", "/en/0.2.4/"),
    ("0.2.3", "/en/0.2.3/"),
    ("0.2.2", "/en/0.2.2/"),
    ("0.2.1", "/en/0.2.1/"),
    ("0.2.0", "/en/0.2.0/"),
    ("0.1.2", "/en/0.1.2/"),
    ("0.1.1", "/en/0.1.1/"),
    ("rightsidebar", "/en/rightsidebar/"),
    ("readthedocs-sphinx-search", "/en/readthedocs-sphinx-search/"),
    ("breadcrumbs", "/en/breadcrumbs/"),
    ("0.1.0", "/en/0.1.0/"),
    ],
    'downloads': [ 
    ("html", "//insipid-sphinx-theme.readthedocs.io/_/downloads/en/0.2.9/htmlzip/"),
    ],
    'subprojects': [ 
    ],
    'slug': 'insipid-sphinx-theme',
    'name': u'insipid-sphinx-theme',
    'rtd_language': u'en',
    'programming_language': u'css',
    'canonical_url': 'https://insipid-sphinx-theme.readthedocs.io/en/0.2.9/',
    'analytics_code': 'None',
    'single_version': False,
    'conf_py_path': '/doc/',
    'api_host': 'https://readthedocs.org',
    'github_user': 'mgeier',
    'proxied_api_host': '/_',
    'github_repo': 'insipid-sphinx-theme',
    'github_version': '0.2.9',
    'display_github': True,
    'bitbucket_user': 'None',
    'bitbucket_repo': 'None',
    'bitbucket_version': '0.2.9',
    'display_bitbucket': False,
    'gitlab_user': 'None',
    'gitlab_repo': 'None',
    'gitlab_version': '0.2.9',
    'display_gitlab': False,
    'READTHEDOCS': True,
    'using_theme': (html_theme == "default"),
    'new_theme': (html_theme == "sphinx_rtd_theme"),
    'source_suffix': SUFFIX,
    'ad_free': False,
    'docsearch_disabled': False,
    'user_analytics_code': '',
    'global_analytics_code': None,
    'commit': '2c878a5e',
}

# For sphinx >=1.8 we can use html_baseurl to set the canonical URL.
# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_baseurl
if version_info >= (1, 8):
    if not globals().get('html_baseurl'):
        html_baseurl = context['canonical_url']
    context['canonical_url'] = None





if 'html_context' in globals():
    
    html_context.update(context)
    
else:
    html_context = context

# Add custom RTD extension
if 'extensions' in globals():
    # Insert at the beginning because it can interfere
    # with other extensions.
    # See https://github.com/rtfd/readthedocs.org/pull/4054
    extensions.insert(0, "readthedocs_ext.readthedocs")
else:
    extensions = ["readthedocs_ext.readthedocs"]

# Add External version warning banner to the external version documentation
if 'tag' == 'external':
    extensions.insert(1, "readthedocs_ext.external_version_warning")
    readthedocs_vcs_url = 'None'
    readthedocs_build_url = 'https://readthedocs.org/projects/insipid-sphinx-theme/builds/15450374/'

project_language = 'en'

# User's Sphinx configurations
language_user = globals().get('language', None)
latex_engine_user = globals().get('latex_engine', None)
latex_elements_user = globals().get('latex_elements', None)

# Remove this once xindy gets installed in Docker image and XINDYOPS
# env variable is supported
# https://github.com/rtfd/readthedocs-docker-images/pull/98
latex_use_xindy = False

chinese = any([
    language_user in ('zh_CN', 'zh_TW'),
    project_language in ('zh_CN', 'zh_TW'),
])

japanese = any([
    language_user == 'ja',
    project_language == 'ja',
])

if chinese:
    latex_engine = latex_engine_user or 'xelatex'

    latex_elements_rtd = {
        'preamble': '\\usepackage[UTF8]{ctex}\n',
    }
    latex_elements = latex_elements_user or latex_elements_rtd
elif japanese:
    latex_engine = latex_engine_user or 'platex'

# Make sure our build directory is always excluded
exclude_patterns = globals().get('exclude_patterns', [])
exclude_patterns.extend(['_build'])
