diff options
-rw-r--r-- | docs/.gitignore | 7 | ||||
-rwxr-xr-x | docs/build-current | 2 | ||||
-rwxr-xr-x | docs/render_examples.py | 48 | ||||
-rw-r--r-- | docs/src/assets/style.scss | 1 | ||||
-rw-r--r-- | docs/src/layouts/shortcodes/example.html | 3 |
5 files changed, 56 insertions, 5 deletions
diff --git a/docs/.gitignore b/docs/.gitignore index 1fb99949..610ffdf1 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -1,5 +1,6 @@ generated/ -src/public -node_modules -public +src/public/ +node_modules/ +public/ src/resources/_gen/ +src/content/addons-examples.md diff --git a/docs/build-current b/docs/build-current index 7164de6d..d01b4e7e 100755 --- a/docs/build-current +++ b/docs/build-current @@ -8,5 +8,7 @@ for script in scripts/* ; do "$script" > "src/generated/${output%.*}.html" done +python3 render_examples > src/content/addons-examples.md + cd src hugo diff --git a/docs/render_examples.py b/docs/render_examples.py new file mode 100755 index 00000000..ad156698 --- /dev/null +++ b/docs/render_examples.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 + +import os +import textwrap +from pathlib import Path + +print(""" +--- +title: "Examples" +menu: + addons: + weight: 6 +--- + +# Examples of Addons and Scripts + +""") + +base = os.path.dirname(os.path.realpath(__file__)) +examples_path = os.path.join(base, '../src/examples/') +pathlist = Path(examples_path).glob('**/*.py') + +examples = [os.path.relpath(str(p), examples_path) for p in sorted(pathlist)] +examples = [p for p in examples if not os.path.basename(p) == '__init__.py'] +examples = [p for p in examples if not os.path.basename(p).startswith('test_')] + +current_dir = None +current_level = 2 +for ex in examples: + if os.path.dirname(ex) != current_dir: + current_dir = os.path.dirname(ex) + sanitized = current_dir.replace('/', '').replace('.', '') + print(" * [Examples: {}]({{{{< relref \"addons-examples#{}\">}}}})".format(current_dir, sanitized)) + + sanitized = ex.replace('/', '').replace('.', '') + print(" * [{}]({{{{< relref \"addons-examples#{}\">}}}})".format(ex, sanitized)) + +current_dir = None +current_level = 2 +for ex in examples: + if os.path.dirname(ex) != current_dir: + current_dir = os.path.dirname(ex) + print("#"*current_level, current_dir) + + print(textwrap.dedent(""" + {} {} + {{{{< example src="{}" lang="py" >}}}} + """.format("#"*(current_level+1), ex, "/examples/"+ex))) diff --git a/docs/src/assets/style.scss b/docs/src/assets/style.scss index 26c22071..33e8863e 100644 --- a/docs/src/assets/style.scss +++ b/docs/src/assets/style.scss @@ -47,6 +47,7 @@ body > div { width: 100%; text-align: right; } + max-width: 70vw; margin-bottom: 1em; } diff --git a/docs/src/layouts/shortcodes/example.html b/docs/src/layouts/shortcodes/example.html index d23cabb6..83a6075d 100644 --- a/docs/src/layouts/shortcodes/example.html +++ b/docs/src/layouts/shortcodes/example.html @@ -1,5 +1,4 @@ - <div class="example"> {{ highlight (trim (readFile (.Get "src")) "\n\r") (.Get "lang") "" }} <div class="path">{{ (.Get "src" )}}</div> -</div>
\ No newline at end of file +</div> |