diff --git a/conf.py b/conf.py index 55152f5e..10ae3fbd 100644 --- a/conf.py +++ b/conf.py @@ -102,20 +102,55 @@ def build_served_html(): from pathlib import Path os.chdir(Path(__file__).parent) - versions = [ + + # Create .htaccess to serve schemas inline (not download) + os.makedirs("_html_extra", exist_ok=True) + htaccess_content = """ + Header set Content-Disposition "inline" + +""" + with open("_html_extra/.htaccess", "w") as f: + f.write(htaccess_content) + print(f"✅ Created .htaccess to serve schemas inline") + + # Fetch GitHub tags and download schemas + try: + result = subprocess.check_output([ + "git", "ls-remote", "--tags", "https://github.com/ome/ngff-spec" + ], text=True, timeout=10) + tags = [line.split()[1].replace("refs/tags/", "").rstrip("^{}") for line in result.strip().split("\n") if line] + for tag in sorted(set(tags)): + schema_dir = f"_html_extra/{tag}/schemas" + os.makedirs(schema_dir, exist_ok=True) + # Download schemas from GitHub raw for this tag + gh_url = f"https://github.com/ome/ngff-spec/archive/refs/tags/{tag}.tar.gz" + try: + import tempfile, tarfile + with tempfile.NamedTemporaryFile(delete=False) as tmp: + subprocess.check_call(["curl", "-sL", gh_url, "-o", tmp.name]) + with tarfile.open(tmp.name) as tar: + for member in tar.getmembers(): + if "/schemas/" in member.name and member.name.endswith(".schema"): + # Extract just the filename, flatten into schema_dir + target = os.path.join(schema_dir, os.path.basename(member.name)) + tar.extract(member, path=tempfile.gettempdir()) + src = os.path.join(tempfile.gettempdir(), member.name) + shutil.copy2(src, target) + os.unlink(tmp.name) + print(f"✅ Downloaded schemas for {tag}") + except Exception as e: + print(f"⚠️ Could not download schemas for {tag}: {e}") + except Exception: + pass + + # Build specifications from local submodules + displayed_spec_versions = [ d for d in os.listdir("specifications") if os.path.isdir(os.path.join("specifications", d)) ] - for version in versions: - - # copy schemas to _html_extra - os.makedirs(f"_html_extra/{version}/schemas", exist_ok=True) - schemas = glob.glob(f"specifications/{version}/**/*.schema", recursive=True) - for schema in schemas: - shutil.copy2(schema, f"_html_extra/{version}/schemas/") - print(f"✅ Copied schemas for version {version}") + for version in displayed_spec_versions: # find 'pre_build.py' in 'specifications' subdirectories script = glob.glob(f"specifications/{version}/**/pre_build.py", recursive=True)[