From 6e9fdf1010ed861461835459a19e18501e3c8d54 Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Thu, 2 Feb 2023 11:59:19 +0800 Subject: [PATCH 1/3] feat: add conditional rendering --- mkdocs.yml | 8 ++++++- prepare.sh | 6 ++++- requirements.txt | 1 + scripts/conditional_render.py | 40 +++++++++++++++++++++++++++++++ scripts/conditional_yml.py | 45 +++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 scripts/conditional_render.py create mode 100644 scripts/conditional_yml.py diff --git a/mkdocs.yml b/mkdocs.yml index c11c375ed19..bc106ca4ea4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -79,6 +79,7 @@ plugins: - spark-connector/* - 4.deployment-and-installation/5.zone.md - 4.deployment-and-installation/3.upgrade-nebula-graph/upgrade-nebula-from-200-to-latest.md + # 仅发布包含企业版功能的文档版本时,注释以下页面 # begin # - 3.ngql-guide/6.functions-and-expressions/17.ES-function.md @@ -95,7 +96,8 @@ plugins: # - nebula-dashboard-ent/4.cluster-operator/operator/scale.md # - 6.monitor-and-metrics/3.bbox # end - + # comm.begin + # comm.end # Exclude the file with the following file name. # - abc.md @@ -125,6 +127,10 @@ extra_javascript: # modify when release: extra: + # For conditional rendering + # Valid options: enterprise, community, both + # enterprise means this version is for the Enterprise only. And so on in a similar fashion + database_edition: community # Language selector. alternate: - name: English diff --git a/prepare.sh b/prepare.sh index 6c40d01d427..b9b032bbe8f 100644 --- a/prepare.sh +++ b/prepare.sh @@ -1,10 +1,14 @@ sudo apt update -y sudo apt install -y python3-pip python3-cffi python3-brotli libpango-1.0-0 libharfbuzz0b libpangoft2-1.0-0 pango1.0-tools - +# Install dependencies pip install --upgrade pip pip install -r ./requirements.txt +# Render content according to the database_edition in mkdocs.yml +python ./scripts/conditional_render.py +python ./scripts/conditional_yml.py + # zh language sudo apt install font-manager fonts-noto-cjk language-pack-zh-hans fonts-arphic-ukai fonts-arphic-uming fonts-ipafont-mincho fonts-ipafont-gothic fonts-unfonts-core diff --git a/requirements.txt b/requirements.txt index 5c39f5d39d2..5ccd3ff5db4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ mkdocs-exclude mkdocs-redirects mkdocs-minify-plugin Markdown==3.3.7 +pyyaml \ No newline at end of file diff --git a/scripts/conditional_render.py b/scripts/conditional_render.py new file mode 100644 index 00000000000..3791151f60b --- /dev/null +++ b/scripts/conditional_render.py @@ -0,0 +1,40 @@ +# Rules for processing the markdown files in the docs-2.0 directory: +# - If database_edition is enterprise, the content between {{ ent.ent_begin }} and {{ ent.ent_end }} is kept and the content between {{ comm.comm_begin }} and {{ comm.comm_end }} is removed. +# - If database_edition is community, the content between {{ comm.comm_begin }} and {{ comm.comm_end }} is kept and the content between {{ ent.ent_begin }} and {{ ent.ent_end }} is removed. +# - If database_edition is both, both types of content are removed. + +import os +import re +import yaml + +def process_files(file_path, database_edition): + for root, dirs, files in os.walk(file_path): + for file in files: + if file.endswith('.md'): + file_full_path = os.path.join(root, file) + with open(file_full_path, 'r', encoding='utf-8') as f: + content = f.read() + if database_edition == 'enterprise': + content = re.sub( + r'{{\s*ent\.ent_begin\s*}}(.*?){{\s*ent\.ent_end\s*}}', + '\\1', content, flags=re.DOTALL) + content = re.sub( + r'{{\s*comm\.comm_begin\s*}}(.*?){{\s*comm\.comm_end\s*}}', + '', content, flags=re.DOTALL) + elif database_edition == 'community': + content = re.sub( + r'{{\s*ent\.ent_begin\s*}}(.*?){{\s*ent\.ent_end\s*}}', + '', content, flags=re.DOTALL) + content = re.sub( + r'{{\s*comm\.comm_begin\s*}}(.*?){{\s*comm\.comm_end\s*}}', + '\\1', content, flags=re.DOTALL) + with open(file_full_path, 'w', encoding='utf-8') as f: + f.write(content) + +if __name__ == '__main__': + mkdocs_yml_path = 'mkdocs.yml' + with open(mkdocs_yml_path, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + database_edition = config.get("extra", {}).get("database_edition", "both") + file_path = 'docs-2.0/' + process_files(file_path, database_edition) \ No newline at end of file diff --git a/scripts/conditional_yml.py b/scripts/conditional_yml.py new file mode 100644 index 00000000000..dd2aa36851e --- /dev/null +++ b/scripts/conditional_yml.py @@ -0,0 +1,45 @@ +# Rules for processing the mkdocs.yml file: +# - When `database_edition` is `community`, keep all content between tags `# ent.begin` and `# ent.end`, and delete all content between tags `# comm.begin` and `# comm.end`. +# - When `database_edition` is `enterprise`, keep all content between `# comm.begin` and `# comm.end`, and delete all content between `# ent.begin` and `# ent.end` +# - When `database_edition` is `both`, delete all content between `# ent.begin` and `# ent.end`, and between `# comm.begin` and `# comm.end`. +# - Always keep the tags. + +import os +import re +import yaml + +mkdocs_yml_path = 'mkdocs.yml' + +def process_mkdocs_yml(mkdocs_yml_path, database_edition): + with open(mkdocs_yml_path, 'r', encoding='utf-8') as f: + content = f.read() + if database_edition == 'enterprise': + content = re.sub( + r'#\s*ent\.begin(.*?)#\s*ent\.end', + '', content, flags=re.DOTALL) + content = re.sub( + r'#\s*comm\.begin(.*?)#\s*comm\.end', + '\\1', content, flags=re.DOTALL) + elif database_edition == 'community': + content = re.sub( + r'#\s*ent\.begin(.*?)#\s*ent\.end', + '\\1', content, flags=re.DOTALL) + content = re.sub( + r'#\s*comm\.begin(.*?)#\s*comm\.end', + '', content, flags=re.DOTALL) + elif database_edition == 'both': + content = re.sub( + r'#\s*ent\.begin(.*?)#\s*ent\.end', + '', content, flags=re.DOTALL) + content = re.sub( + r'#\s*comm\.begin(.*?)#\s*comm\.end', + '', content, flags=re.DOTALL) + with open(mkdocs_yml_path, 'w', encoding='utf-8') as f: + f.write(content) + +if __name__ == '__main__': + mkdocs_yml_path = 'mkdocs.yml' + with open(mkdocs_yml_path, 'r', encoding='utf-8') as f: + config = yaml.safe_load(f) + database_edition = config.get("extra", {}).get("database_edition", "both") + process_mkdocs_yml(mkdocs_yml_path, database_edition) \ No newline at end of file From ecc00343a78def4520aef940f481ff4ac740da70 Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Fri, 3 Feb 2023 11:55:30 +0800 Subject: [PATCH 2/3] Update conditional_render.py --- scripts/conditional_render.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/conditional_render.py b/scripts/conditional_render.py index 3791151f60b..31a22816b4c 100644 --- a/scripts/conditional_render.py +++ b/scripts/conditional_render.py @@ -1,7 +1,7 @@ # Rules for processing the markdown files in the docs-2.0 directory: # - If database_edition is enterprise, the content between {{ ent.ent_begin }} and {{ ent.ent_end }} is kept and the content between {{ comm.comm_begin }} and {{ comm.comm_end }} is removed. # - If database_edition is community, the content between {{ comm.comm_begin }} and {{ comm.comm_end }} is kept and the content between {{ ent.ent_begin }} and {{ ent.ent_end }} is removed. -# - If database_edition is both, both types of content are removed. +# - If database_edition is both, both types of content are kept. import os import re From 2dab16f9ac0830a41f0506657b8ceef3c7712e5b Mon Sep 17 00:00:00 2001 From: randomJoe211 <69501902+randomJoe211@users.noreply.github.com> Date: Fri, 3 Feb 2023 14:39:59 +0800 Subject: [PATCH 3/3] add value check --- scripts/conditional_render.py | 2 ++ scripts/conditional_yml.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/scripts/conditional_render.py b/scripts/conditional_render.py index 31a22816b4c..cf05f671d03 100644 --- a/scripts/conditional_render.py +++ b/scripts/conditional_render.py @@ -36,5 +36,7 @@ def process_files(file_path, database_edition): with open(mkdocs_yml_path, 'r', encoding='utf-8') as f: config = yaml.safe_load(f) database_edition = config.get("extra", {}).get("database_edition", "both") + if database_edition not in ['community', 'enterprise', 'both']: + raise ValueError("Invalid value for database_edition: {}".format(database_edition)) file_path = 'docs-2.0/' process_files(file_path, database_edition) \ No newline at end of file diff --git a/scripts/conditional_yml.py b/scripts/conditional_yml.py index dd2aa36851e..fa8cdf410e0 100644 --- a/scripts/conditional_yml.py +++ b/scripts/conditional_yml.py @@ -42,4 +42,6 @@ def process_mkdocs_yml(mkdocs_yml_path, database_edition): with open(mkdocs_yml_path, 'r', encoding='utf-8') as f: config = yaml.safe_load(f) database_edition = config.get("extra", {}).get("database_edition", "both") + if database_edition not in ['community', 'enterprise', 'both']: + raise ValueError("Invalid value for database_edition: {}".format(database_edition)) process_mkdocs_yml(mkdocs_yml_path, database_edition) \ No newline at end of file