diff --git a/bin/check-review-dates.py b/bin/check-review-dates.py index b79dfc50d8..092566ece1 100644 --- a/bin/check-review-dates.py +++ b/bin/check-review-dates.py @@ -2,7 +2,8 @@ import logging from slack_sdk import WebClient from datetime import timedelta, date, datetime -import json +import re +import ast DEFAULT_VAL_FREQ = 6 FILEPATH = "./" ## for local testing use "../" and shift filepath_list[] indexes +1 @@ -22,18 +23,53 @@ def get_prod_cat_ref(): product_categories = {} - # Load the menu file - with open(FILEPATH + 'menu/navigation.json', 'r') as file: - data = json.load(file) # Parse the JSON content into a Python dictionary or list - - for grouping in data: - for category in grouping["items"]: - category_label = category["label"] - for product in category["items"]: - product_label = product["label"] - product_slug = product["slug"] - - product_categories[product_slug] = [category_label, product_label] + # Read the menu file + with open(FILEPATH + "menu/navigation.ts", "r", encoding="utf-8") as f: + js = f.read() + + # remove all lines up to "export default" + js = re.sub(r"^import .*", "", js, flags=re.M) # remove import lines + js = re.sub(r"//.*", "", js) # strip line comments + js = re.sub(r"/\*.*?\*/", "", js, flags=re.S) # strip block comments + js = js.replace("export default", "").strip() # strip "export default" and cleanup + + # Convert items - [accountMenu, billingMenu] → ['account', 'billing'] + js = re.sub(r"\b([a-zA-Z0-9_]+)Menu\b(?!')", r"'\1'", js) + + # Convert icons - OrganizationDashboardCategoryIcon → 'OrganizationDashboardCategory' + js = re.sub(r"\b([A-Z][A-Za-z0-9]+)Icon\b(?!')", r"'\1'", js) + + # Normalize JS → Python syntax --- + js = re.sub(r"(\w+):", r"'\1':", js) # quote keys + js = js.replace("null", "None") # replace nulls with Nones + js = re.sub(r",(\s*[}\]])", r"\1", js) # remove trailing commas + + # Convert the js string now containing Python literal syntax, into an actual Python object. + data = ast.literal_eval(js) + + # Helper function + def camel_to_kebab(name: str) -> str: + """Convert camelCase or PascalCase to kebab-case.""" + s1 = re.sub('(.)([A-Z][a-z]+)', r'\1-\2', name) + s2 = re.sub('([a-z0-9])([A-Z])', r'\1-\2', s1) + return s2.lower() + + # Helper function + def prettify_label(slug: str) -> str: + """Convert kebab-case to title case.""" + return slug.replace("-", " ").title() + + # Walk structure and make new dict + + product_categories = {} + + for section in data: + for category in section["items"]: + category_label = category["label"] + for item in category["items"]: + key = camel_to_kebab(item).lower().replace("_", "-") + label = prettify_label(key) + product_categories[key] = [category_label, label] return(product_categories) diff --git a/menu/navigation.ts b/menu/navigation.ts index 86b85c2797..76388d4d54 100644 --- a/menu/navigation.ts +++ b/menu/navigation.ts @@ -51,7 +51,7 @@ import { partnerSpaceMenu } from "../pages/partner-space/menu" import { publicGatewaysMenu } from "../pages/public-gateways/menu" import { queuesMenu } from "../pages/queues/menu" import { scalewayCliMenu } from "../pages/scaleway-cli/menu" -import { scalewySdkMenu } from "../pages/scaleway-sdk/menu" +import { scalewaySdkMenu } from "../pages/scaleway-sdk/menu" import { secretManagerMenu } from "../pages/secret-manager/menu" import { serverlessContainersMenu } from "../pages/serverless-containers/menu" import { serverlessFunctionsMenu } from "../pages/serverless-functions/menu" @@ -61,7 +61,7 @@ import { terraformMenu } from "../pages/terraform/menu" import { topicsAndEventsMenu } from "../pages/topics-and-events/menu" import { transactionalEmailMenu } from "../pages/transactional-email/menu" import { vpcMenu } from "../pages/vpc/menu" -import { webHostingMenu } from "../pages/webhosting/menu" +import { webhostingMenu } from "../pages/webhosting/menu" export default [ { @@ -162,7 +162,7 @@ export default [ icon: 'DevToolsCategoryIcon', items: [ scalewayCliMenu, - scalewySdkMenu, + scalewaySdkMenu, terraformMenu, ], label: 'Developer Tools', @@ -173,7 +173,7 @@ export default [ items: [ domainsAndDnsMenu, transactionalEmailMenu, - webHostingMenu, + webhostingMenu, ], label: 'Domains & Web Hosting', category: 'domains-and-web-hosting', diff --git a/pages/scaleway-sdk/menu.ts b/pages/scaleway-sdk/menu.ts index 11d53c9f35..02e34eaed4 100644 --- a/pages/scaleway-sdk/menu.ts +++ b/pages/scaleway-sdk/menu.ts @@ -1,4 +1,4 @@ -export const scalewySdkMenu = { +export const scalewaySdkMenu = { items: [ { label: 'Python SDK quickstart', diff --git a/pages/webhosting/menu.ts b/pages/webhosting/menu.ts index dd83f6d68c..69d9bbbfd3 100644 --- a/pages/webhosting/menu.ts +++ b/pages/webhosting/menu.ts @@ -1,4 +1,4 @@ -export const webHostingMenu = { +export const webhostingMenu = { items: [ { label: 'Overview',