From a716ac6ed267e0a2e019fe7d2fda1bef0046cdc7 Mon Sep 17 00:00:00 2001 From: Themba Dube Date: Mon, 7 Jun 2021 16:07:40 -0400 Subject: [PATCH] feat(docs) add view on GitHub link --- docs/_ext/lv_example.py | 14 ++++++++------ docs/conf.py | 3 +++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/_ext/lv_example.py b/docs/_ext/lv_example.py index 7c5268fb9..a451890c1 100644 --- a/docs/_ext/lv_example.py +++ b/docs/_ext/lv_example.py @@ -1,14 +1,17 @@ -from docutils.parsers.rst import Directive +import os + from docutils import nodes +from docutils.parsers.rst import Directive from docutils.parsers.rst.directives.images import Image from sphinx.directives.code import LiteralInclude -import os + class LvExample(Directive): required_arguments = 3 def run(self): example_path = self.arguments[0] example_name = os.path.split(example_path)[1] + language = self.arguments[2] node_list = [] env = self.state.document.settings.env @@ -28,9 +31,9 @@ class LvExample(Directive): except FileNotFoundError: contents = 'Error encountered while trying to open ' + example_file literal_list = nodes.literal_block(contents, contents) - literal_list['language'] = self.arguments[2] + literal_list['language'] = language toggle.append(literal_list) - header.append(nodes.paragraph(text="code")) + header.append(nodes.raw(text=f"

code (view on GitHub)

", format='html')) if env.app.tags.has('html'): node_list.append(paragraph_node) node_list.append(toggle) @@ -38,8 +41,7 @@ class LvExample(Directive): def setup(app): app.add_directive("lv_example", LvExample) - app.add_config_value("example_commit_hash", "", "env") - app.add_config_value("built_example_commit_hash", "", "env") + app.add_config_value("repo_commit_hash", "", "env") return { 'version': '0.1', diff --git a/docs/conf.py b/docs/conf.py index 20b775892..d0e532d3f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -224,6 +224,9 @@ StandaloneHTMLBuilder.supported_image_types = [ smartquotes = False +_, repo_commit_hash = subprocess.getstatusoutput("git rev-parse HEAD") + + # Example configuration for intersphinx: refer to the Python standard library. def setup(app):