github.com/SamarSidharth/kpt@v0.0.0-20231122062228-c7d747ae3ace/site/static/js/plugins/github_widget.js (about) 1 // Matches a path like /book/02-concepts/01-packages 2 const bookPath = /^\/book\/(\d+)-(.+)\/(\d+)?-?(.+)?/; 3 4 const issueIcon = document.createElement("span"); 5 issueIcon.innerText = "bug_report"; 6 issueIcon.classList.add("material-icons-outlined"); 7 const createIssue = document.createElement("a"); 8 createIssue.id = "create_issue_button"; 9 createIssue.target = "_blank"; 10 createIssue.title = "Create documentation issue"; 11 createIssue.appendChild(issueIcon); 12 13 const editIcon = document.createElement("span"); 14 editIcon.innerText = "edit"; 15 editIcon.classList.add("material-icons-outlined"); 16 const editPage = document.createElement("a"); 17 editPage.id = "edit_page_button"; 18 editPage.target = "_blank"; 19 editPage.title = "Edit this page"; 20 editPage.appendChild(editIcon); 21 22 function addGitHubWidget() { 23 createIssue.href = `https://github.com/GoogleContainerTools/kpt/issues/new?labels=documentation&title=Docs: ${document.title} (${window.location})`; 24 25 let path = window.location.pathname; 26 const pageName = path.match(bookPath) ? "00.md" : "README.md"; 27 path += path.endsWith("/") ? pageName : ".md"; 28 editPage.href = `https://github.com/GoogleContainerTools/kpt/edit/main/site${path}`; 29 30 const container = document.createElement("div"); 31 container.classList.add("github-widget"); 32 container.appendChild(createIssue); 33 container.appendChild(editPage); 34 document 35 .getElementsByClassName("docsify-pagination-container") 36 .item(0) 37 .append(container); 38 } 39 40 // Load plugins into Docsify. 41 window.$docsify = window.$docsify || {}; 42 window.$docsify.plugins = [].concat(function (hook, _vm) { 43 hook.doneEach(addGitHubWidget); 44 }, window.$docsify.plugins); 45 46 // Export functions for testing. 47 if (typeof module !== "undefined") { 48 module.exports = { addGitHubWidget }; 49 }