Skip to content

Commit 154d063

Browse files
authored
[doc][mkdocs] Add edit button to documentation (#19637)
Signed-off-by: reidliu41 <[email protected]> Co-authored-by: reidliu41 <[email protected]>
1 parent ccd7c05 commit 154d063

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* edit_and_feedback.js
3+
*
4+
* Enhances MkDocs Material docs pages by:
5+
*
6+
* 1. Adding a "Question? Give us feedback" link
7+
* below the "Edit" button.
8+
*
9+
* - The link opens a GitHub issue with a template,
10+
* auto-filled with the current page URL and path.
11+
*
12+
* 2. Ensuring the edit button opens in a new tab
13+
* with target="_blank" and rel="noopener".
14+
*/
15+
document.addEventListener("DOMContentLoaded", function () {
16+
const url = window.location.href;
17+
const page = document.body.dataset.mdUrl || location.pathname;
18+
19+
const feedbackLink = document.createElement("a");
20+
feedbackLink.href = `https://github.com/vllm-project/vllm/issues/new?template=100-documentation.yml&title=${encodeURIComponent(
21+
`[Docs] Feedback for \`${page}\``
22+
)}&body=${encodeURIComponent(`📄 **Reference:**\n${url}\n\n📝 **Feedback:**\n_Your response_`)}`;
23+
feedbackLink.target = "_blank";
24+
feedbackLink.rel = "noopener";
25+
feedbackLink.title = "Provide feedback";
26+
feedbackLink.className = "md-content__button";
27+
feedbackLink.innerHTML = `
28+
<svg
29+
xmlns="http://www.w3.org/2000/svg"
30+
height="24px"
31+
viewBox="0 -960 960 960"
32+
width="24px"
33+
fill="currentColor"
34+
>
35+
<path d="M280-280h280v-80H280v80Zm0-160h400v-80H280v80Zm0-160h400v-80H280v80Zm-80 480q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z"/>
36+
</svg>
37+
`;
38+
39+
const editButton = document.querySelector('.md-content__button[href*="edit"]');
40+
41+
if (editButton && editButton.parentNode) {
42+
editButton.insertAdjacentElement("beforebegin", feedbackLink);
43+
44+
editButton.setAttribute("target", "_blank");
45+
editButton.setAttribute("rel", "noopener");
46+
}
47+
});

docs/mkdocs/stylesheets/extra.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,40 @@ body[data-md-color-scheme="slate"] .md-nav__item--section > label.md-nav__link .
7171
-webkit-mask-image: var(--md-admonition-icon--important);
7272
mask-image: var(--md-admonition-icon--important);
7373
}
74+
75+
/* Make label fully visible on hover */
76+
.md-content__button[href*="edit"]:hover::after {
77+
opacity: 1;
78+
}
79+
80+
/* Hide edit button on generated docs/examples pages */
81+
@media (min-width: 960px) {
82+
.md-content__button[href*="docs/examples/"] {
83+
display: none !important;
84+
}
85+
}
86+
87+
.md-content__button-wrapper {
88+
position: absolute;
89+
top: 0.6rem;
90+
right: 0.8rem;
91+
display: flex;
92+
flex-direction: row;
93+
align-items: center;
94+
gap: 0.4rem;
95+
z-index: 1;
96+
}
97+
98+
.md-content__button-wrapper a {
99+
display: inline-flex;
100+
align-items: center;
101+
justify-content: center;
102+
height: 24px;
103+
width: 24px;
104+
color: var(--md-default-fg-color);
105+
text-decoration: none;
106+
}
107+
108+
.md-content__button-wrapper a:hover {
109+
color: var(--md-accent-fg-color);
110+
}

mkdocs.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
site_name: vLLM
22
site_url: https://docs.vllm.ai
33
repo_url: https://github.com/vllm-project/vllm
4+
edit_uri: edit/main/docs/
45
exclude_docs: |
56
*.inc.md
67
*.template.md
@@ -29,6 +30,7 @@ theme:
2930
icon: material/brightness-2
3031
name: Switch to system preference
3132
features:
33+
- content.action.edit
3234
- content.code.copy
3335
- content.tabs.link
3436
- navigation.tracking
@@ -124,6 +126,7 @@ extra_css:
124126
extra_javascript:
125127
- mkdocs/javascript/run_llm_widget.js
126128
- https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML
129+
- mkdocs/javascript/edit_and_feedback.js
127130

128131
# Makes the url format end in .html rather than act as a dir
129132
# So index.md generates as index.html and is available under URL /index.html

0 commit comments

Comments
 (0)