From 3df60b4ac8c2fc127751b12434c02676eecf1dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Brand=C3=A9ho?= Date: Fri, 26 May 2023 20:49:11 +0200 Subject: [PATCH] add asset_path method (#1089) --- pynecone/__init__.py | 1 + pynecone/compiler/utils.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pynecone/__init__.py b/pynecone/__init__.py index 0e6d655b3..3bc97f122 100644 --- a/pynecone/__init__.py +++ b/pynecone/__init__.py @@ -9,6 +9,7 @@ from . import el as el from .app import App as App from .app import UploadFile as UploadFile from .base import Base as Base +from .compiler.utils import get_asset_path from .components import * from .components.component import custom_component as memo from .components.graphing.victory import data as data diff --git a/pynecone/compiler/utils.py b/pynecone/compiler/utils.py index 2c9671c50..79f8c83a3 100644 --- a/pynecone/compiler/utils.py +++ b/pynecone/compiler/utils.py @@ -222,6 +222,21 @@ def get_components_path() -> str: return os.path.join(constants.WEB_UTILS_DIR, "components" + constants.JS_EXT) +def get_asset_path(filename: Optional[str] = None) -> str: + """Get the path for an asset. + + Args: + filename: Optional, if given, is added to the root path of assets dir. + + Returns: + The path of the asset. + """ + if filename is None: + return constants.WEB_ASSETS_DIR + else: + return os.path.join(constants.WEB_ASSETS_DIR, filename) + + def add_meta( page: Component, title: str, image: str, description: str, meta: List[Dict] ) -> Component: