-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: add conditional rendering #2547
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is \\1
?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
You could do more (if you want) Change the action file. If But currently, its OK. |
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):
database_edition
iscommunity
, keep all content between tags# ent.begin
and# ent.end
, and delete all content between tags# comm.begin
and# comm.end
.database_edition
isenterprise
, keep all content between# comm.begin
and# comm.end
, and delete all content between# ent.begin
and# ent.end
database_edition
isboth
, delete all content between# ent.begin
and# ent.end
, and between# comm.begin
and# comm.end
.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):
database_edition
isenterprise
, 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.{{ comm.comm_begin }}
and{{ comm.comm_end }}
is kept and the content between{{ ent.ent_begin }}
and{{ ent.ent_end }}
is removed.database_edition
isboth
, both types of content are kept.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 }}
.