diff --git a/docs/mkdocs/hooks/generate_examples.py b/docs/mkdocs/hooks/generate_examples.py index b4c928936..81f2bac24 100644 --- a/docs/mkdocs/hooks/generate_examples.py +++ b/docs/mkdocs/hooks/generate_examples.py @@ -16,6 +16,7 @@ ROOT_DIR_RELATIVE = "../../../../.." EXAMPLE_DIR = ROOT_DIR / "examples" EXAMPLE_DOC_DIR = ROOT_DIR / "docs/user_guide/examples" NAV_FILE = ROOT_DIR / "docs/.nav.yml" +MAX_INLINE_MATERIAL_SIZE = 8 * 1024 def fix_case(text: str) -> str: @@ -191,18 +192,21 @@ class Example: return re.sub(link_pattern, replace_link, content) + def github_url(self, path: Path) -> str: + url = "https://github.com/vllm-project/vllm-omni/" + url += "tree/main" if path.is_dir() else "blob/main" + return f"{url}/{path.relative_to(ROOT_DIR).as_posix()}" + def generate(self) -> str: content = f"# {self.title}\n\n" - url = "https://github.com/vllm-project/vllm-omni/" - url += "tree/main" if self.path.is_dir() else "blob/main" - content += f"Source <{url}/{self.path.relative_to(ROOT_DIR)}>.\n\n" + content += f"Source <{self.github_url(self.path)}>.\n\n" # Use long code fence to avoid issues with # included files containing code fences too code_fence = "``````" if self.is_code: - main_file_rel = self.main_file.relative_to(ROOT_DIR) + main_file_rel = self.main_file.relative_to(ROOT_DIR).as_posix() content += f'{code_fence}{self.main_file.suffix[1:]}\n--8<-- "{main_file_rel}"\n{code_fence}\n' else: with open(self.main_file, encoding="utf-8") as f: @@ -216,10 +220,15 @@ class Example: content += "## Example materials\n\n" for file in sorted(self.other_files): - content += f'??? abstract "{file.relative_to(self.path)}"\n' + content += f'??? abstract "{file.relative_to(self.path).as_posix()}"\n' + if file.stat().st_size > MAX_INLINE_MATERIAL_SIZE: + content += ( + f" Large file omitted from the rendered docs. View it on GitHub: <{self.github_url(file)}>.\n\n" + ) + continue if file.suffix != ".md": content += f" {code_fence}{file.suffix[1:]}\n" - content += f' --8<-- "{file.relative_to(ROOT_DIR)}"\n' + content += f' --8<-- "{file.relative_to(ROOT_DIR).as_posix()}"\n' if file.suffix != ".md": content += f" {code_fence}\n" @@ -291,7 +300,7 @@ def update_nav_file(examples: list[Example]): for example in category_examples: doc_path = EXAMPLE_DOC_DIR / example.category / f"{example.path.stem}.md" rel_path = doc_path.relative_to(ROOT_DIR / "docs") - category_items.append({example.title: str(rel_path)}) + category_items.append({example.title: rel_path.as_posix()}) if category_items: # Format category name (e.g., "offline_inference" -> "Offline Inference") diff --git a/docs/mkdocs/hooks/search_index.py b/docs/mkdocs/hooks/search_index.py new file mode 100644 index 000000000..1b9e268d9 --- /dev/null +++ b/docs/mkdocs/hooks/search_index.py @@ -0,0 +1,29 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project +"""Reduce browser search-index memory for generated API reference pages.""" + +from material.plugins.search.plugin import SearchIndex + +_add_entry_from_context = SearchIndex.add_entry_from_context + + +def add_entry_from_context(self: SearchIndex, page) -> None: + search = page.meta.get("search") or {} + if search.get("exclude"): + return + + if str(page.url).startswith("api/"): + entry = { + "location": page.url, + "title": str(page.meta.get("title", page.title)), + "text": "", + } + if "boost" in search: + entry["boost"] = search["boost"] + self.entries.append(entry) + return + + _add_entry_from_context(self, page) + + +SearchIndex.add_entry_from_context = add_entry_from_context diff --git a/docs/mkdocs/javascript/mathjax.js b/docs/mkdocs/javascript/mathjax.js index eb89ace06..2238e32e4 100644 --- a/docs/mkdocs/javascript/mathjax.js +++ b/docs/mkdocs/javascript/mathjax.js @@ -1,20 +1,44 @@ -// Enables MathJax rendering +// Enables MathJax rendering only on pages that contain math. window.MathJax = { - tex: { - inlineMath: [["\\(", "\\)"]], - displayMath: [["\\[", "\\]"]], - processEscapes: true, - processEnvironments: true - }, - options: { - ignoreHtmlClass: ".*|", - processHtmlClass: "arithmatex" - } - }; + tex: { + inlineMath: [["\\(", "\\)"]], + displayMath: [["\\[", "\\]"]], + processEscapes: true, + processEnvironments: true, + }, + options: { + ignoreHtmlClass: ".*|", + processHtmlClass: "arithmatex", + }, +}; - document$.subscribe(() => { - MathJax.startup.output.clearCache() - MathJax.typesetClear() - MathJax.texReset() - MathJax.typesetPromise() - }) +let mathJaxLoading; + +function loadMathJax() { + if (window.MathJax.typesetPromise) { + return Promise.resolve(); + } + if (!mathJaxLoading) { + mathJaxLoading = new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.src = "https://unpkg.com/mathjax@3.2.2/es5/tex-mml-chtml.js"; + script.async = true; + script.onload = resolve; + script.onerror = reject; + document.head.appendChild(script); + }); + } + return mathJaxLoading; +} + +document$.subscribe(() => { + if (!document.querySelector(".arithmatex")) { + return; + } + loadMathJax().then(() => { + MathJax.startup.output.clearCache(); + MathJax.typesetClear(); + MathJax.texReset(); + MathJax.typesetPromise(); + }); +}); diff --git a/docs/mkdocs/javascript/memory.js b/docs/mkdocs/javascript/memory.js new file mode 100644 index 000000000..1cc22a8ff --- /dev/null +++ b/docs/mkdocs/javascript/memory.js @@ -0,0 +1,2 @@ +// Opt out of bfcache so large generated API pages are released after navigation. +window.addEventListener("unload", () => {}); diff --git a/docs/mkdocs/javascript/mermaid.js b/docs/mkdocs/javascript/mermaid.js index 63676de9d..f8fae2d47 100644 --- a/docs/mkdocs/javascript/mermaid.js +++ b/docs/mkdocs/javascript/mermaid.js @@ -1,21 +1,42 @@ -// Initialize Mermaid for diagram rendering -mermaid.initialize({ - startOnLoad: false, - theme: 'default', - securityLevel: 'loose', - flowchart: { - useMaxWidth: true, - htmlLabels: true - } -}); +// Load Mermaid only on pages that contain diagrams. +let mermaidLoading; -// Render Mermaid diagrams when page content is ready -document$.subscribe(() => { - const mermaidElements = document.querySelectorAll('.mermaid'); - if (mermaidElements.length > 0) { - mermaid.run({ - querySelector: '.mermaid', - nodes: mermaidElements +function loadMermaid() { + if (window.mermaid) { + return Promise.resolve(); + } + if (!mermaidLoading) { + mermaidLoading = new Promise((resolve, reject) => { + const script = document.createElement("script"); + script.src = "https://unpkg.com/mermaid@10/dist/mermaid.min.js"; + script.async = true; + script.onload = () => { + mermaid.initialize({ + startOnLoad: false, + theme: "default", + securityLevel: "loose", + flowchart: { + useMaxWidth: true, + htmlLabels: true, + }, + }); + resolve(); + }; + script.onerror = reject; + document.head.appendChild(script); }); } + return mermaidLoading; +} + +document$.subscribe(() => { + if (!document.querySelector(".mermaid")) { + return; + } + loadMermaid().then(() => { + mermaid.run({ + querySelector: ".mermaid", + nodes: document.querySelectorAll(".mermaid"), + }); + }); }); diff --git a/mkdocs.yml b/mkdocs.yml index d19483002..74f2145fe 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -38,13 +38,12 @@ theme: features: - content.action.edit - content.code.copy - - navigation.instant - - navigation.instant.progress - navigation.tracking - navigation.tabs - navigation.tabs.sticky - navigation.sections - navigation.indexes + - navigation.prune - navigation.top - search.suggest - search.highlight @@ -56,6 +55,7 @@ theme: custom_dir: docs/mkdocs/overrides hooks: + - docs/mkdocs/hooks/search_index.py - docs/mkdocs/hooks/generate_api_readme.py - docs/mkdocs/hooks/url_schemes.py - docs/mkdocs/hooks/generate_examples.py @@ -117,6 +117,7 @@ plugins: separate_signature: true show_overloads: true signature_crossrefs: true + show_source: false inventories: - https://docs.python.org/3/objects.inv - https://typing-extensions.readthedocs.io/en/latest/objects.inv @@ -167,9 +168,8 @@ extra_css: - mkdocs/stylesheets/extra.css extra_javascript: + - mkdocs/javascript/memory.js - mkdocs/javascript/mathjax.js - - https://unpkg.com/mathjax@3.2.2/es5/tex-mml-chtml.js - - https://unpkg.com/mermaid@10/dist/mermaid.min.js - mkdocs/javascript/mermaid.js - mkdocs/javascript/edit_and_feedback.js - mkdocs/javascript/slack_and_forum.js