import os from subprocess import run from pathlib import Path ON_CF = os.getenv("CF_PAGES") == "1" def get_env_info() -> dict[str, str]: # 读取环境变量 env_info = {} # git branch # if on cf, read it from env: CF_PAGES_BRANCH if ON_CF: branch = os.getenv("CF_PAGES_BRANCH") or "unknown" else: branch = run( ["git", "branch", "--show-current"], capture_output=True, text=True, encoding="utf-8", ).stdout env_info["branch"] = branch.strip() # git commit hash # on cf -> get from CF_PAGES_COMMIT_SHA if ON_CF: commit = os.getenv("CF_PAGES_COMMIT_SHA") or "unknown" else: commit = run( ["git", "rev-parse", "HEAD"], capture_output=True, text=True, encoding="utf-8", ).stdout env_info["commit"] = commit.strip() # git commit message message = run( ["git", "log", "-1", "--pretty=%B"], capture_output=True, text=True, encoding="utf-8", ) env_info["message"] = message.stdout.strip() # git tag if ON_CF: tag = os.getenv("CF_PAGES_COMMIT_TAG") or "cf_deploy" else: tag = run( ["git", "describe", "--tags"], capture_output=True, text=True, encoding="utf-8" ).stdout env_info["tag"] = tag.strip() return env_info if __name__ == "__main__": # 虽然但是, 我还是决定用 python 写这个脚本 border_raw = "/* border: 2px solid marker_color */" border_template = "border: 2px solid {};" marker_raw = '
' marker_template = '