|
| 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 | +}); |
0 commit comments