[MERGE] Forward-port of branch 12.0 to 13.0
This commit is contained in:
@@ -1,443 +1,330 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Understanding Accounting For Entrepreneurs documentation build configuration file, created by
|
||||
# sphinx-quickstart on Tue Feb 3 10:57:29 2015.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its
|
||||
# containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys
|
||||
import re
|
||||
import os
|
||||
DIR = os.path.dirname(__file__)
|
||||
sys.path.insert(
|
||||
0, os.path.abspath(
|
||||
os.path.join(DIR, '_extensions')))
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
from pygments.lexers import JsonLexer, XmlLexer
|
||||
from sphinx.util import logging
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
# 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.ifconfig',
|
||||
'sphinx.ext.todo',
|
||||
'odoo',
|
||||
'demo_link',
|
||||
'embedded_video',
|
||||
'github_link',
|
||||
'html_domain',
|
||||
'redirects',
|
||||
]
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
#=== General configuration ===#
|
||||
|
||||
# General information about the project.
|
||||
project = 'Odoo'
|
||||
copyright = 'Odoo S.A.'
|
||||
|
||||
# `version` if the version info for the project being documented, acts as replacement for |version|,
|
||||
# also used in various other places throughout the built documents.
|
||||
# `release` is the full version, including alpha/beta/rc tags. Acts as replacement for |release|.
|
||||
version = release = '13.0'
|
||||
|
||||
# The minimal Sphinx version required to build the documentation.
|
||||
needs_sphinx = '3.0.0'
|
||||
|
||||
# The default language in which the documentation is written. It is set to `None` because Sphinx
|
||||
# considers that no language means 'en'.
|
||||
language = None
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Odoo'
|
||||
copyright = u'2015-TODAY, Odoo S.A.'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '13.0'
|
||||
version = '13.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# List of patterns, relative to source directory, that match files and directories to ignore when
|
||||
# looking for source files.
|
||||
exclude_patterns = [
|
||||
# translations
|
||||
'locale',
|
||||
'README.*',
|
||||
# virtualenv
|
||||
'bin', 'include', 'lib',
|
||||
'odoo',
|
||||
]
|
||||
|
||||
# The RST text role to use when the role is not specified. E.g.: `example`.
|
||||
# We use 'literal' as default role for markdown compatibility: `foo` behaves like ``foo``.
|
||||
# See https://docutils.sourceforge.io/docs/ref/rst/roles.html#standard-roles for other roles.
|
||||
default_role = 'literal'
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text
|
||||
add_function_parentheses = True
|
||||
|
||||
#=== Extensions configuration ===#
|
||||
|
||||
# Add extensions directory to PYTHONPATH
|
||||
extension_dir = Path('extensions')
|
||||
sys.path.insert(0, str(extension_dir.absolute()))
|
||||
|
||||
# Search for the directory of odoo sources to know whether autodoc should be used on the dev doc
|
||||
odoo_dir = Path('odoo')
|
||||
odoo_dir_in_path = False
|
||||
if not odoo_dir.is_dir():
|
||||
_logger.warning(
|
||||
f"Could not find Odoo sources directory at {odoo_dir.absolute()}.\n"
|
||||
f"The 'Developer' documentation will be built but autodoc directives will be skipped.\n"
|
||||
f"In order to fully build the 'Developer' documentation, clone the repository with "
|
||||
f"`git clone https://github.com/odoo/odoo` or create a symbolink link."
|
||||
)
|
||||
else:
|
||||
sys.path.insert(0, str(odoo_dir.absolute()))
|
||||
from odoo import release as odoo_release # Don't collide with Sphinx's 'release' config option
|
||||
odoo_version = odoo_release.version if 'alpha' not in odoo_release.version else 'master'
|
||||
if release != odoo_version:
|
||||
_logger.warning(
|
||||
f"Found Odoo sources directory but with version '{odoo_version}' incompatible with "
|
||||
f"documentation version '{version}'.\n"
|
||||
f"The 'Developer' documentation will be built but autodoc directives will be skipped.\n"
|
||||
f"In order to fully build the 'Developer' documentation, checkout the matching branch"
|
||||
f" with `cd odoo && git checkout {version}`."
|
||||
)
|
||||
else:
|
||||
_logger.info(f"Found Odoo sources directory matching documentation version {release}.")
|
||||
odoo_dir_in_path = True
|
||||
|
||||
# The Sphinx extensions to use, as module names.
|
||||
# They can be extensions coming with Sphinx (named 'sphinx.ext.*') or custom ones.
|
||||
extensions = [
|
||||
# Parse Python docstrings (autodoc, automodule, autoattribute directives)
|
||||
'sphinx.ext.autodoc' if odoo_dir_in_path else 'autodoc_placeholder',
|
||||
|
||||
# Link sources in other projects (used to build the reference doc)
|
||||
'sphinx.ext.intersphinx',
|
||||
|
||||
# Support the specialized to-do directives
|
||||
'sphinx.ext.todo',
|
||||
|
||||
# Custom Odoo theme
|
||||
'odoo_theme',
|
||||
|
||||
# Youtube and Vimeo videos integration (youtube, vimeo directives)
|
||||
'embedded_video',
|
||||
|
||||
'exercise_admonition',
|
||||
|
||||
# Build code from git patches
|
||||
'patchqueue',
|
||||
|
||||
# Redirection generator
|
||||
'redirects',
|
||||
|
||||
# Code switcher (switcher and case directives)
|
||||
'switcher',
|
||||
|
||||
# Strange html domain logic used in memento pages
|
||||
'html_domain',
|
||||
]
|
||||
if odoo_dir_in_path:
|
||||
# GitHub links generation
|
||||
extensions += [
|
||||
'sphinx.ext.linkcode',
|
||||
'github_link',
|
||||
]
|
||||
|
||||
todo_include_todos = False
|
||||
|
||||
intersphinx_mapping = {
|
||||
'python': ('https://docs.python.org/3/', None),
|
||||
'werkzeug': ('https://werkzeug.palletsprojects.com/en/1.0.x/', None),
|
||||
}
|
||||
|
||||
github_user = 'odoo'
|
||||
github_project = 'documentation'
|
||||
|
||||
locale_dirs = ['locale/']
|
||||
supported_languages = {
|
||||
'de': 'Deutsch',
|
||||
'en': 'English',
|
||||
'es': 'Español',
|
||||
'fr': 'Français',
|
||||
'nl': 'Nederlands',
|
||||
'pt_BR': 'Português (BR)',
|
||||
'uk': 'українська',
|
||||
'zh_CN': '简体中文',
|
||||
}
|
||||
|
||||
# The specifications of redirect rules used by the redirects extension.
|
||||
redirects_file = 'redirects.txt'
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#default_role = None
|
||||
#=== Options for HTML output ===#
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
html_theme = 'odoo_theme'
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
# See extensions/odoo_theme/pygments_override.py
|
||||
pygments_style = 'odoo'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
# The paths that contain custom themes, relative to this directory.
|
||||
html_theme_path = ['extensions']
|
||||
|
||||
# If true, keep warnings as "system message" paragraphs in the built documents.
|
||||
#keep_warnings = False
|
||||
# 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.
|
||||
html_favicon = os.path.join(html_theme_path[0], html_theme, 'static', 'img', 'favicon.ico')
|
||||
|
||||
# The paths that contain custom static files, 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']
|
||||
html_add_permalinks = '¶' # Sphinx < 3.5
|
||||
html_permalinks = True # Sphinx >= 3.5
|
||||
# Additional JS & CSS files that can be imported with the 'custom-js' and 'custom-css' metadata.
|
||||
# Lists are empty because the files are specified in extensions/themes.
|
||||
html_js_files = []
|
||||
html_css_files = []
|
||||
|
||||
# -- 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 = 'odoo'
|
||||
|
||||
# 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 = {
|
||||
'nosidebar': 'true',
|
||||
# PHP lexer option to not require <?php
|
||||
highlight_options = {
|
||||
'php': {'startinline': True},
|
||||
}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
html_theme_path = ['_extensions']
|
||||
|
||||
# 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 = None
|
||||
|
||||
# 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.
|
||||
#html_favicon = None
|
||||
|
||||
# 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']
|
||||
html_add_permalinks = ''
|
||||
|
||||
# Add any extra paths that contain custom files (such as robots.txt or
|
||||
# .htaccess) here, relative to this directory. These files are copied
|
||||
# directly to the root of the documentation.
|
||||
#html_extra_path = []
|
||||
|
||||
# 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
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'UnderstandingAccountingForEntrepreneursdoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
#=== Options for LaTeX output ===#
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
'papersize': 'a4paper',
|
||||
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
'papersize': 'a4paper',
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
'preamble': r'\usepackage{odoo}',
|
||||
'tableofcontents': '', # no TOC
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
'preamble': r'\usepackage{odoo}',
|
||||
'tableofcontents': r'', # no TOC
|
||||
|
||||
# output manually in latex docs
|
||||
'releasename': '',
|
||||
# Output manually in latex docs
|
||||
'releasename': '14.0',
|
||||
}
|
||||
|
||||
latex_additional_files = ['_static/latex/odoo.sty']
|
||||
latex_additional_files = ['static/latex/odoo.sty']
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
# 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 = [
|
||||
('legal/terms/enterprise_tex', 'odoo_enterprise_agreement.tex', 'Odoo Enterprise Subscription Agreement', '', 'howto'),
|
||||
('legal/terms/partnership_tex', 'odoo_partnership_agreement.tex', 'Odoo Partnership Agreement', '', 'howto'),
|
||||
('legal/terms/terms_of_sale', 'terms_of_sale.tex', 'Odoo Terms of Sale', '', 'howto'),
|
||||
('legal/terms/enterprise_tex', 'odoo_enterprise_agreement.tex',
|
||||
'Odoo Enterprise Subscription Agreement', '', 'howto'),
|
||||
('legal/terms/partnership_tex',
|
||||
'odoo_partnership_agreement.tex', 'Odoo Partnership Agreement', '', 'howto'),
|
||||
('legal/terms/terms_of_sale',
|
||||
'terms_of_sale.tex', 'Odoo Terms of Sale', '', 'howto'),
|
||||
|
||||
('legal/terms/i18n/enterprise_tex_fr', 'odoo_enterprise_agreement_fr.tex', 'Odoo Enterprise Subscription Agreement (FR)', '', 'howto'),
|
||||
('legal/terms/i18n/partnership_tex_fr', 'odoo_partnership_agreement_fr.tex', 'Odoo Partnership Agreement (FR)', '', 'howto'),
|
||||
('legal/terms/i18n/terms_of_sale_fr', 'terms_of_sale_fr.tex', u'Conditions Générales de Vente Odoo', '', 'howto'),
|
||||
('legal/terms/i18n/enterprise_tex_fr', 'odoo_enterprise_agreement_fr.tex',
|
||||
'Odoo Enterprise Subscription Agreement (FR)', '', 'howto'),
|
||||
('legal/terms/i18n/partnership_tex_fr',
|
||||
'odoo_partnership_agreement_fr.tex', 'Odoo Partnership Agreement (FR)', '', 'howto'),
|
||||
('legal/terms/i18n/terms_of_sale_fr', 'terms_of_sale_fr.tex',
|
||||
u'Conditions Générales de Vente Odoo', '', 'howto'),
|
||||
|
||||
('legal/terms/i18n/enterprise_tex_nl', 'odoo_enterprise_agreement_nl.tex', 'Odoo Enterprise Subscription Agreement (NL)', '', 'howto'),
|
||||
#('legal/terms/i18n/partnership_tex_nl', 'odoo_partnership_agreement_nl.tex', 'Odoo Partnership Agreement (NL)', '', 'howto'),
|
||||
('legal/terms/i18n/enterprise_tex_nl', 'odoo_enterprise_agreement_nl.tex',
|
||||
'Odoo Enterprise Subscription Agreement (NL)', '', 'howto'),
|
||||
|
||||
('legal/terms/i18n/enterprise_tex_de', 'odoo_enterprise_agreement_de.tex', 'Odoo Enterprise Subscription Agreement (DE)', '', 'howto'),
|
||||
#('legal/terms/i18n/partnership_tex_de', 'odoo_partnership_agreement_de.tex', 'Odoo Partnership Agreement (DE)', '', 'howto'),
|
||||
('legal/terms/i18n/enterprise_tex_de', 'odoo_enterprise_agreement_de.tex',
|
||||
'Odoo Enterprise Subscription Agreement (DE)', '', 'howto'),
|
||||
|
||||
('legal/terms/i18n/enterprise_tex_es', 'odoo_enterprise_agreement_es.tex', 'Odoo Enterprise Subscription Agreement (ES)', '', 'howto'),
|
||||
('legal/terms/i18n/partnership_tex_es', 'odoo_partnership_agreement_es.tex', 'Odoo Partnership Agreement (ES)', '', 'howto'),
|
||||
|
||||
#('index', 'UnderstandingAccountingForEntrepreneurs.tex', u'Understanding Accounting For Entrepreneurs Documentation', u'fp, xmo', 'manual'),
|
||||
('legal/terms/i18n/enterprise_tex_es', 'odoo_enterprise_agreement_es.tex',
|
||||
'Odoo Enterprise Subscription Agreement (ES)', '', 'howto'),
|
||||
('legal/terms/i18n/partnership_tex_es',
|
||||
'odoo_partnership_agreement_es.tex', 'Odoo Partnership Agreement (ES)', '', 'howto'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
latex_logo = '_static/icons/odoo_logo.png'
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
# The name of an image file (relative to this directory) to place at the top of the title page.
|
||||
latex_logo = 'static/img/odoo_logo.png'
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
latex_show_urls = "True"
|
||||
latex_show_urls = 'True'
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'understandingaccountingforentrepreneurs', u'Understanding Accounting For Entrepreneurs Documentation',
|
||||
[u'fp, xmo'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- 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 = [
|
||||
('index', 'UnderstandingAccountingForEntrepreneurs', u'Understanding Accounting For Entrepreneurs Documentation',
|
||||
u'fp, xmo', 'UnderstandingAccountingForEntrepreneurs', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
|
||||
# If true, do not generate a @detailmenu in the "Top" node's menu.
|
||||
#texinfo_no_detailmenu = False
|
||||
|
||||
odoo_cover_external = {}
|
||||
|
||||
github_user = 'odoo'
|
||||
github_project = 'documentation-user'
|
||||
|
||||
# Where are stored the localisations files
|
||||
locale_dirs = ['locale/']
|
||||
|
||||
LANGUAGES = {
|
||||
'de': 'German',
|
||||
'en': 'English',
|
||||
'es': 'Spanish',
|
||||
'fr': 'French',
|
||||
'hr': 'Croatian',
|
||||
'nl': 'Dutch',
|
||||
'pt_BR': 'Portuguese (BR)',
|
||||
'uk': 'Ukrainian',
|
||||
'zh_CN': 'Chinese',
|
||||
}
|
||||
|
||||
def setup(app):
|
||||
app.add_stylesheet('accounting.css')
|
||||
app.add_stylesheet('legal.css')
|
||||
app.add_javascript('prefixfree.min.js')
|
||||
app.add_javascript('atom.js')
|
||||
app.add_javascript('immutable.js')
|
||||
app.add_javascript('react.min.js')
|
||||
app.add_javascript('accounts.js')
|
||||
app.add_javascript('chart-of-accounts.js')
|
||||
app.add_javascript('entries.js')
|
||||
app.add_javascript('reconciliation.js')
|
||||
app.add_javascript('misc.js')
|
||||
# Generate all alternate URLs for each document
|
||||
app.add_config_value('project_root', None, 'env')
|
||||
app.add_config_value('canonical_version', None, 'env')
|
||||
app.add_config_value('versions', None, 'env')
|
||||
app.add_config_value('languages', None, 'env')
|
||||
app.add_config_value('is_remote_build', None, 'env') # Whether the build is remotely deployed
|
||||
|
||||
app.add_javascript('inventory.js')
|
||||
app.add_javascript('coa-valuation-continental.js')
|
||||
app.add_javascript('coa-valuation-anglo-saxon.js')
|
||||
app.add_lexer('json', JsonLexer)
|
||||
app.add_lexer('xml', XmlLexer)
|
||||
|
||||
app.connect('html-page-context', canonicalize)
|
||||
app.add_config_value('canonical_root', None, 'env')
|
||||
app.add_config_value('canonical_branch', 'master', 'env')
|
||||
app.connect('html-page-context', _generate_alternate_urls)
|
||||
|
||||
app.connect('html-page-context', analytics)
|
||||
app.add_config_value('google_analytics_key', '', 'env')
|
||||
|
||||
app.connect('html-page-context', versionize)
|
||||
app.add_config_value('versions', '', 'env')
|
||||
def _generate_alternate_urls(app, pagename, templatename, context, doctree):
|
||||
""" Add keys of required alternate URLs for the current document in the rendering context.
|
||||
|
||||
app.connect('html-page-context', localize)
|
||||
app.add_config_value('languages', '', 'env')
|
||||
|
||||
app.connect('doctree-resolved', tag_toctrees)
|
||||
|
||||
def versionize(app, pagename, templatename, context, doctree):
|
||||
""" Adds a version switcher below the menu, requires ``canonical_root``
|
||||
and ``versions`` (an ordered, space-separated lists of all possible
|
||||
versions).
|
||||
Alternate URLS are required for:
|
||||
- The canonical link tag
|
||||
- The version switcher
|
||||
- The language switcher and related link tags
|
||||
"""
|
||||
if not (app.config.canonical_root and app.config.versions):
|
||||
return
|
||||
|
||||
# remove last fragment containing the version
|
||||
root = '/'.join(app.config.canonical_root.rstrip('/').split('/')[:-1])
|
||||
def _canonicalize():
|
||||
""" Add the canonical URL for the current document in the rendering context.
|
||||
|
||||
context['versions'] = [
|
||||
(vs, _build_url(root, vs, pagename))
|
||||
for vs in app.config.versions.split(',')
|
||||
if vs != app.config.version
|
||||
]
|
||||
The canonical version is the last released version of the documentation.
|
||||
For a given language, the canonical root of a page is in the same language so that web
|
||||
searches in that language don't redirect users to the english version of that page.
|
||||
|
||||
def analytics(app, pagename, templatename, context, doctree):
|
||||
if not app.config.google_analytics_key:
|
||||
return
|
||||
E.g.:
|
||||
- /documentation/sale.html -> canonical = /documentation/14.0/sale.html
|
||||
- /documentation/11.0/fr/website.html -> canonical = /documentation/14.0/fr/website.html
|
||||
"""
|
||||
# If the canonical version is not set, assume that the project has a single version
|
||||
_canonical_version = app.config.canonical_version or app.config.version
|
||||
_canonical_lang = 'en' # Always 'en'. Don't take the value of the config option.
|
||||
context['canonical'] = _build_url(_version=_canonical_version, _lang=_canonical_lang)
|
||||
|
||||
context['google_analytics_key'] = app.config.google_analytics_key
|
||||
def _versionize():
|
||||
""" Add the pairs of (version, url) for the current document in the rendering context.
|
||||
|
||||
def tag_toctrees(app, doctree, docname):
|
||||
""" Adds a 'toc' metadata entry to all documents containing a toctree node"""
|
||||
# document
|
||||
# section
|
||||
# title
|
||||
# compound@toctree-wrapper
|
||||
# ....
|
||||
if not len(doctree.children) == 1:
|
||||
return
|
||||
[section] = doctree.children
|
||||
if len(section.children) < 2:
|
||||
return
|
||||
compound = section.children[1]
|
||||
if 'toctree-wrapper' not in compound['classes']:
|
||||
return
|
||||
The entry 'version' is added by Sphinx in the rendering context.
|
||||
"""
|
||||
# If the list of versions is not set, assume that the project has no alternate version
|
||||
_alternate_versions = app.config.versions and app.config.versions.split(',') or []
|
||||
context['alternate_versions'] = [
|
||||
(_alternate_version, _build_url(_version=_alternate_version))
|
||||
for _alternate_version in sorted(_alternate_versions, reverse=True)
|
||||
if _alternate_version != version and (
|
||||
_alternate_version != 'master' or pagename.startswith('developer')
|
||||
)
|
||||
]
|
||||
|
||||
app.env.metadata[docname]['has-toc'] = True
|
||||
def _localize():
|
||||
""" Add the pairs of (lang, code, url) for the current document in the rendering context.
|
||||
|
||||
def localize(app, pagename, templatename, context, doctree):
|
||||
""" Adds a language switcher below the menu, requires ``canonical_root``
|
||||
and ``languages`` (an ordered, space-separated lists of all possible
|
||||
languages).
|
||||
"""
|
||||
if not (app.config.canonical_root and app.config.languages):
|
||||
return
|
||||
E.g.: ('French', 'fr', 'https://.../fr_BE/...')
|
||||
|
||||
current_lang = app.config.language or 'en'
|
||||
context['language'] = LANGUAGES.get(current_lang, current_lang.upper())
|
||||
context['languages'] = [
|
||||
(LANGUAGES.get(la, la.upper()), _build_url(app.config.canonical_root, (la != 'en' and la or ''), pagename))
|
||||
for la in app.config.languages.split(',')
|
||||
if la != current_lang
|
||||
]
|
||||
context['language_codes'] = [
|
||||
(la.split('_')[0] if la != 'en' else 'x-default', _build_url(app.config.canonical_root, (la != 'en' and la or ''), pagename))
|
||||
for la in app.config.languages.split(',')
|
||||
]
|
||||
The entry 'language' is added by Sphinx in the rendering context.
|
||||
"""
|
||||
_current_lang = app.config.language or 'en'
|
||||
# Replace the context value by its translated description ("Français" instead of "french")
|
||||
context['language'] = supported_languages.get(_current_lang)
|
||||
|
||||
def canonicalize(app, pagename, templatename, context, doctree):
|
||||
""" Adds a 'canonical' URL for the current document in the rendering
|
||||
context. Requires the ``canonical_root`` setting being set. The canonical
|
||||
branch is ``master`` but can be overridden using ``canonical_branch``.
|
||||
/documentation/user/12.0/sale.html -> /documentation/user/13.0/sale.html
|
||||
/documentation/user/11.0/fr/website.html -> /documentation/user/13.0/fr/website.html
|
||||
"""
|
||||
if not app.config.canonical_root:
|
||||
return
|
||||
# If the list of languages is not set, assume that the project has no alternate language
|
||||
_alternate_languages = app.config.languages and app.config.languages.split(',') or []
|
||||
context['alternate_languages'] = [
|
||||
(
|
||||
supported_languages.get(_alternate_lang),
|
||||
_alternate_lang.split('_')[0] if _alternate_lang != 'en' else 'x-default',
|
||||
_build_url(_lang=_alternate_lang),
|
||||
)
|
||||
for _alternate_lang in _alternate_languages
|
||||
if _alternate_lang in supported_languages and _alternate_lang != _current_lang
|
||||
]
|
||||
|
||||
# remove last fragment containing the version
|
||||
root = '/'.join(app.config.canonical_root.rstrip('/').split('/')[:-1])
|
||||
root += '/' + app.config.canonical_branch
|
||||
current_lang = app.config.language or 'en'
|
||||
def _build_url(_version=None, _lang=None):
|
||||
if app.config.is_remote_build:
|
||||
# Project root like https://odoo.com/documentation/14.0/fr
|
||||
_root = app.config.project_root
|
||||
else:
|
||||
# Project root like .../documentation/_build/html/14.0/fr
|
||||
_root = re.sub(rf'(/{app.config.version})?(/{app.config.language})?$', '', app.outdir)
|
||||
# If the canonical version is not set, assume that the project has a single version
|
||||
_canonical_version = app.config.canonical_version or app.config.version
|
||||
_version = _version or app.config.version
|
||||
_lang = _lang or app.config.language or 'en'
|
||||
_canonical_page = f'{pagename}.html'
|
||||
if app.config.is_remote_build:
|
||||
_canonical_page = _canonical_page.replace('index.html', '')
|
||||
return f'{_root}' \
|
||||
f'{f"/{_version}" if app.config.versions else ""}' \
|
||||
f'{f"/{_lang}" if _lang != "en" else ""}' \
|
||||
f'/{_canonical_page}'
|
||||
|
||||
context['canonical'] = _build_url(
|
||||
root, (current_lang != 'en' and current_lang or ''), pagename)
|
||||
|
||||
def _build_url(root, branch, pagename):
|
||||
root = root.rstrip('/')
|
||||
if branch:
|
||||
root += '/'
|
||||
return "{canonical_url}{canonical_branch}/{canonical_page}".format(
|
||||
canonical_url=root,
|
||||
canonical_branch=branch,
|
||||
canonical_page=(pagename + '.html').replace('index.html', '')
|
||||
.replace('index/', ''),
|
||||
)
|
||||
_canonicalize()
|
||||
_versionize()
|
||||
_localize()
|
||||
|
||||
Reference in New Issue
Block a user