Skip to content

Commit c4c83cc

Browse files
authored
Remove glossary tooltips version from home pages (#1303)
* Remove unnecessary indenting * Hide glossary tooltips on version home pages * Streamline handling of version home page languages
1 parent e648844 commit c4c83cc

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/components/GlossaryInjector.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,25 @@ const GlossaryInjector: React.FC<GlossaryInjectorProps> = ({ children }) => {
3030
.catch((err) => console.error('Failed to load glossary:', err));
3131
}, []);
3232

33+
// Function to check if the current page is a version index page
34+
const isVersionIndexPage = () => {
35+
if (typeof window !== 'undefined') {
36+
const path = window.location.pathname;
37+
38+
// Check for various version index patterns
39+
const localePrefix = '(?:/ja-jp)?'; // Matches either '/ja-jp' or nothing
40+
if (path.match(new RegExp(`${localePrefix}/docs/latest/?$`)) ||
41+
path.match(new RegExp(`${localePrefix}/docs/latest/index(\\.html)?`)) ||
42+
path.match(new RegExp(`${localePrefix}/docs/[0-9]+\\.[0-9]+/?$`)) ||
43+
path.match(new RegExp(`${localePrefix}/docs/[0-9]+\\.[0-9]+/index(\\.html)?`))) {
44+
return true;
45+
}
46+
}
47+
return false;
48+
};
49+
3350
useEffect(() => {
34-
if (Object.keys(glossary).length === 0) return;
51+
if (Object.keys(glossary).length === 0 || isVersionIndexPage()) return;
3552

3653
// Sort terms in descending order by length to prioritize multi-word terms.
3754
const terms = Object.keys(glossary).sort((a, b) => b.length - a.length);
@@ -89,14 +106,14 @@ const GlossaryInjector: React.FC<GlossaryInjectorProps> = ({ children }) => {
89106

90107
while ((match = regex.exec(currentText))) {
91108
const matchedText = match[0]; // The full matched text (may include plural suffix).
92-
109+
93110
// Find the base term from the glossary that matches (without plural).
94111
const baseTerm = terms.find(term =>
95112
matchedText.toLowerCase() === term.toLowerCase() ||
96113
matchedText.toLowerCase() === `${term.toLowerCase()}s` ||
97114
matchedText.toLowerCase() === `${term.toLowerCase()}es`
98115
);
99-
116+
100117
if (!baseTerm) {
101118
// Skip if no matching base term found.
102119
continue;
@@ -116,11 +133,11 @@ const GlossaryInjector: React.FC<GlossaryInjectorProps> = ({ children }) => {
116133
tooltipWrapper.className = 'glossary-term';
117134

118135
const definition = glossary[baseTerm];
119-
136+
120137
// Extract the part to underline (the base term) and the suffix (if plural).
121138
let textToUnderline = matchedText;
122139
let suffix = '';
123-
140+
124141
if (matchedText.toLowerCase() !== baseTerm.toLowerCase()) {
125142
// This is a plural form - only underline the base part.
126143
const baseTermLength = baseTerm.length;

0 commit comments

Comments
 (0)