Skip to content

Commit

Permalink
Add active version class to document body
Browse files Browse the repository at this point in the history
  • Loading branch information
burnash committed Sep 13, 2024
1 parent b7fa8ca commit fc75ccb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/website/src/theme/Root.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import React, {useState, useEffect} from 'react';
import {useLocation} from '@docusaurus/router';
import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client';

// inject overlay content in root element
export default function Root({children}) {
const { activeVersion } = useActiveDocContext();

useEffect(() => {
if (activeVersion) {
// Remove all version classes
document.body.className = document.body.className.replace(/\bversion-\S+/g, '');
// Add the active version class
document.body.classList.add(`version-${activeVersion.name}`);
}
}, [activeVersion]);

return <>{children}<Overlay /></>;
}

Expand Down

0 comments on commit fc75ccb

Please sign in to comment.