Generate app sitemap (#552)
This commit is contained in:
parent
7fa1a85d91
commit
d72256d427
Binary file not shown.
@ -2,7 +2,7 @@
|
|||||||
"name": "pynecone",
|
"name": "pynecone",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"export": "next build && next export -o _static",
|
"export": "next build && next-sitemap && next export -o _static",
|
||||||
"prod": "next start"
|
"prod": "next start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -17,6 +17,7 @@
|
|||||||
"gridjs": "^4.0.0",
|
"gridjs": "^4.0.0",
|
||||||
"gridjs-react": "^4.0.0",
|
"gridjs-react": "^4.0.0",
|
||||||
"next": "^12.1.0",
|
"next": "^12.1.0",
|
||||||
|
"next-sitemap": "^3.1.52",
|
||||||
"plotly.js": "2.6.4",
|
"plotly.js": "2.6.4",
|
||||||
"prettier": "^2.8.1",
|
"prettier": "^2.8.1",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
|
@ -193,3 +193,6 @@ SOCKET = "const socket = useRef(null)"
|
|||||||
|
|
||||||
# Color toggle
|
# Color toggle
|
||||||
COLORTOGGLE = f"const {{ {constants.COLOR_MODE}, {constants.TOGGLE_COLOR_MODE} }} = {constants.USE_COLOR_MODE}()"
|
COLORTOGGLE = f"const {{ {constants.COLOR_MODE}, {constants.TOGGLE_COLOR_MODE} }} = {constants.USE_COLOR_MODE}()"
|
||||||
|
|
||||||
|
# Sitemap config file.
|
||||||
|
SITEMAP_CONFIG = "module.exports = {config}".format
|
||||||
|
@ -21,6 +21,9 @@ class Config(Base):
|
|||||||
# The backend API url.
|
# The backend API url.
|
||||||
api_url: str = constants.API_URL
|
api_url: str = constants.API_URL
|
||||||
|
|
||||||
|
# The deploy url.
|
||||||
|
deploy_url: Optional[str] = None
|
||||||
|
|
||||||
# The database url.
|
# The database url.
|
||||||
db_url: Optional[str] = constants.DB_URL
|
db_url: Optional[str] = constants.DB_URL
|
||||||
|
|
||||||
@ -30,8 +33,8 @@ class Config(Base):
|
|||||||
# Telemetry opt-in.
|
# Telemetry opt-in.
|
||||||
telemetry_enabled: bool = True
|
telemetry_enabled: bool = True
|
||||||
|
|
||||||
# The deploy url.
|
# The pcdeploy url.
|
||||||
deploy_url: Optional[str] = None
|
pcdeploy_url: Optional[str] = None
|
||||||
|
|
||||||
# The environment mode.
|
# The environment mode.
|
||||||
env: constants.Env = constants.Env.DEV
|
env: constants.Env = constants.Env.DEV
|
||||||
|
@ -50,6 +50,8 @@ WEB_STATIC_DIR = os.path.join(WEB_DIR, "_static")
|
|||||||
WEB_UTILS_DIR = os.path.join(WEB_DIR, UTILS_DIR)
|
WEB_UTILS_DIR = os.path.join(WEB_DIR, UTILS_DIR)
|
||||||
# The directory where the assets are located.
|
# The directory where the assets are located.
|
||||||
WEB_ASSETS_DIR = os.path.join(WEB_DIR, "public")
|
WEB_ASSETS_DIR = os.path.join(WEB_DIR, "public")
|
||||||
|
# The sitemap config file.
|
||||||
|
SITEMAP_CONFIG_FILE = os.path.join(WEB_DIR, "next-sitemap.config.js")
|
||||||
# The node modules directory.
|
# The node modules directory.
|
||||||
NODE_MODULES = "node_modules"
|
NODE_MODULES = "node_modules"
|
||||||
# The package lock file.
|
# The package lock file.
|
||||||
|
@ -129,14 +129,14 @@ def deploy(dry_run: bool = typer.Option(False, help="Whether to run a dry run.")
|
|||||||
config.api_url = utils.get_production_backend_url()
|
config.api_url = utils.get_production_backend_url()
|
||||||
|
|
||||||
# Check if the deploy url is set.
|
# Check if the deploy url is set.
|
||||||
if config.deploy_url is None:
|
if config.pcdeploy_url is None:
|
||||||
typer.echo("This feature is coming soon!")
|
typer.echo("This feature is coming soon!")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Compile the app in production mode.
|
# Compile the app in production mode.
|
||||||
typer.echo("Compiling production app")
|
typer.echo("Compiling production app")
|
||||||
app = utils.get_app().app
|
app = utils.get_app().app
|
||||||
utils.export_app(app, zip=True)
|
utils.export_app(app, zip=True, deploy_url=config.deploy_url)
|
||||||
|
|
||||||
# Exit early if this is a dry run.
|
# Exit early if this is a dry run.
|
||||||
if dry_run:
|
if dry_run:
|
||||||
@ -144,7 +144,7 @@ def deploy(dry_run: bool = typer.Option(False, help="Whether to run a dry run.")
|
|||||||
|
|
||||||
# Deploy the app.
|
# Deploy the app.
|
||||||
data = {"userId": config.username, "projectId": config.app_name}
|
data = {"userId": config.username, "projectId": config.app_name}
|
||||||
original_response = httpx.get(config.deploy_url, params=data)
|
original_response = httpx.get(config.pcdeploy_url, params=data)
|
||||||
response = original_response.json()
|
response = original_response.json()
|
||||||
frontend = response["frontend_resources_url"]
|
frontend = response["frontend_resources_url"]
|
||||||
backend = response["backend_resources_url"]
|
backend = response["backend_resources_url"]
|
||||||
@ -175,15 +175,22 @@ def export(
|
|||||||
),
|
),
|
||||||
):
|
):
|
||||||
"""Export the app to a zip file."""
|
"""Export the app to a zip file."""
|
||||||
|
config = utils.get_config()
|
||||||
|
|
||||||
if for_pc_deploy:
|
if for_pc_deploy:
|
||||||
# Get the app config and modify the api_url base on username and app_name.
|
# Get the app config and modify the api_url base on username and app_name.
|
||||||
config = utils.get_config()
|
|
||||||
config.api_url = utils.get_production_backend_url()
|
config.api_url = utils.get_production_backend_url()
|
||||||
|
|
||||||
# Compile the app in production mode and export it.
|
# Compile the app in production mode and export it.
|
||||||
utils.console.rule("[bold]Compiling production app and preparing for export.")
|
utils.console.rule("[bold]Compiling production app and preparing for export.")
|
||||||
app = utils.get_app().app
|
app = utils.get_app().app
|
||||||
utils.export_app(app, backend=backend, frontend=frontend, zip=zipping)
|
utils.export_app(
|
||||||
|
app,
|
||||||
|
backend=backend,
|
||||||
|
frontend=frontend,
|
||||||
|
zip=zipping,
|
||||||
|
deploy_url=config.deploy_url,
|
||||||
|
)
|
||||||
|
|
||||||
# Post a telemetry event.
|
# Post a telemetry event.
|
||||||
pynecone_telemetry("export", utils.get_config().telemetry_enabled)
|
pynecone_telemetry("export", utils.get_config().telemetry_enabled)
|
||||||
|
@ -493,8 +493,32 @@ def set_pynecone_project_hash():
|
|||||||
json.dump(pynecone_json, f, ensure_ascii=False)
|
json.dump(pynecone_json, f, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_sitemap(deploy_url: str):
|
||||||
|
"""Generate the sitemap config file.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
deploy_url: The URL of the deployed app.
|
||||||
|
"""
|
||||||
|
# Import here to avoid circular imports.
|
||||||
|
from pynecone.compiler import templates
|
||||||
|
|
||||||
|
config = json.dumps(
|
||||||
|
{
|
||||||
|
"siteUrl": deploy_url,
|
||||||
|
"generateRobotsTxt": True,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(constants.SITEMAP_CONFIG_FILE, "w") as f:
|
||||||
|
f.write(templates.SITEMAP_CONFIG(config=config))
|
||||||
|
|
||||||
|
|
||||||
def export_app(
|
def export_app(
|
||||||
app: App, backend: bool = True, frontend: bool = True, zip: bool = False
|
app: App,
|
||||||
|
backend: bool = True,
|
||||||
|
frontend: bool = True,
|
||||||
|
zip: bool = False,
|
||||||
|
deploy_url: Optional[str] = None,
|
||||||
):
|
):
|
||||||
"""Zip up the app for deployment.
|
"""Zip up the app for deployment.
|
||||||
|
|
||||||
@ -503,6 +527,7 @@ def export_app(
|
|||||||
backend: Whether to zip up the backend app.
|
backend: Whether to zip up the backend app.
|
||||||
frontend: Whether to zip up the frontend app.
|
frontend: Whether to zip up the frontend app.
|
||||||
zip: Whether to zip the app.
|
zip: Whether to zip the app.
|
||||||
|
deploy_url: The URL of the deployed app.
|
||||||
"""
|
"""
|
||||||
# Force compile the app.
|
# Force compile the app.
|
||||||
app.compile(force_compile=True)
|
app.compile(force_compile=True)
|
||||||
@ -510,6 +535,10 @@ def export_app(
|
|||||||
# Remove the static folder.
|
# Remove the static folder.
|
||||||
rm(constants.WEB_STATIC_DIR)
|
rm(constants.WEB_STATIC_DIR)
|
||||||
|
|
||||||
|
# Generate the sitemap file.
|
||||||
|
if deploy_url is not None:
|
||||||
|
generate_sitemap(deploy_url)
|
||||||
|
|
||||||
# Export the Next app.
|
# Export the Next app.
|
||||||
subprocess.run([get_package_manager(), "run", "export"], cwd=constants.WEB_DIR)
|
subprocess.run([get_package_manager(), "run", "export"], cwd=constants.WEB_DIR)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "pynecone"
|
name = "pynecone"
|
||||||
version = "0.1.14"
|
version = "0.1.16"
|
||||||
description = "Web apps in pure Python."
|
description = "Web apps in pure Python."
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
authors = [
|
authors = [
|
||||||
|
Loading…
Reference in New Issue
Block a user