From 3f151f054d537b7b11b349fc373cab3198bc6066 Mon Sep 17 00:00:00 2001 From: Nikhil Rao Date: Mon, 17 Jul 2023 23:14:37 -0700 Subject: [PATCH] Generate sitemap on export (#1358) * Generate sitemap on export * Remove prints --- reflex/.templates/web/package.json | 3 ++- reflex/components/datadisplay/table.py | 4 ++-- reflex/components/feedback/alert.py | 6 +++--- reflex/utils/build.py | 20 +++++++++++++++++--- reflex/utils/console.py | 14 +++++++------- reflex/utils/prerequisites.py | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/reflex/.templates/web/package.json b/reflex/.templates/web/package.json index af26b82d6..80d466822 100644 --- a/reflex/.templates/web/package.json +++ b/reflex/.templates/web/package.json @@ -16,10 +16,10 @@ "focus-visible": "^5.2.0", "framer-motion": "^10.12.4", "gridjs": "^6.0.6", - "universal-cookie": "^4.0.4", "gridjs-react": "^6.0.1", "json5": "^2.2.3", "next": "^13.3.1", + "next-sitemap": "^4.1.8", "plotly.js": "^2.22.0", "react": "^18.2.0", "react-debounce-input": "^3.3.0", @@ -34,6 +34,7 @@ "remark-gfm": "^3.0.1", "remark-math": "^5.1.1", "socket.io-client": "^4.6.1", + "universal-cookie": "^4.0.4", "victory": "^36.6.8" }, "devDependencies": { diff --git a/reflex/components/datadisplay/table.py b/reflex/components/datadisplay/table.py index 30ca9f436..57a4c2356 100644 --- a/reflex/components/datadisplay/table.py +++ b/reflex/components/datadisplay/table.py @@ -148,8 +148,8 @@ class Tr(ChakraComponent): Args: children: The children of the component. props: The properties of the component. - cell_type (str): the type of cells in this table row. "header" or "data". Defaults to None. - cells (list, optional): The cells value to add in the table row. Defaults to None. + cell_type: the type of cells in this table row. "header" or "data". Defaults to None. + cells: The cells value to add in the table row. Defaults to None. Returns: The table row component diff --git a/reflex/components/feedback/alert.py b/reflex/components/feedback/alert.py index f4ebde16c..4c445720b 100644 --- a/reflex/components/feedback/alert.py +++ b/reflex/components/feedback/alert.py @@ -24,9 +24,9 @@ class Alert(ChakraComponent): Args: children: The children of the component. - icon (bool): The icon of the alert. - title (str): The title of the alert. - desc (str): The description of the alert + icon: The icon of the alert. + title: The title of the alert. + desc: The description of the alert props: The properties of the component. Returns: diff --git a/reflex/utils/build.py b/reflex/utils/build.py index a48f2e38c..bf36f858f 100644 --- a/reflex/utils/build.py +++ b/reflex/utils/build.py @@ -12,6 +12,7 @@ from typing import Optional, Union from rich.progress import MofNCompleteColumn, Progress, TimeElapsedColumn from reflex import constants +from reflex.config import get_config from reflex.utils import console, path_ops, prerequisites from reflex.utils.processes import new_process @@ -65,7 +66,7 @@ def set_os_env(**kwargs): os.environ[key.upper()] = value -def generate_sitemap(deploy_url: str): +def generate_sitemap_config(deploy_url: str): """Generate the sitemap config file. Args: @@ -85,6 +86,15 @@ def generate_sitemap(deploy_url: str): f.write(templates.SITEMAP_CONFIG(config=config)) +def generate_sitemap(): + """Generate the actual sitemap.""" + subprocess.run( + [prerequisites.get_package_manager(), "run", "next-sitemap"], + cwd=constants.WEB_DIR, + stdout=subprocess.PIPE, + ) + + def export_app( backend: bool = True, frontend: bool = True, @@ -106,7 +116,7 @@ def export_app( # Generate the sitemap file. if deploy_url is not None: - generate_sitemap(deploy_url) + generate_sitemap_config(deploy_url) # Create a progress object progress = Progress( @@ -158,6 +168,10 @@ def export_app( ) os._exit(1) + # Generate the actual sitemap. + if deploy_url is not None: + generate_sitemap() + # Zip up the app. if zip: if os.name == "posix": @@ -256,4 +270,4 @@ def setup_frontend_prod( disable_telemetry: Whether to disable the Next telemetry. """ setup_frontend(root, loglevel, disable_telemetry) - export_app(loglevel=loglevel) + export_app(loglevel=loglevel, deploy_url=get_config().deploy_url) diff --git a/reflex/utils/console.py b/reflex/utils/console.py index e2316fbd4..936990b6c 100644 --- a/reflex/utils/console.py +++ b/reflex/utils/console.py @@ -25,7 +25,7 @@ def log(msg: str) -> None: """Takes a string and logs it to the console. Args: - msg (str): The message to log. + msg: The message to log. """ _console.log(msg) @@ -34,7 +34,7 @@ def print(msg: str) -> None: """Prints the given message to the console. Args: - msg (str): The message to print to the console. + msg: The message to print to the console. """ _console.print(msg) @@ -43,7 +43,7 @@ def rule(title: str) -> None: """Prints a horizontal rule with a title. Args: - title (str): The title of the rule. + title: The title of the rule. """ _console.rule(title) @@ -55,9 +55,9 @@ def ask( and returns the user input. Args: - question (str): The question to ask the user. - choices (Optional[List[str]]): A list of choices to select from. - default(Optional[str]): The default option selected. + question: The question to ask the user. + choices: A list of choices to select from. + default: The default option selected. Returns: A string @@ -70,7 +70,7 @@ def status(msg: str) -> Status: which can be used as a context manager. Args: - msg (str): The message to be used as status title. + msg: The message to be used as status title. Returns: The status of the console. diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 0e4516101..218e0f8ff 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -309,7 +309,7 @@ def install_frontend_packages(web_dir: str): into the given web directory. Args: - web_dir (str): The directory where the frontend code is located. + web_dir: The directory where the frontend code is located. """ # Install the frontend packages. console.rule("[bold]Installing frontend packages")