[Doc] Reduce browser memory usage for docs (#3870)
Signed-off-by: David Chen <530634352@qq.com>
This commit is contained in:
1 parent
b72ffb82bb
commit
0e3bf4de8e
6 files changed
+131
-46
No files matched your search
@@ -16,6 +16,7 @@ ROOT_DIR_RELATIVE = "../../../../.."
|
|||||||
EXAMPLE_DIR = ROOT_DIR / "examples"
|
EXAMPLE_DIR = ROOT_DIR / "examples"
|
||||||
EXAMPLE_DOC_DIR = ROOT_DIR / "docs/user_guide/examples"
|
EXAMPLE_DOC_DIR = ROOT_DIR / "docs/user_guide/examples"
|
||||||
NAV_FILE = ROOT_DIR / "docs/.nav.yml"
|
NAV_FILE = ROOT_DIR / "docs/.nav.yml"
|
||||||
|
MAX_INLINE_MATERIAL_SIZE = 8 * 1024
|
||||||
|
|
||||||
|
|
||||||
def fix_case(text: str) -> str:
|
def fix_case(text: str) -> str:
|
||||||
@@ -191,18 +192,21 @@ class Example:
|
|||||||
|
|
||||||
return re.sub(link_pattern, replace_link, content)
|
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:
|
def generate(self) -> str:
|
||||||
content = f"# {self.title}\n\n"
|
content = f"# {self.title}\n\n"
|
||||||
url = "https://github.com/vllm-project/vllm-omni/"
|
content += f"Source <{self.github_url(self.path)}>.\n\n"
|
||||||
url += "tree/main" if self.path.is_dir() else "blob/main"
|
|
||||||
content += f"Source <{url}/{self.path.relative_to(ROOT_DIR)}>.\n\n"
|
|
||||||
|
|
||||||
# Use long code fence to avoid issues with
|
# Use long code fence to avoid issues with
|
||||||
# included files containing code fences too
|
# included files containing code fences too
|
||||||
code_fence = "``````"
|
code_fence = "``````"
|
||||||
|
|
||||||
if self.is_code:
|
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'
|
content += f'{code_fence}{self.main_file.suffix[1:]}\n--8<-- "{main_file_rel}"\n{code_fence}\n'
|
||||||
else:
|
else:
|
||||||
with open(self.main_file, encoding="utf-8") as f:
|
with open(self.main_file, encoding="utf-8") as f:
|
||||||
@@ -216,10 +220,15 @@ class Example:
|
|||||||
|
|
||||||
content += "## Example materials\n\n"
|
content += "## Example materials\n\n"
|
||||||
for file in sorted(self.other_files):
|
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":
|
if file.suffix != ".md":
|
||||||
content += f" {code_fence}{file.suffix[1:]}\n"
|
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":
|
if file.suffix != ".md":
|
||||||
content += f" {code_fence}\n"
|
content += f" {code_fence}\n"
|
||||||
|
|
||||||
@@ -291,7 +300,7 @@ def update_nav_file(examples: list[Example]):
|
|||||||
for example in category_examples:
|
for example in category_examples:
|
||||||
doc_path = EXAMPLE_DOC_DIR / example.category / f"{example.path.stem}.md"
|
doc_path = EXAMPLE_DOC_DIR / example.category / f"{example.path.stem}.md"
|
||||||
rel_path = doc_path.relative_to(ROOT_DIR / "docs")
|
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:
|
if category_items:
|
||||||
# Format category name (e.g., "offline_inference" -> "Offline Inference")
|
# Format category name (e.g., "offline_inference" -> "Offline Inference")
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1,20 +1,44 @@
|
|||||||
// Enables MathJax rendering
|
// Enables MathJax rendering only on pages that contain math.
|
||||||
window.MathJax = {
|
window.MathJax = {
|
||||||
tex: {
|
tex: {
|
||||||
inlineMath: [["\\(", "\\)"]],
|
inlineMath: [["\\(", "\\)"]],
|
||||||
displayMath: [["\\[", "\\]"]],
|
displayMath: [["\\[", "\\]"]],
|
||||||
processEscapes: true,
|
processEscapes: true,
|
||||||
processEnvironments: true
|
processEnvironments: true,
|
||||||
},
|
},
|
||||||
options: {
|
options: {
|
||||||
ignoreHtmlClass: ".*|",
|
ignoreHtmlClass: ".*|",
|
||||||
processHtmlClass: "arithmatex"
|
processHtmlClass: "arithmatex",
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
document$.subscribe(() => {
|
let mathJaxLoading;
|
||||||
MathJax.startup.output.clearCache()
|
|
||||||
MathJax.typesetClear()
|
function loadMathJax() {
|
||||||
MathJax.texReset()
|
if (window.MathJax.typesetPromise) {
|
||||||
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
// Opt out of bfcache so large generated API pages are released after navigation.
|
||||||
|
window.addEventListener("unload", () => {});
|
||||||
@@ -1,21 +1,42 @@
|
|||||||
// Initialize Mermaid for diagram rendering
|
// Load Mermaid only on pages that contain diagrams.
|
||||||
mermaid.initialize({
|
let mermaidLoading;
|
||||||
startOnLoad: false,
|
|
||||||
theme: 'default',
|
|
||||||
securityLevel: 'loose',
|
|
||||||
flowchart: {
|
|
||||||
useMaxWidth: true,
|
|
||||||
htmlLabels: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Render Mermaid diagrams when page content is ready
|
function loadMermaid() {
|
||||||
document$.subscribe(() => {
|
if (window.mermaid) {
|
||||||
const mermaidElements = document.querySelectorAll('.mermaid');
|
return Promise.resolve();
|
||||||
if (mermaidElements.length > 0) {
|
}
|
||||||
mermaid.run({
|
if (!mermaidLoading) {
|
||||||
querySelector: '.mermaid',
|
mermaidLoading = new Promise((resolve, reject) => {
|
||||||
nodes: mermaidElements
|
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"),
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
+4
-4
@@ -38,13 +38,12 @@ theme:
|
|||||||
features:
|
features:
|
||||||
- content.action.edit
|
- content.action.edit
|
||||||
- content.code.copy
|
- content.code.copy
|
||||||
- navigation.instant
|
|
||||||
- navigation.instant.progress
|
|
||||||
- navigation.tracking
|
- navigation.tracking
|
||||||
- navigation.tabs
|
- navigation.tabs
|
||||||
- navigation.tabs.sticky
|
- navigation.tabs.sticky
|
||||||
- navigation.sections
|
- navigation.sections
|
||||||
- navigation.indexes
|
- navigation.indexes
|
||||||
|
- navigation.prune
|
||||||
- navigation.top
|
- navigation.top
|
||||||
- search.suggest
|
- search.suggest
|
||||||
- search.highlight
|
- search.highlight
|
||||||
@@ -56,6 +55,7 @@ theme:
|
|||||||
custom_dir: docs/mkdocs/overrides
|
custom_dir: docs/mkdocs/overrides
|
||||||
|
|
||||||
hooks:
|
hooks:
|
||||||
|
- docs/mkdocs/hooks/search_index.py
|
||||||
- docs/mkdocs/hooks/generate_api_readme.py
|
- docs/mkdocs/hooks/generate_api_readme.py
|
||||||
- docs/mkdocs/hooks/url_schemes.py
|
- docs/mkdocs/hooks/url_schemes.py
|
||||||
- docs/mkdocs/hooks/generate_examples.py
|
- docs/mkdocs/hooks/generate_examples.py
|
||||||
@@ -117,6 +117,7 @@ plugins:
|
|||||||
separate_signature: true
|
separate_signature: true
|
||||||
show_overloads: true
|
show_overloads: true
|
||||||
signature_crossrefs: true
|
signature_crossrefs: true
|
||||||
|
show_source: false
|
||||||
inventories:
|
inventories:
|
||||||
- https://docs.python.org/3/objects.inv
|
- https://docs.python.org/3/objects.inv
|
||||||
- https://typing-extensions.readthedocs.io/en/latest/objects.inv
|
- https://typing-extensions.readthedocs.io/en/latest/objects.inv
|
||||||
@@ -167,9 +168,8 @@ extra_css:
|
|||||||
- mkdocs/stylesheets/extra.css
|
- mkdocs/stylesheets/extra.css
|
||||||
|
|
||||||
extra_javascript:
|
extra_javascript:
|
||||||
|
- mkdocs/javascript/memory.js
|
||||||
- mkdocs/javascript/mathjax.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/mermaid.js
|
||||||
- mkdocs/javascript/edit_and_feedback.js
|
- mkdocs/javascript/edit_and_feedback.js
|
||||||
- mkdocs/javascript/slack_and_forum.js
|
- mkdocs/javascript/slack_and_forum.js
|
||||||
Reference in new issue
Block a user