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

feat: add conditional rendering #2547

Merged

Conversation

randomJoe211
Copy link
Contributor

Render content according to the database_edition in mkdocs.yml.
Added two scripts to process markdown files and the mkdocs.yml separately.

Rules for processing the mkdocs.yml file (here keeping something means hiding it with the exclude plugin, while deleting something means releasing it):

  • 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.

Rules for processing the markdown files in the docs-2.0 directory (here deleting something means don't show it, and keeping means show it):

  • 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.
  • Deletes all the tags once the script is run.

The scripts are run in the prepare.sh script before building the docs.

REMEMBER: Write enterprise-only content between {{ ent.ent_begin }} and {{ ent.ent_end }} in markdown files, and community-only content between {{ comm.comm_begin }} and {{ comm.comm_end }}.

whitewum
whitewum previously approved these changes Feb 3, 2023
Copy link
Contributor

@whitewum whitewum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work

if database_edition == 'enterprise':
content = re.sub(
r'{{\s*ent\.ent_begin\s*}}(.*?){{\s*ent\.ent_end\s*}}',
'\\1', content, flags=re.DOTALL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is \\1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \\1 in the replacement string refers to the first captured group in the regular expression pattern. In this script, the first captured group is defined using parentheses in the pattern, and it matches the content between the conditional tags.

So, when re.sub is called, it will replace the entire match (i.e., the entire conditional tag and its contents) with just the contents of the first captured group. This effectively removes the tags and only keeps the content between them.

'', content, flags=re.DOTALL)
content = re.sub(
r'#\s*comm\.begin(.*?)#\s*comm\.end',
'', content, flags=re.DOTALL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise, you can raise an error if someone inputs other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@whitewum
Copy link
Contributor

whitewum commented Feb 3, 2023

You could do more (if you want)

Change the action file. If database_version == all is set, you can run the build process twice to make two separate packages.

But currently, its OK.

@cooper-lzy cooper-lzy merged commit 2a45226 into vesoft-inc:master Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants