Skip to content

Commit

Permalink
fix: fixed Cookbook Onboard bug with "s" key (#196)
Browse files Browse the repository at this point in the history
Fixed Cookbook Onboard bug with "s" key not working because of mdbook search hijacking it
  • Loading branch information
ClockRide authored Jan 10, 2025
1 parent d3d3e9a commit 575fdcb
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions theme/head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,47 @@
amplitude.init('f60df2d0d709d50faa2ffda153a84bc0', { identityStorage:'none', defaultTracking: true });
}
</script>

<script>
function initAskCookbook() {
// It's a public API key, so it's safe to expose it here
const PUBLIC_API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NzU4Y2YyODM4NTcxODU5MjU0MGIyMDciLCJpYXQiOjE3MzM4NzM0NDgsImV4cCI6MjA0OTQ0OTQ0OH0.Z3cv3HuMkYq3aYZYzCKkkYuM5LI3KG-kuA0R-GaSMV4";
let cookbookContainer = document.getElementById("__cookbook");
if (!cookbookContainer) {
cookbookContainer = document.createElement("div");
cookbookContainer.id = "__cookbook";
cookbookContainer.dataset.apiKey = PUBLIC_API_KEY;
document.body.appendChild(cookbookContainer);
}
let cookbookScript = document.getElementById("__cookbook-script");
if (!cookbookScript) {
cookbookScript = document.createElement("script");
cookbookScript.id = "__cookbook-script";
cookbookScript.src = "https://cdn.jsdelivr.net/npm/@cookbookdev/docsbot/dist/standalone/index.cjs.js";
cookbookScript.async = true;
document.head.appendChild(cookbookScript);
}
const keyPressPropagationBlocker = function (e) {
e.stopPropagation();
};
document.addEventListener("cookbook:modal:state:change", function (e) {
const isOpen = e.detail.isOpen;
if (isOpen) {
document.body.addEventListener("keydown", keyPressPropagationBlocker, { capture: true });
} else {
document.body.removeEventListener("keydown", keyPressPropagationBlocker, { capture: true });
}
});
}
// Check if the document is already loaded and if so, initialize the script, otherwise wait for the load event
if (document.readyState === "complete") {
initAskCookbook();
} else {
window.addEventListener("load", initAskCookbook);
}
</script>

0 comments on commit 575fdcb

Please sign in to comment.