Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

help-beta: Add support for relative links.

Shubham Padia8d4c2b7847e7
diff --git a/help-beta/astro.config.mjs b/help-beta/astro.config.mjs
index ebc1522aec5..33c04ac3039 100644
--- a/help-beta/astro.config.mjs
+++ b/help-beta/astro.config.mjs
@@ -45,6 +45,12 @@ export default defineConfig({
optional: true,
default: true,
}),
+ SHOW_BILLING_HELP_LINKS: envField.boolean({
+ context: "client",
+ access: "public",
+ optional: true,
+ default: true,
+ }),
},
},
integrations: [
diff --git a/help-beta/src/components/NavigationSteps.astro b/help-beta/src/components/NavigationSteps.astro
index ecd52ad7a54..6c5dc722fe9 100644
--- a/help-beta/src/components/NavigationSteps.astro
+++ b/help-beta/src/components/NavigationSteps.astro
@@ -1,6 +1,19 @@
---
-import { SHOW_RELATIVE_LINKS } from "astro:env/client";
+import { SHOW_RELATIVE_LINKS, SHOW_BILLING_HELP_LINKS } from "astro:env/client";
+import assert from "node:assert";
import RawZulipIconGear from "~icons/zulip-icon/gear?raw";
+import RawZulipIconHash from "~icons/zulip-icon/hash?raw";
+import RawZulipIconTool from "~icons/zulip-icon/tool?raw";
+import RawZulipIconBuilding from "~icons/zulip-icon/building?raw";
+import RawZulipIconUserGroupCog from "~icons/zulip-icon/user-group-cog?raw";
+import RawZulipIconBarChart from "~icons/zulip-icon/bar-chart?raw";
+import RawZulipIconGitPullRequest from "~icons/zulip-icon/git-pull-request?raw";
+import RawZulipIconRocket from "~icons/zulip-icon/rocket?raw";
+import RawZulipIconCreditCard from "~icons/zulip-icon/credit-card?raw";
+import RawZulipIconKeyboard from "~icons/zulip-icon/keyboard?raw";
+import RawZulipIconEdit from "~icons/zulip-icon/edit?raw";
+import RawZulipIconManageSearch from "~icons/zulip-icon/manage-search?raw";
+import RawZulipIconInfo from "~icons/zulip-icon/info?raw";
// This list has been transformed one-off from `help_settings_links.py`, we
// have added a comment in that file to update this list in case of any
@@ -138,6 +151,135 @@ const setting_link_mapping: {
}
};
+type RelativeLinkInfo = {
+ label: string;
+ relative_link: string;
+};
+
+const default_template_for_relative_links = `
+<ol>
+ <li>Click on the <strong>gear</strong> (${RawZulipIconGear}) icon in the upper right corner of the web or desktop app.</li>
+ <li>Select {item}.</li>
+</ol>
+`
+
+const relative_link_mapping: Record<
+ string,
+ {
+ data: Record<string, RelativeLinkInfo>;
+ template: string;
+ is_link_relative: () => boolean;
+ }
+> = {
+ gear: {
+ data: {
+ "channel-settings": {
+ label: `${RawZulipIconHash} Channel settings`,
+ relative_link: "/#channels/subscribed",
+ },
+ settings: {
+ label: `${RawZulipIconTool} Personal Settings`,
+ relative_link: "/#settings/profile",
+ },
+ "organization-settings": {
+ label: `${RawZulipIconBuilding} Organization settings`,
+ relative_link: "/#organization/organization-profile",
+ },
+ "group-settings": {
+ label: `${RawZulipIconUserGroupCog} Group settings`,
+ relative_link: "/#groups/your",
+ },
+ stats: {
+ label: `${RawZulipIconBarChart} Usage statistics`,
+ relative_link: "/stats",
+ },
+ integrations: {
+ label: `${RawZulipIconGitPullRequest} Integrations`,
+ relative_link: "/integrations/",
+ },
+ "about-zulip": {
+ label: "About Zulip",
+ relative_link: "/#about-zulip",
+ },
+ },
+ template: default_template_for_relative_links,
+ is_link_relative: () => SHOW_RELATIVE_LINKS,
+ },
+ "gear-billing": {
+ data: {
+ plans: {
+ label: `${RawZulipIconRocket} Plans and pricing`,
+ relative_link: "/plans/",
+ },
+ billing: {
+ label: `${RawZulipIconCreditCard} Billing`,
+ relative_link: "/billing/",
+ },
+ },
+ template: default_template_for_relative_links,
+ is_link_relative: () => SHOW_RELATIVE_LINKS && SHOW_BILLING_HELP_LINKS,
+ },
+ help: {
+ data: {
+ "keyboard-shortcuts": {
+ label: `${RawZulipIconKeyboard} Keyboard shortcuts`,
+ relative_link: "/#keyboard-shortcuts",
+ },
+ "message-formatting": {
+ label: `${RawZulipIconEdit} Message formatting`,
+ relative_link: "/#message-formatting",
+ },
+ "search-filters": {
+ label: `${RawZulipIconManageSearch} Search filters`,
+ relative_link: "/#search-operators",
+ },
+ "about-zulip": {
+ label: `${RawZulipIconInfo} About Zulip`,
+ relative_link: "/#about-zulip",
+ },
+ },
+ template: default_template_for_relative_links,
+ is_link_relative: () => SHOW_RELATIVE_LINKS,
+ },
+ channel: {
+ data: {
+ all: {
+ label: "All",
+ relative_link: "/#channels/all",
+ },
+ "not-subscribed": {
+ label: "Not subscribed",
+ relative_link: "/#channels/notsubscribed",
+ },
+ },
+ template: `
+<ol>
+ <li>Click on the <strong>gear</strong> (${RawZulipIconGear}) icon in the upper right corner of the web or desktop app.</li>
+ <li>Select ${RawZulipIconHash} <strong>Channel settings</strong>.</li>
+ <li>Click {item} in the upper left.</li>
+</ol>
+`,
+ is_link_relative: () => SHOW_RELATIVE_LINKS,
+ },
+ group: {
+ data: {
+ all: {
+ label: "All groups",
+ relative_link: "/#groups/all",
+ },
+ },
+ template: `
+<ol>
+ <li>Click on the <strong>gear</strong> (${RawZulipIconGear}) icon in the upper right corner of the web or desktop app.</li>
+ <li>Select ${RawZulipIconUserGroupCog} <strong>Group settings</strong>.</li>
+ <li>Click {item} in the upper left.</li>
+</ol>
+`,
+ is_link_relative: () => SHOW_RELATIVE_LINKS,
+ },
+};
+
+
const getSettingsMarkdown = (setting_type_name: string, setting_name: string) => `
<ol>
<li>
@@ -180,12 +322,34 @@ const getSettingsHTML = (
</ol>`;
}
+const LINK_TYPE_HANDLERS: Record<string, (key: string) => string> = {};
+
+for (const type in relative_link_mapping) {
+ const { data, template, is_link_relative } = relative_link_mapping[type]!;
+
+ LINK_TYPE_HANDLERS[type] = (key: string) => {
+ const { label, relative_link } = data[key]!;
+ const formattedItem = is_link_relative() ? `<a href="${relative_link}">${label}</a>` : `<strong>${label}</strong>`;
+ return template.replace("{item}", formattedItem);
+ };
+}
+
const { identifier } = Astro.props;
const navigation_link_type = identifier.split("/")[0];
-if (navigation_link_type !== "settings") {
- throw new Error("Invalid navigation link type. Only `settings` is allowed.");
+
+if (navigation_link_type !== "settings" && navigation_link_type !== "relative" ) {
+ throw new Error("Invalid navigation link type. Only `settings` or `relative` is allowed.");
+}
+
+let resultHTML: string | undefined;
+if (navigation_link_type === "settings") {
+ resultHTML = getSettingsHTML(identifier.split("/")[1], SHOW_RELATIVE_LINKS);
+} else {
+ const link_type = identifier.split("/")[1];
+ const key = identifier.split("/")[2];
+ resultHTML = LINK_TYPE_HANDLERS[link_type]!(key);
}
-const resultHTML = getSettingsHTML(identifier.split("/")[1], SHOW_RELATIVE_LINKS);
+assert(resultHTML !== undefined);
---
<Fragment set:html={resultHTML} />
diff --git a/tools/build-help-center b/tools/build-help-center
index 747f5540df2..b076c95a666 100755
--- a/tools/build-help-center
+++ b/tools/build-help-center
@@ -16,12 +16,18 @@ os.environ["DJANGO_SETTINGS_MODULE"] = "zproject.settings"
import django
django.setup()
+from django.conf import settings
def run() -> None:
subprocess.check_call(["./tools/convert-help-center-docs-to-mdx"], stderr=subprocess.STDOUT)
+ env = os.environ.copy()
+ env["SHOW_BILLING_HELP_LINKS"] = str(settings.CORPORATE_ENABLED).lower()
subprocess.check_call(
- ["/usr/local/bin/corepack", "pnpm", "build"], stderr=subprocess.STDOUT, cwd="help-beta"
+ ["/usr/local/bin/corepack", "pnpm", "build"],
+ stderr=subprocess.STDOUT,
+ cwd="help-beta",
+ env=env,
)
diff --git a/tools/convert-help-center-docs-to-mdx b/tools/convert-help-center-docs-to-mdx
index a7f2723b7a7..abbfd67f38b 100755
--- a/tools/convert-help-center-docs-to-mdx
+++ b/tools/convert-help-center-docs-to-mdx
@@ -26,6 +26,7 @@ from zerver.lib.markdown.tabbed_sections import generate_content_blocks, parse_t
INDENT_SPACES = " "
SETTINGS_LINK_PATTERN = re.compile(r"{settings_tab\|(?P<setting_identifier>.*?)}")
+RELATIVE_LINKS_PATTERN = re.compile(r"\{relative\|(?P<link_type>.*?)\|(?P<key>.*?)\}")
# TODO list before cutover.
#
@@ -85,6 +86,20 @@ def replace_setting_links(
return setting_links_pattern.sub(replace_setting_links_match, markdown_string)
+def replace_relative_links(
+ markdown_string: str, import_statement_set: set[str], import_relative_base_path: str
+) -> str:
+ def replace_relative_links_match(match: re.Match[str]) -> str:
+ import_statement_set.add(
+ f'import NavigationSteps from "{import_relative_base_path}/NavigationSteps.astro"'
+ )
+ link_type = match.group("link_type")
+ key = match.group("key")
+ return f'<NavigationSteps identifier="relative/{link_type}/{key}" />'
+
+ return RELATIVE_LINKS_PATTERN.sub(replace_relative_links_match, markdown_string)
+
+
def replace_image_path(markdown_string: str, replacement_path: str) -> str:
"""
We will point to the existing image folder till
@@ -338,7 +353,8 @@ def insert_flattened_steps_component(
index += step
continue
settings_link_match = SETTINGS_LINK_PATTERN.match(line)
- if settings_link_match:
+ relative_links_match = RELATIVE_LINKS_PATTERN.match(line)
+ if settings_link_match or relative_links_match:
index += step
continue
break
@@ -363,6 +379,9 @@ def insert_flattened_steps_component(
for match in SETTINGS_LINK_PATTERN.finditer(markdown_string):
insert_flatten_list(match)
+ for match in RELATIVE_LINKS_PATTERN.finditer(markdown_string):
+ insert_flatten_list(match)
+
for match in file_include_pattern.finditer(markdown_string):
filename = match.group(1)
if not include_files_info[filename]["is_only_ordered_list"]:
@@ -519,6 +538,7 @@ def convert_help_center_file_to_mdx(
result = convert_admonitions_to_asides(result, import_statement_set, "../../components")
result = convert_tab_syntax(result, import_statement_set)
result = replace_setting_links(result, import_statement_set, "../../components")
+ result = replace_relative_links(result, import_statement_set, "../../components")
result = escape_curly_braces(result)
result = replace_emoticon_translation_table(result, import_statement_set)
result = replace_image_path(result, "../../../../static/images/help")
@@ -556,6 +576,7 @@ def convert_include_file_to_mdx(
result = convert_admonitions_to_asides(result, import_statement_set, "../../../components")
result = convert_tab_syntax(result, import_statement_set)
result = replace_setting_links(result, import_statement_set, "../../../components")
+ result = replace_relative_links(result, import_statement_set, "../../../components")
result = escape_curly_braces(result)
result = replace_image_path(result, "../../../../../static/images/help")
result = replace_icons(result, import_statement_set)