mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
feat(docs) add view on GitHub link
This commit is contained in:
parent
3cf5751461
commit
a716ac6ed2
@ -1,14 +1,17 @@
|
|||||||
from docutils.parsers.rst import Directive
|
import os
|
||||||
|
|
||||||
from docutils import nodes
|
from docutils import nodes
|
||||||
|
from docutils.parsers.rst import Directive
|
||||||
from docutils.parsers.rst.directives.images import Image
|
from docutils.parsers.rst.directives.images import Image
|
||||||
from sphinx.directives.code import LiteralInclude
|
from sphinx.directives.code import LiteralInclude
|
||||||
import os
|
|
||||||
|
|
||||||
class LvExample(Directive):
|
class LvExample(Directive):
|
||||||
required_arguments = 3
|
required_arguments = 3
|
||||||
def run(self):
|
def run(self):
|
||||||
example_path = self.arguments[0]
|
example_path = self.arguments[0]
|
||||||
example_name = os.path.split(example_path)[1]
|
example_name = os.path.split(example_path)[1]
|
||||||
|
language = self.arguments[2]
|
||||||
node_list = []
|
node_list = []
|
||||||
|
|
||||||
env = self.state.document.settings.env
|
env = self.state.document.settings.env
|
||||||
@ -28,9 +31,9 @@ class LvExample(Directive):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
contents = 'Error encountered while trying to open ' + example_file
|
contents = 'Error encountered while trying to open ' + example_file
|
||||||
literal_list = nodes.literal_block(contents, contents)
|
literal_list = nodes.literal_block(contents, contents)
|
||||||
literal_list['language'] = self.arguments[2]
|
literal_list['language'] = language
|
||||||
toggle.append(literal_list)
|
toggle.append(literal_list)
|
||||||
header.append(nodes.paragraph(text="code"))
|
header.append(nodes.raw(text=f"<p>code (<a class='fa fa-github' href='https://github.com/lvgl/lvgl/blob/{env.config.repo_commit_hash}/examples/{example_path}.{language}'>view on GitHub</a>)</p>", format='html'))
|
||||||
if env.app.tags.has('html'):
|
if env.app.tags.has('html'):
|
||||||
node_list.append(paragraph_node)
|
node_list.append(paragraph_node)
|
||||||
node_list.append(toggle)
|
node_list.append(toggle)
|
||||||
@ -38,8 +41,7 @@ class LvExample(Directive):
|
|||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_directive("lv_example", LvExample)
|
app.add_directive("lv_example", LvExample)
|
||||||
app.add_config_value("example_commit_hash", "", "env")
|
app.add_config_value("repo_commit_hash", "", "env")
|
||||||
app.add_config_value("built_example_commit_hash", "", "env")
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'version': '0.1',
|
'version': '0.1',
|
||||||
|
@ -224,6 +224,9 @@ StandaloneHTMLBuilder.supported_image_types = [
|
|||||||
|
|
||||||
smartquotes = False
|
smartquotes = False
|
||||||
|
|
||||||
|
_, repo_commit_hash = subprocess.getstatusoutput("git rev-parse HEAD")
|
||||||
|
|
||||||
|
|
||||||
# Example configuration for intersphinx: refer to the Python standard library.
|
# Example configuration for intersphinx: refer to the Python standard library.
|
||||||
|
|
||||||
def setup(app):
|
def setup(app):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user