From 9e20a7fff62152f2a221f43165986e226abea6c5 Mon Sep 17 00:00:00 2001 From: Kevin Yu <31861128+yqlbu@users.noreply.github.com> Date: Sat, 27 May 2023 19:52:13 +0800 Subject: [PATCH] ci(hack): add config-doc-generator (#101) Co-authored-by: mzz2017 <2017@duck.com> --- .github/workflows/check-docs.yml | 8 ++++---- docs/.gitignore | 2 ++ docs/sync/.gitkeep | 0 docs/templates/example-config.md | 15 ++++++++++++++ example.dae | 4 ---- hack/ci/config-doc-generator.py | 34 ++++++++++++++++++++++++++++++++ 6 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 docs/.gitignore create mode 100644 docs/sync/.gitkeep create mode 100644 docs/templates/example-config.md create mode 100644 hack/ci/config-doc-generator.py diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml index a50eca1..421d9a0 100644 --- a/.github/workflows/check-docs.yml +++ b/.github/workflows/check-docs.yml @@ -4,21 +4,21 @@ on: push: branches: [main] paths: - - 'README*.md' + - 'README.md' - 'docs/**' - 'package.json' - '.autocorrectrc' - '.markdownlint-cli2.jsonc' - - '.github/workflows/check-docs.yaml' + - '.github/workflows/check-docs.yml' pull_request: branches: [main] paths: - - 'README*.md' + - 'README.md' - 'docs/**' - 'package.json' - '.autocorrectrc' - '.markdownlint-cli2.jsonc' - - '.github/workflows/check-docs.yaml' + - '.github/workflows/check-docs.yml' jobs: check-doc: diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000..42be43c --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,2 @@ +sync/* +!sync/.gitkeep diff --git a/docs/sync/.gitkeep b/docs/sync/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/templates/example-config.md b/docs/templates/example-config.md new file mode 100644 index 0000000..652a423 --- /dev/null +++ b/docs/templates/example-config.md @@ -0,0 +1,15 @@ +--- +sidebar_position: 7 +--- + +# Example Config + +Original Copy: + + + +```python + +``` + + diff --git a/example.dae b/example.dae index 26f1525..956eb54 100644 --- a/example.dae +++ b/example.dae @@ -1,6 +1,5 @@ global { ##### Software options. - ### # tproxy port to listen on. It is NOT a HTTP/SOCKS port, and is just used by eBPF program. # In normal case, you do not need to use it. @@ -14,7 +13,6 @@ global { ##### Interface and kernel options. - ### # The LAN interface to bind. Use it if you want to proxy LAN. # Multiple interfaces split by ",". @@ -30,7 +28,6 @@ global { ##### Node connectivity check. - ### # Host of URL should have both IPv4 and IPv6 if you have double stack in local. # First is URL, others are IP addresses if given. @@ -56,7 +53,6 @@ global { ##### Connecting options. - ### # Optional values of dial_mode are: # 1. "ip". Dial proxy using the IP from DNS directly. This allows your ipv4, ipv6 to choose the optimal path diff --git a/hack/ci/config-doc-generator.py b/hack/ci/config-doc-generator.py new file mode 100644 index 0000000..baa41a6 --- /dev/null +++ b/hack/ci/config-doc-generator.py @@ -0,0 +1,34 @@ +import re + + +def read_config(filename): + with open(filename, 'r') as f: + return ''.join(f.readlines()) + + +def replacetext(src_file, dest_file, search_text, replace_text): + with open(src_file, 'r+') as src: + src_file = src.read() # Read + src.close() + with open(dest_file, 'w') as dest: + dest_file = re.sub(search_text, replace_text, src_file) # Replace + dest.seek(0) # Setting the position to the top of the page to insert data + dest.write(dest_file) # Write + + dest.close() + + +def main(): + search_text = '' + replace_text = read_config('example.dae') + + replacetext( + 'docs/templates/example-config.md', + 'docs/sync/example-config.md', + search_text, + replace_text, + ) + + +if __name__ == '__main__': + main()