def freeze(skip_build=False): if not skip_build: print(f"{' BUILDING ':=^90}") build_time = build_all() else: build_time = 0 print(f"\n{'Template build time:':<30} {build_time:>6.2f} secs") print("\n" + f"{' FREEZING ':=^90}") start = time.time() build_path = PROJECT_PATH / BASE_CONFIG["build_path"] backup = PROJECT_PATH / (build_path.name + ".bak") if build_path.exists(): log.info(f"{build_path.name} -> {backup.name}") build_path.rename(backup) try: log.info("Building files...") app.config["FREEZER_DESTINATION"] = build_path freezer.freeze() if backup.exists(): log.info(f"deleting {backup.name}") rmtree(str(backup)) end = time.time() return end - start, build_time except Exception as e: log.error(e) if build_path.exists(): log.info(f"deleting {build_path.name}") rmtree(str(build_path)) if backup.exists(): log.info(f"restoring {backup.name} -> {build_path.name}") backup.rename(build_path) return None
def get_root_page(): """A static URL generator for app.py::get_root_page. Yields ------- args: dict The arguments of app.py::get_page. """ for root_page_path in BASE_CONFIG["root_pages"].values(): log.info(f"Freezing root page: {root_page_path}.") yield {"file": root_page_path}
def get_page(): """A static URL generator for app.py::get_page. Yields ------dict The arguments of app.py::get_page. """ for page_url in get_all_context_pages(): log.info(f"Freezing page: {page_url}") url_split = page_url.split("/") context = url_split[0] if url_split[1] == "index.html": # For root pages, app.py::get_page will handle it # e.g., context/index.html page = "index.html" elif url_split[-1] == "index.html": # e.g., context/.../page/index.html -> page := .../page/ page = "/".join(url_split[1:][:-1]) + "/" else: # e.g., context/.../page -> page := ../page page = "/".join(url_split[1:]) yield {"context": context, "page": page}