#!/usr/bin/env python3 # # Copyright (C) 2026 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os import sys import http.server import socketserver from pathlib import Path try: import mistletoe from mistletoe.html_renderer import HTMLRenderer except ImportError: print("mistletoe is not installed. Please install it using `pip install mistletoe`.", file=sys.stderr) sys.exit(1) SCRIPT_DIR = Path(__file__).parent.resolve() ROOT_DIR = SCRIPT_DIR.parent.parent def find_examples_dir(): # search for filament.js in out/ out_dir = ROOT_DIR / 'out' if out_dir.exists(): for root, dirs, files in os.walk(out_dir): if 'filament.js' in files: return root return None examples_dir = find_examples_dir() if not examples_dir: print("Could not find the built examples directory in out/. Please build the webgl target first.", file=sys.stderr) # fallback to web/examples for testing, though it won't have the built assets examples_dir = str(SCRIPT_DIR) # Read template HTML_TEMPLATE = """
$BODY """ class CustomHandler(http.server.SimpleHTTPRequestHandler): def __init__(self, *args, **kwargs): super().__init__(*args, directory=examples_dir, **kwargs) def do_GET(self): # Serve main index if root if self.path == '/' or self.path == '/index.html': self.serve_index() return # If it's a markdown file, render it if self.path.endswith('.md'): self.serve_markdown() return # Otherwise serve normally super().do_GET() def serve_index(self): self.send_response(200) self.send_header('Content-type', 'text/html') self.end_headers() # Generate a list of all samples and tutorials html = ["