commit
47f0042f5e
80 changed files with 1222 additions and 689 deletions
@ -0,0 +1,80 @@ |
|||||||
|
// Giscus functionality
|
||||||
|
function loadGiscus() { |
||||||
|
const giscusContainer = document.getElementById("giscus-container"); |
||||||
|
if (!giscusContainer || giscusContainer.querySelector("script")) return; |
||||||
|
|
||||||
|
const script = document.createElement("script"); |
||||||
|
script.src = "https://giscus.app/client.js"; |
||||||
|
script.setAttribute("data-repo", "ultralytics/ultralytics"); |
||||||
|
script.setAttribute("data-repo-id", "R_kgDOH-jzvQ"); |
||||||
|
script.setAttribute("data-category", "Docs"); |
||||||
|
script.setAttribute("data-category-id", "DIC_kwDOH-jzvc4CWLkL"); |
||||||
|
script.setAttribute("data-mapping", "pathname"); |
||||||
|
script.setAttribute("data-strict", "1"); |
||||||
|
script.setAttribute("data-reactions-enabled", "1"); |
||||||
|
script.setAttribute("data-emit-metadata", "0"); |
||||||
|
script.setAttribute("data-input-position", "top"); |
||||||
|
script.setAttribute("data-theme", "preferred_color_scheme"); |
||||||
|
script.setAttribute("data-lang", "en"); |
||||||
|
script.setAttribute("data-loading", "lazy"); |
||||||
|
script.setAttribute("crossorigin", "anonymous"); |
||||||
|
script.setAttribute("async", ""); |
||||||
|
|
||||||
|
giscusContainer.appendChild(script); |
||||||
|
|
||||||
|
// Synchronize Giscus theme with palette
|
||||||
|
var palette = __md_get("__palette"); |
||||||
|
if (palette && typeof palette.color === "object") { |
||||||
|
var theme = palette.color.scheme === "slate" ? "dark" : "light"; |
||||||
|
script.setAttribute("data-theme", theme); |
||||||
|
} |
||||||
|
|
||||||
|
// Register event handlers for theme changes
|
||||||
|
var ref = document.querySelector("[data-md-component=palette]"); |
||||||
|
if (ref) { |
||||||
|
ref.addEventListener("change", function () { |
||||||
|
var palette = __md_get("__palette"); |
||||||
|
if (palette && typeof palette.color === "object") { |
||||||
|
var theme = palette.color.scheme === "slate" ? "dark" : "light"; |
||||||
|
|
||||||
|
// Instruct Giscus to change theme
|
||||||
|
var frame = document.querySelector(".giscus-frame"); |
||||||
|
if (frame) { |
||||||
|
frame.contentWindow.postMessage( |
||||||
|
{ giscus: { setConfig: { theme } } }, |
||||||
|
"https://giscus.app", |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Use Intersection Observer to load Giscus when the container is visible
|
||||||
|
function setupGiscusLoader() { |
||||||
|
const giscusContainer = document.getElementById("giscus-container"); |
||||||
|
|
||||||
|
if (giscusContainer) { |
||||||
|
const observer = new IntersectionObserver((entries) => { |
||||||
|
entries.forEach((entry) => { |
||||||
|
if (entry.isIntersecting) { |
||||||
|
loadGiscus(); |
||||||
|
observer.unobserve(entry.target); |
||||||
|
} |
||||||
|
}); |
||||||
|
}, { threshold: 0.1 }); // Trigger when 10% of the element is visible
|
||||||
|
|
||||||
|
observer.observe(giscusContainer); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Hook into MkDocs' navigation system
|
||||||
|
if (typeof document$ !== "undefined") { |
||||||
|
document$.subscribe(() => { |
||||||
|
// This function is called on every page load/change
|
||||||
|
setupGiscusLoader(); |
||||||
|
}); |
||||||
|
} else { |
||||||
|
console.warn("MkDocs document$ not found. Falling back to DOMContentLoaded."); |
||||||
|
document.addEventListener("DOMContentLoaded", setupGiscusLoader); |
||||||
|
} |
@ -1,51 +1,7 @@ |
|||||||
{% if page.meta.comments %} |
{% if page.meta.comments %} |
||||||
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2> |
<h2 id="__comments">{{ lang.t("meta.comments") }}</h2> |
||||||
|
|
||||||
<!-- Insert Giscus code snippet from https://giscus.app/ here --> |
<!-- Giscus container --> |
||||||
<script async |
<div id="giscus-container"></div> |
||||||
crossorigin="anonymous" |
|
||||||
data-category="Docs" |
|
||||||
data-category-id="DIC_kwDOH-jzvc4CWLkL" |
|
||||||
data-emit-metadata="0" |
|
||||||
data-input-position="top" |
|
||||||
data-lang="en" |
|
||||||
data-loading="lazy" |
|
||||||
data-mapping="pathname" |
|
||||||
data-reactions-enabled="1" |
|
||||||
data-repo="ultralytics/ultralytics" |
|
||||||
data-repo-id="R_kgDOH-jzvQ" |
|
||||||
data-strict="1" |
|
||||||
data-theme="preferred_color_scheme" |
|
||||||
src="https://giscus.app/client.js"> |
|
||||||
</script> |
|
||||||
|
|
||||||
<!-- Synchronize Giscus theme with palette --> |
|
||||||
<script> |
|
||||||
var giscus = document.querySelector("script[src*=giscus]") |
|
||||||
|
|
||||||
/* Set palette on initial load */ |
|
||||||
var palette = __md_get("__palette") |
|
||||||
if (palette && typeof palette.color === "object") { |
|
||||||
var theme = palette.color.scheme === "slate" ? "dark" : "light" |
|
||||||
giscus.setAttribute("data-theme", theme) |
|
||||||
} |
|
||||||
|
|
||||||
/* Register event handlers after documented loaded */ |
|
||||||
document.addEventListener("DOMContentLoaded", function() { |
|
||||||
var ref = document.querySelector("[data-md-component=palette]") |
|
||||||
ref.addEventListener("change", function() { |
|
||||||
var palette = __md_get("__palette") |
|
||||||
if (palette && typeof palette.color === "object") { |
|
||||||
var theme = palette.color.scheme === "slate" ? "dark" : "light" |
|
||||||
|
|
||||||
/* Instruct Giscus to change theme */ |
|
||||||
var frame = document.querySelector(".giscus-frame") |
|
||||||
frame.contentWindow.postMessage( |
|
||||||
{ giscus: { setConfig: { theme } } }, |
|
||||||
"https://giscus.app" |
|
||||||
) |
|
||||||
} |
|
||||||
}) |
|
||||||
}) |
|
||||||
</script> |
|
||||||
{% endif %} |
{% endif %} |
||||||
|
@ -1,26 +0,0 @@ |
|||||||
{% import "partials/language.html" as lang with context %} |
|
||||||
|
|
||||||
<!-- taken from |
|
||||||
https://github.com/squidfunk/mkdocs-material/blob/master/src/partials/source-file.html --> |
|
||||||
|
|
||||||
<br> |
|
||||||
<div class="md-source-file"> |
|
||||||
<small> |
|
||||||
|
|
||||||
<!-- mkdocs-git-revision-date-localized-plugin --> |
|
||||||
{% if page.meta.git_revision_date_localized %} |
|
||||||
📅 {{ lang.t("source.file.date.updated") }}: |
|
||||||
{{ page.meta.git_revision_date_localized }} |
|
||||||
{% if page.meta.git_creation_date_localized %} |
|
||||||
<br/> |
|
||||||
🎂 {{ lang.t("source.file.date.created") }}: |
|
||||||
{{ page.meta.git_creation_date_localized }} |
|
||||||
{% endif %} |
|
||||||
|
|
||||||
<!-- mkdocs-git-revision-date-plugin --> |
|
||||||
{% elif page.meta.revision_date %} |
|
||||||
📅 {{ lang.t("source.file.date.updated") }}: |
|
||||||
{{ page.meta.revision_date }} |
|
||||||
{% endif %} |
|
||||||
</small> |
|
||||||
</div> |
|
Loading…
Reference in new issue