From 12b37c39e19df082e48825cfcf59fc067bffb4d0 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Fri, 10 Apr 2020 14:08:25 +0200 Subject: docs: render all examples into one markdown page --- docs/render_examples.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 docs/render_examples.py (limited to 'docs/render_examples.py') 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))) -- cgit v1.2.3 From 5ea75a1a8176f764429fb45875626b1b7ef6644c Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Fri, 10 Apr 2020 14:08:40 +0200 Subject: examples: reformat to prevent too long lines --- docs/render_examples.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/render_examples.py') diff --git a/docs/render_examples.py b/docs/render_examples.py index ad156698..b6fa42eb 100755 --- a/docs/render_examples.py +++ b/docs/render_examples.py @@ -40,9 +40,9 @@ 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("#" * current_level, current_dir) print(textwrap.dedent(""" {} {} {{{{< example src="{}" lang="py" >}}}} - """.format("#"*(current_level+1), ex, "/examples/"+ex))) + """.format("#" * (current_level + 1), ex, "/examples/" + ex))) -- cgit v1.2.3 From 55527c00eb35bf3b07b361363fd8ca2961afc8ba Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 11 Apr 2020 12:25:56 +0200 Subject: docs: rename docs scripts and improve template --- docs/render_examples.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'docs/render_examples.py') diff --git a/docs/render_examples.py b/docs/render_examples.py index b6fa42eb..9c6dea74 100755 --- a/docs/render_examples.py +++ b/docs/render_examples.py @@ -14,10 +14,12 @@ menu: # Examples of Addons and Scripts +The most recent set of examples is also available [on our GitHub project](https://github.com/mitmproxy/mitmproxy/tree/master/examples). + """) base = os.path.dirname(os.path.realpath(__file__)) -examples_path = os.path.join(base, '../src/examples/') +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)] @@ -33,7 +35,7 @@ for ex in examples: print(" * [Examples: {}]({{{{< relref \"addons-examples#{}\">}}}})".format(current_dir, sanitized)) sanitized = ex.replace('/', '').replace('.', '') - print(" * [{}]({{{{< relref \"addons-examples#{}\">}}}})".format(ex, sanitized)) + print(" * [{}]({{{{< relref \"addons-examples#example-{}\">}}}})".format(os.path.basename(ex), sanitized)) current_dir = None current_level = 2 @@ -43,6 +45,6 @@ for ex in examples: print("#" * current_level, current_dir) print(textwrap.dedent(""" - {} {} + {} Example: {} {{{{< example src="{}" lang="py" >}}}} - """.format("#" * (current_level + 1), ex, "/examples/" + ex))) + """.format("#" * (current_level + 1), ex, "examples/" + ex))) -- cgit v1.2.3