mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-08-21 07:02:25 +02:00
# Overview Adding conditional rendering logic to co-locate js and python documentation. * `:::` conditional syntax can be used to switch between python only or js only content. * Contains simple unit tests for `:::` * PR adds set up for a way to implement a context switch between languages, but it will not be enabled until JS content is merged in. * Contains a script that can add javascript documentation Implementation of: https://github.com/langchain-ai/langgraph/pull/5118 ## Example Example of conditional rendering / compilation. ```markdown ### Config (static context) Config is for immutable data like user metadata or API keys. Use when you have values that don't change mid-run. Specify configuration using a key called **"configurable"** which is reserved for this purpose: :::python This content will only be rendered for the python site. ::: :::js this content will only be rendered for the js / ts site. ::: ```
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
function applyLanguageSwitching() {
|
|
const selector = document.getElementById("global-language-selector");
|
|
|
|
const langBlocks = {
|
|
python: document.querySelectorAll(".lang-python"),
|
|
javascript: document.querySelectorAll(".lang-javascript"),
|
|
};
|
|
|
|
const setLanguage = (lang) => {
|
|
for (const [key, blocks] of Object.entries(langBlocks)) {
|
|
blocks.forEach((block) => {
|
|
block.style.display = key === lang ? "block" : "none";
|
|
});
|
|
}
|
|
localStorage.setItem("preferredLang", lang);
|
|
};
|
|
|
|
const saved = localStorage.getItem("preferredLang") || "python";
|
|
|
|
if (selector) {
|
|
selector.value = saved;
|
|
selector.addEventListener("change", (e) => setLanguage(e.target.value));
|
|
}
|
|
|
|
setLanguage(saved);
|
|
}
|
|
|
|
// Run on initial load
|
|
document.addEventListener("DOMContentLoaded", applyLanguageSwitching);
|
|
|
|
// Re-run after client-side navigation (MkDocs Material)
|
|
document.addEventListener("pjax:success", applyLanguageSwitching);
|
|
|
|
// Optional: observe DOM changes (e.g., for late-loaded content)
|
|
if (window.MutationObserver) {
|
|
const observer = new MutationObserver(() => applyLanguageSwitching());
|
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
}
|