gstreamer/subprojects/gst-docs/scripts/assets/js/theme-sync.js
Thibault Saunier 58939e10ee docs: Embed the gstreamer-rs documentation into our documentation in CI
Downloading the latest build of GStreamer-rs from its CI job and running a
script to embed the rustoc generated documentation into hotdoc based one.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8317>
2025-01-23 10:52:50 +00:00

34 lines
1.1 KiB
JavaScript

function syncThemeWithHotdoc() {
// Get the current stylesheet
const currentStyle = document.querySelector('link[rel="stylesheet"][href*="frontend"]');
if (!currentStyle) return;
// Check if we're using dark theme in hotdoc
const isDark = getActiveStyleSheet() == 'dark';
// Use rustdoc's switchTheme function to set the theme
let newThemeName = isDark ? 'dark' : 'light';
window.switchTheme(newThemeName, true);
}
// Run on page load
document.addEventListener('DOMContentLoaded', () => {
localStorage.setItem("rustdoc-use-system-theme", false);
syncThemeWithHotdoc();
// Watch for theme changes in hotdoc
const theme_observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
syncThemeWithHotdoc();
}
});
});
// Start observing theme changes
const styleLink = document.querySelector('link[rel="stylesheet"][href*="frontend"]');
if (styleLink) {
theme_observer.observe(styleLink, { attributes: true });
}
});