Skip to content

Commit

Permalink
fix: rewrite contents_helper for compatibility with CMS (#338)
Browse files Browse the repository at this point in the history
* rewrite contents_helper for compatibility with CMS

* formatting
  • Loading branch information
joepercival authored Jul 8, 2024
1 parent ba3f6d6 commit ed5ce23
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
6 changes: 5 additions & 1 deletion sml_builder/api_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ def api_guidances(category, sub_category=None):
mkdocs = get_feature_config("docs_integration")
if mkdocs["enabled"] is True:
try:
with open(
"./content/api_reference/api_reference.json", encoding="utf-8"
) as help_contents_file:
contents = load(help_contents_file)
category_label, sub_category_label, sub_category = category_labels(
"./content/api_reference/api_reference.json", category, sub_category
contents, category, sub_category
)
except Exception as e: # pylint: disable=broad-except
_page_not_found(e)
Expand Down
23 changes: 17 additions & 6 deletions sml_builder/help_centre.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def help_centre(category=None):
@app.route("/help-centre/<category>/index")
@app.route("/help-centre/<category>/<sub_category>")
def guidances(category, sub_category=None):
try:
category_label, sub_category_label, sub_category = category_labels(
"./content/help_centre/help_centre.json", category, sub_category
)
except Exception as e: # pylint: disable=broad-except
_page_not_found(e)
help_centre_nav = _help_centre_nav(category)

if content_management["enabled"]:
contents = getContent("helpCentreStructure")["structure"]
if checkEmptyList(contents):
_page_not_found("helpCentreStructure content not found")
category_label, sub_category_label, sub_category = category_labels(
contents, category, sub_category
)
if sub_category == "methods-request":
content = getContent("helpCentreMethodRequest")
if checkEmptyList(content):
Expand Down Expand Up @@ -97,6 +97,17 @@ def guidances(category, sub_category=None):
cms_enabled=content_management["enabled"],
)

try:
with open(
"./content/help_centre/help_centre.json", encoding="utf-8"
) as help_contents_file:
contents = load(help_contents_file)
category_label, sub_category_label, sub_category = category_labels(
contents, category, sub_category
)
except Exception as e: # pylint: disable=broad-except
_page_not_found(e)

if sub_category not in externallink_help_categories:
try:
with open(
Expand Down
4 changes: 1 addition & 3 deletions sml_builder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ def get_feature_config(feature_name: str):
raise KeyError(f"Feature '{feature_name}' not found in features.") from e


def category_labels(file_path, selected_category, selected_sub_category):
with open(file_path, encoding="utf-8") as help_contents_file:
contents = load(help_contents_file)
def category_labels(contents, selected_category, selected_sub_category):
for category in contents["categories"]:
if category["name"] == selected_category:
category_label = category["label"]
Expand Down

0 comments on commit ed5ce23

Please sign in to comment.