Skip to content

Commit f454065

Browse files
committed
0.06
1 parent 4bf4562 commit f454065

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

docs/assets/javascripts/online-compile.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@
6464
function createHeaderButton() {
6565
const a = document.createElement("a");
6666
a.href = "https://godbolt.org/";
67-
a.className = "md-header__button md-icon online-compile-header-button";
67+
a.className = "md-button online-compile-header-button";
6868
a.title = "在线编译(打开 Compiler Explorer)";
6969
a.setAttribute("aria-label", a.title);
70-
a.innerHTML =
71-
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" aria-hidden="true">' +
72-
'<path d="M10 17l6-5-6-5v10ZM19 19H5V5h14v14Zm0-16H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V5a2 2 0 0 0-2-2Z"/>' +
73-
"</svg>";
70+
a.textContent = "在线编译";
7471

7572
a.addEventListener("click", (e) => {
7673
e.preventDefault();
@@ -81,15 +78,24 @@
8178
}
8279

8380
function ensureHeaderButton() {
84-
const headerInner =
85-
document.querySelector(".md-header__inner") ||
86-
document.querySelector("header.md-header") ||
87-
document.body;
81+
const header = document.querySelector("header.md-header") || document.querySelector(".md-header");
82+
if (!(header instanceof HTMLElement)) return;
8883

89-
if (!(headerInner instanceof HTMLElement)) return;
90-
if (headerInner.querySelector(".online-compile-header-button")) return;
84+
const search = header.querySelector(".md-search");
85+
const target =
86+
(search && search.parentElement instanceof HTMLElement ? search.parentElement : null) ||
87+
header.querySelector(".md-header__inner") ||
88+
header;
9189

92-
headerInner.appendChild(createHeaderButton());
90+
if (!(target instanceof HTMLElement)) return;
91+
if (target.querySelector(".online-compile-header-button")) return;
92+
93+
const btn = createHeaderButton();
94+
if (search && search instanceof HTMLElement) {
95+
target.insertBefore(btn, search);
96+
} else {
97+
target.appendChild(btn);
98+
}
9399
}
94100

95101
function onReady(fn) {
@@ -100,10 +106,18 @@
100106
}
101107
}
102108

103-
onReady(() => {
109+
function init() {
104110
ensureHeaderButton();
111+
}
105112

106-
const observer = new MutationObserver(() => ensureHeaderButton());
107-
observer.observe(document.body, { childList: true, subtree: true });
113+
onReady(() => {
114+
const doc$ = window.document$;
115+
if (doc$ && typeof doc$.subscribe === "function") {
116+
doc$.subscribe(() => init());
117+
} else {
118+
init();
119+
const observer = new MutationObserver(() => init());
120+
observer.observe(document.body, { childList: true, subtree: true });
121+
}
108122
});
109123
})();

docs/assets/stylesheets/online-compile.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
display: inline-flex;
33
align-items: center;
44
justify-content: center;
5+
margin-right: 0.5rem;
6+
padding: 0.25rem 0.6rem;
7+
font-size: 0.7rem;
8+
line-height: 1.2;
59
}
610

7-
.online-compile-header-button svg {
8-
width: 1.2rem;
9-
height: 1.2rem;
11+
.md-header .online-compile-header-button {
12+
white-space: nowrap;
1013
}

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
site_name: QrCraft 开发文档
2-
# site_url: https://github.com/USERNAME/qrcraft
2+
# site_url: https://sudoevolve.github.io/cppNote/
33
site_description: Qt/C++/QML 开发文档与组件库
44

55
# 文档根目录设为 docs 目录

0 commit comments

Comments
 (0)