mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
docs: add 'edit-on-github' link to html theme
Closes IDF-1504
This commit is contained in:
parent
a97cd645ad
commit
214f1fbbed
@ -23,6 +23,8 @@ import re
|
||||
import subprocess
|
||||
from sanitize_version import sanitize_version
|
||||
from idf_extensions.util import download_file_if_missing
|
||||
from get_github_rev import get_github_rev
|
||||
|
||||
|
||||
# build_docs on the CI server sometimes fails under Python3. This is a workaround:
|
||||
sys.setrecursionlimit(3500)
|
||||
@ -218,6 +220,14 @@ html_redirect_pages = [tuple(l.split(' ')) for l in lines]
|
||||
|
||||
html_theme = 'sphinx_idf_theme'
|
||||
|
||||
# context used by sphinx_idf_theme
|
||||
html_context = {
|
||||
"display_github": True, # Add 'Edit on Github' link instead of 'View page source'
|
||||
"github_user": "espressif",
|
||||
"github_repo": "esp-idf",
|
||||
"github_version": get_github_rev(),
|
||||
}
|
||||
|
||||
# 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.
|
||||
@ -237,6 +247,7 @@ html_theme = 'sphinx_idf_theme'
|
||||
# of the sidebar.
|
||||
html_logo = "../_static/espressif-logo.svg"
|
||||
|
||||
|
||||
# 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.
|
||||
@ -387,6 +398,7 @@ def setup(app):
|
||||
|
||||
# Config values pushed by -D using the cmdline is not available when setup is called
|
||||
app.connect('config-inited', setup_config_values)
|
||||
app.connect('config-inited', setup_html_context)
|
||||
|
||||
|
||||
def setup_config_values(app, config):
|
||||
@ -402,6 +414,11 @@ def setup_config_values(app, config):
|
||||
app.add_config_value('pdf_file', pdf_name, 'env')
|
||||
|
||||
|
||||
def setup_html_context(app, config):
|
||||
# Setup path for 'edit on github'-link
|
||||
config.html_context['conf_py_path'] = "/docs/{}/".format(app.config.language)
|
||||
|
||||
|
||||
def setup_diag_font(app):
|
||||
# blockdiag and other tools require a font which supports their character set
|
||||
# the font file is stored on the download server to save repo size
|
||||
|
15
docs/get_github_rev.py
Normal file
15
docs/get_github_rev.py
Normal file
@ -0,0 +1,15 @@
|
||||
import subprocess
|
||||
|
||||
|
||||
# Get revision used for constructing github URLs
|
||||
def get_github_rev():
|
||||
path = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
|
||||
try:
|
||||
tag = subprocess.check_output(['git', 'describe', '--exact-match']).strip().decode('utf-8')
|
||||
except subprocess.CalledProcessError:
|
||||
tag = None
|
||||
print('Git commit ID: ', path)
|
||||
if tag:
|
||||
print('Git tag: ', tag)
|
||||
return tag
|
||||
return path
|
@ -8,19 +8,7 @@ import subprocess
|
||||
from docutils import nodes
|
||||
from collections import namedtuple
|
||||
from sphinx.transforms.post_transforms import SphinxPostTransform
|
||||
|
||||
|
||||
def get_github_rev():
|
||||
path = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip().decode('utf-8')
|
||||
try:
|
||||
tag = subprocess.check_output(['git', 'describe', '--exact-match']).strip().decode('utf-8')
|
||||
except subprocess.CalledProcessError:
|
||||
tag = None
|
||||
print('Git commit ID: ', path)
|
||||
if tag:
|
||||
print('Git tag: ', tag)
|
||||
return tag
|
||||
return path
|
||||
from get_github_rev import get_github_rev
|
||||
|
||||
|
||||
# Creates a dict of all submodules with the format {submodule_path : (url relative to git root), commit)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user