# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# At top on conf.py (with other import statements)
import recommonmark
from recommonmark.transform import AutoStructify


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

project = 'MISP-dockerized'
copyright = '2018,2019, DCSO GmbH'
author = 'DCSO GmbH'

# The short X.Y version
version = '1.1.1'
# The full version, including alpha/beta/rc tags
release = '1.1.1'

github_doc_root = 'https://github.com/DCSO/MISP-dockerized-docs/tree/master/docs/'

# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    #'sphinx.ext.autodoc',
    #'sphinx.ext.doctest',
    #'sphinx.ext.intersphinx',
    #'sphinx.ext.todo',
    #'sphinx.ext.coverage',
    #'sphinx.ext.mathjax',
    #'sphinx.ext.ifconfig',
    #'sphinx.ext.viewcode',
    'docxsphinx',
    'sphinx.ext.githubpages',
    'sphinx_markdown_tables',
    #'releases',
]

# Do not warn about external images (status badges in README.rst)
suppress_warnings = ['image.nonlocal_uri']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# http://www.sphinx-doc.org/en/stable/markdown.html
source_parsers = {
   '.md': 'recommonmark.parser.CommonMarkParser',
}

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'default'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
#html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further.  For a list of options available for each theme, see the
# documentation.
html_theme_options = {
    # Further Information: https://sphinx-rtd-theme.readthedocs.io/en/latest/configuring.html#html-theme-options
    #'canonical_url': '',
    #'analytics_id': '',
    'logo_only': False,
    'display_version': False,
    'prev_next_buttons_location': 'bottom',
    'style_external_links': True,
    #'vcs_pageview_mode': 'edit',
    # Toc options
    'collapse_navigation': False,
    'sticky_navigation': True,
    'navigation_depth': 4,
    'includehidden': True,
    'titles_only': False
}

# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = ["../.."]

# The name for this set of Sphinx documents.  If None, it defaults to
# "<project> v<release> documentation".
#html_title = None

# A shorter title for the navigation bar.  Default is the same as html_title.
#html_short_title = None

# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
html_logo = "_static/DCSO_Logo_Office_36pt_150dpi_allgrgb.png"

# The name of an image file (within the static path) to use as favicon of the
# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# Default: none
html_favicon = "_static/DCSO_Logo_Favicon_152x152_srgb.png"

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
html_last_updated_fmt = '%b %d, %Y'

# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True

# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}

# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}

# If false, no module index is generated.
html_domain_indices = True

# If false, no index is generated.
html_use_index = True

# If true, the index is split into individual pages for each letter.
#html_split_index = False

# If true, links to the reST sources are added to the pages.
html_show_sourcelink = True

# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
html_show_sphinx = True

# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
html_show_copyright = True

# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it.  The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''

# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None

# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'MISP-dockerized-docs'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'MISP-dockerized.tex', 'MISP-dockerized Documentation',
     'DCSO GmbH', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'misp-dockerized', 'MISP-dockerized Documentation',
     [author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'MISP-dockerized', 'MISP-dockerized Documentation',
     author, 'MISP-dockerized', 'One line description of project.',
     'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project
epub_author = author
epub_publisher = author
epub_copyright = copyright

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------

# -- Options for intersphinx extension ---------------------------------------

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}

# -- Options for todo extension ----------------------------------------------

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = True


# -- Options for Releases --------------------------------------------------

#releases_release_uri = "https://github.com/DCSO/MISP-dockerized/tree/%s"
#releases_issue_uri = "https://github.com/DCSO/MISP-dockerized/issues/%s"
# OR
releases_github_path = 'DCSO/MISP-dockerized'

#  You may optionally set releases_debug = True to see debug output while building your docs.
#releases_debug = True

# If your changelog includes “simple” pre-1.0 releases derived from a single branch (i.e. without stable release lines & semantic versioning) you may want to set releases_unstable_prehistory = True.
#releases_unstable_prehistory = True

# If you wish to use a different document name, use another config option (as per previous bullet point), 
# releases_document_name. E.g. releases_document_name = "CHANGES" would cause Releases 
# to mutate a file called CHANGES.rst instead of changelog.rst.
# It is possible to target multiple changelog files for mutation by setting releases_document_name to a list of strings 
# instead of a single string, e.g. releases_document_name = ['project_1/changelog', 'project_2/changes', 'changelog'].
# Releases only modifies the bulleted list in these files and does not touch other elements; 
# this allows you to place paragraphs, comments etc at the top (or bottom) of the document.
#releases_document_name = "CHANGES"

releases_document_name = ['changelogs/main', 'changelogs/misp-modules', 'changelogs/misp-postfix', 'changelogs/misp-proxy', 'changelogs/misp-robot', 'changelogs/misp-server' ]


# --- Options for sphinx-versioning --------------------------------------------------
#   Show a warning banner. Enables the Banner Message feature.
#    This setting may also be specified in your conf.py file. It must be a boolean:
scv_show_banner = True

# SCVersioning.
scv_banner_greatest_tag = True
scv_grm_exclude = ('.gitignore', '.nojekyll', 'README.rst')
scv_sort = ('semver', 'time')

# -- Options for Releases -----------------------------------------
def setup(app):
    app.add_config_value('recommonmark_config', {
            'url_resolver': lambda url: github_doc_root + url,
            'auto_toc_tree_section': 'Contents',
            }, True)
    app.add_transform(AutoStructify)