# SPDX-FileCopyrightText: 2023 The "Notes on OpenPGP" project
# SPDX-License-Identifier: CC0-1.0
#
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from datetime import date

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'OpenPGP for application developers'
author = 'The "Notes on OpenPGP" project'
upstream_url = "https://codeberg.org/openpgp/notes"
license_url = "https://creativecommons.org/licenses/by-sa/4.0/"
copyright = f'{date.today().year}, <a href="{upstream_url}">{author}</a>, <a href="{license_url}">CC-BY-SA-4.0</a>'
version = "0.1"
suppress_warnings = [
    'epub.unknown_project_files',
]
description = 'The essential OpenPGP guide for application developers. Learn the OpenPGP standard for cryptographic operations and how to implement it in your projects. Gain insights into digital signatures, key management, certificates, and more. Version agnostic.'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
    'myst_parser',
    'sphinxext.opengraph',
    'sphinx_sitemap',
]
source_suffix = ['.md', '.rst']

templates_path = ['_templates']
exclude_patterns = []

# number code-blocks, figures and tables, if they have a caption
numfig = True
# number figures in flat hierarchy
numfig_secnum_depth = 0

# format today as YYYY-MM-DD instead of language specific
today_fmt = "%Y-%m-%d"

# -- Options for MyST-parser -------------------------------------------------
# https://myst-parser.readthedocs.io/en/latest/configuration.html

# we want to circumvent obscure warnings about footnotes following a heading:
# https://github.com/executablebooks/MyST-Parser/issues/352
myst_footnote_transition = False

# Enable definition lists
# https://myst-parser.readthedocs.io/en/latest/syntax/optional.html#syntax-definition-lists
myst_enable_extensions = [
    "deflist",
]

# https://myst-parser.readthedocs.io/en/latest/configuration.html#setting-html-metadata
myst_html_meta = {
    "description lang=en": description,
    "keywords": "openpgp, cryptographic operations, data encryption, digital signatures, key management, identity verification, secure communication, pgp, cryptographic protocols, public key encryption, openpgp v4, openpgp v6, openpgp implementation",
    "property=og:locale":  "en_US"
}

# -- Options for EPUB output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-epub-output

epub_copyright = f'{date.today().year}, {author} ({upstream_url}), CC-BY-SA-4.0'
epub_cover = ('_static/epub/img/cover.png', 'cover.j2')
epub_description = description
epub_css_files = [
    'epub/css/custom.css'
]
epub_basename = project.replace(" ", "_")

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
html_css_files = [
    ('html/css/custom.css', {'priority': 1000})
]

html_baseurl = 'https://openpgp.dev/book/'
html_favicon = '_static/html/img/favicon.ico'
html_logo = '_static/html/img/logo.svg'
html_show_sphinx = False
html_show_sourcelink = False
html_title = project

# https://github.com/sphinx-doc/alabaster/blob/0.x/alabaster/theme.conf
html_theme_options = {
    'code_font_size': '9pt',
    'extra_nav_links': {
        'Sources on Codeberg': upstream_url,
        'Download EPUB': f'https://openpgp.dev/book/{epub_basename}.epub',
    },
    'show_relbars': 'yes',
    'show_powered_by': False,
}

# https://github.com/wpilibsuite/sphinxext-opengraph#simple-config
ogp_site_url = 'https://openpgp.dev/book/'
ogp_image = '_static/html/img/logo.png'
ogp_type = 'book'

ogp_custom_meta_tags = [
    f'<meta property="og:description" content="{description}" />',
]

# sphinx sitemap https://sphinx-sitemap.readthedocs.io/en/latest/advanced-configuration.html
sitemap_url_scheme = "{link}"
