Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/components/GlossaryInjector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,33 @@ const GlossaryInjector: React.FC<GlossaryInjectorProps> = ({ children }) => {
.catch((err) => console.error('Failed to load glossary:', err));
}, []);

// Function to check if the current page is a version index page
const isVersionIndexPage = () => {
if (typeof window !== 'undefined') {
const path = window.location.pathname;

// Check for various version index patterns
// English versions
if (path.match(/\/docs\/latest\/?$/) ||
path.match(/\/docs\/latest\/index(\.html)?/) ||
path.match(/\/docs\/[0-9]+\.[0-9]+\/?$/) ||
path.match(/\/docs\/[0-9]+\.[0-9]+\/index(\.html)?/)) {
return true;
}

// Japanese versions
if (path.match(/\/ja-jp\/docs\/latest\/?$/) ||
path.match(/\/ja-jp\/docs\/latest\/index(\.html)?/) ||
path.match(/\/ja-jp\/docs\/[0-9]+\.[0-9]+\/?$/) ||
path.match(/\/ja-jp\/docs\/[0-9]+\.[0-9]+\/index(\.html)?/)) {
return true;
}
}
return false;
};

useEffect(() => {
if (Object.keys(glossary).length === 0) return;
if (Object.keys(glossary).length === 0 || isVersionIndexPage()) return;

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

while ((match = regex.exec(currentText))) {
const matchedText = match[0]; // The full matched text (may include plural suffix).

// Find the base term from the glossary that matches (without plural).
const baseTerm = terms.find(term =>
matchedText.toLowerCase() === term.toLowerCase() ||
matchedText.toLowerCase() === `${term.toLowerCase()}s` ||
matchedText.toLowerCase() === `${term.toLowerCase()}es`
);

if (!baseTerm) {
// Skip if no matching base term found.
continue;
Expand All @@ -116,11 +141,11 @@ const GlossaryInjector: React.FC<GlossaryInjectorProps> = ({ children }) => {
tooltipWrapper.className = 'glossary-term';

const definition = glossary[baseTerm];

// Extract the part to underline (the base term) and the suffix (if plural).
let textToUnderline = matchedText;
let suffix = '';

if (matchedText.toLowerCase() !== baseTerm.toLowerCase()) {
// This is a plural form - only underline the base part.
const baseTermLength = baseTerm.length;
Expand Down