allow multi-version and multi-lang in local
This commit is contained in:
parent
bccdd11398
commit
3316ac780a
23
Makefile
23
Makefile
@ -4,15 +4,17 @@ SPHINX_BUILD = sphinx-build
|
|||||||
CONFIG_DIR = .
|
CONFIG_DIR = .
|
||||||
SPHINXOPTS = -D project_root=$(ROOT) -D canonical_version=$(CANONICAL_VERSION) \
|
SPHINXOPTS = -D project_root=$(ROOT) -D canonical_version=$(CANONICAL_VERSION) \
|
||||||
-D versions=$(VERSIONS) -D languages=$(LANGUAGES) -D language=$(CURRENT_LANG) \
|
-D versions=$(VERSIONS) -D languages=$(LANGUAGES) -D language=$(CURRENT_LANG) \
|
||||||
|
-D is_remote_build=$(IS_REMOTE_BUILD) \
|
||||||
-A google_analytics_key=$(GOOGLE_ANALYTICS_KEY)
|
-A google_analytics_key=$(GOOGLE_ANALYTICS_KEY)
|
||||||
SOURCE_DIR = content
|
SOURCE_DIR = content
|
||||||
BUILD_DIR = _build
|
BUILD_DIR = _build
|
||||||
|
|
||||||
# TODO ANVFE consider current_version==canonical_version to include (or not) in URL?
|
HTML_BUILD_DIR = $(BUILD_DIR)/html
|
||||||
ifeq ($(CURRENT_LANG),en)
|
ifdef VERSIONS
|
||||||
L10N_HTML_BUILD_DIR = $(BUILD_DIR)/html
|
HTML_BUILD_DIR := $(HTML_BUILD_DIR)/12.0
|
||||||
else
|
endif
|
||||||
L10N_HTML_BUILD_DIR = $(BUILD_DIR)/html/$(CURRENT_LANG)
|
ifneq ($(CURRENT_LANG),en)
|
||||||
|
HTML_BUILD_DIR := $(HTML_BUILD_DIR)/$(CURRENT_LANG)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#=== Standard rules ===#
|
#=== Standard rules ===#
|
||||||
@ -28,13 +30,13 @@ help:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo "Cleaning build files..."
|
@echo "Cleaning build files..."
|
||||||
$(RM_CMD) $(BUILD_DIR)/*
|
rm -rf $(BUILD_DIR)/*
|
||||||
$(RM_CMD) extensions/odoo_theme/static/style.css
|
rm extensions/odoo_theme/static/style.css
|
||||||
@echo "Cleaning finished."
|
@echo "Cleaning finished."
|
||||||
|
|
||||||
html: extensions/odoo_theme/static/style.css
|
html: extensions/odoo_theme/static/style.css
|
||||||
@echo "Starting build..."
|
@echo "Starting build..."
|
||||||
$(SPHINX_BUILD) -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(L10N_HTML_BUILD_DIR)
|
$(SPHINX_BUILD) -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(HTML_BUILD_DIR)
|
||||||
@echo "Build finished."
|
@echo "Build finished."
|
||||||
|
|
||||||
# To call *after* `make html`
|
# To call *after* `make html`
|
||||||
@ -71,7 +73,6 @@ static: extensions/odoo_theme/static/style.css
|
|||||||
|
|
||||||
lang:
|
lang:
|
||||||
make clean
|
make clean
|
||||||
make fast CANONICAL_VERSION=12.0 VERSIONS=12.0,13.0,14.0,master LANGUAGES=en,fr,es CURRENT_LANG=en
|
make fast CANONICAL_VERSION=12.0 VERSIONS=12.0,13.0,14.0,master LANGUAGES=en,fr CURRENT_LANG=en
|
||||||
make fast CANONICAL_VERSION=12.0 VERSIONS=12.0,13.0,14.0,master LANGUAGES=en,fr,es CURRENT_LANG=fr
|
make fast CANONICAL_VERSION=12.0 VERSIONS=12.0,13.0,14.0,master LANGUAGES=en,fr CURRENT_LANG=fr
|
||||||
make fast CANONICAL_VERSION=12.0 VERSIONS=12.0,13.0,14.0,master LANGUAGES=en,fr,es CURRENT_LANG=es
|
|
||||||
|
|
||||||
|
20
conf.py
20
conf.py
@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@ -231,6 +232,7 @@ def setup(app):
|
|||||||
app.add_config_value('canonical_version', None, 'env')
|
app.add_config_value('canonical_version', None, 'env')
|
||||||
app.add_config_value('versions', None, 'env')
|
app.add_config_value('versions', None, 'env')
|
||||||
app.add_config_value('languages', 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_lexer('json', JsonLexer)
|
app.add_lexer('json', JsonLexer)
|
||||||
app.add_lexer('xml', XmlLexer)
|
app.add_lexer('xml', XmlLexer)
|
||||||
@ -302,11 +304,23 @@ def _generate_alternate_urls(app, pagename, templatename, context, doctree):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def _build_url(_version=None, _lang=None):
|
def _build_url(_version=None, _lang=None):
|
||||||
_root = app.config.project_root or str(Path(__file__).parent)
|
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
|
_version = _version or app.config.version
|
||||||
_lang = _lang or app.config.language or 'en'
|
_lang = _lang or app.config.language or 'en'
|
||||||
_canonical_page = (pagename + '.html').replace('index.html', '').replace('index/', '')
|
_canonical_page = f'{pagename}.html'
|
||||||
return f'{_root}/{_version}{f"/{_lang}" if _lang != "en" else ""}/{_canonical_page}'
|
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}'
|
||||||
|
|
||||||
_canonicalize()
|
_canonicalize()
|
||||||
_versionize()
|
_versionize()
|
||||||
|
Loading…
Reference in New Issue
Block a user