Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional rendering #1935

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,21 @@ plugins:
- nebula-cloud/*
- nebula-cloud.md
# When publishing a version of a document that includes Enterprise Edition, annotation the following page
# begin
# - 3.ngql-guide/6.functions-and-expressions/17.ES-function.md
# - 4.deployment-and-installation/deploy-license.md
# - 5.configurations-and-logs/2.log-management/audit-log.md
# - 7.data-security/1.authentication/4.ldap.md
# - nebula-operator/8.custom-cluster-configurations/8.3.balance-data-when-scaling-storage.md
# - synchronization-and-migration/replication-between-clusters.md
# - 20.appendix/release-notes/nebula-ent-release-note.md
# - nebula-dashboard-ent/4.cluster-operator/operator/scale.md
# - backup-and-restore/nebula-br-ent/*
# - 6.monitor-and-metrics/3.bbox/*
# end
# ent.begin
- 3.ngql-guide/6.functions-and-expressions/17.ES-function.md
- 4.deployment-and-installation/deploy-license.md
- 5.configurations-and-logs/2.log-management/audit-log.md
- 7.data-security/1.authentication/4.ldap.md
- nebula-operator/8.custom-cluster-configurations/8.3.balance-data-when-scaling-storage.md
- synchronization-and-migration/replication-between-clusters.md
- 20.appendix/release-notes/nebula-ent-release-note.md
- nebula-dashboard-ent/4.cluster-operator/operator/scale.md
- backup-and-restore/nebula-br-ent/*
- 6.monitor-and-metrics/3.bbox/*
# ent.end

# comm.begin
# comm.end
# Exclude the file with the following file name.
# - abc.md
# Exclude files with regular expressions (regexes)
Expand Down Expand Up @@ -125,6 +128,11 @@ extra_javascript:
- https://www-cdn.nebula-graph.io/nebula-docs/nebula-docs.7e772ed81c779cacbefc.js

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: both

# Language selector.
alternate:
- name: 中文
Expand Down
6 changes: 5 additions & 1 deletion prepare.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ mkdocs-exclude
mkdocs-redirects
mkdocs-minify-plugin
Markdown==3.3.7
pyyaml
42 changes: 42 additions & 0 deletions scripts/conditional_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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 kept.

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")
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)
47 changes: 47 additions & 0 deletions scripts/conditional_yml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 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")
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)