Put homonymn number on public dictionary entries

This commit is contained in:
Robbie Antenesse 2019-06-06 15:41:30 -06:00 committed by Robbie Antenesse
parent 3553530e6e
commit 74642dcc0a
2 changed files with 20 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import md from 'marked'; import md from 'marked';
import { removeTags, slugify } from '../../helpers'; import { removeTags, slugify } from '../../helpers';
import { getWordsStats } from './utilities'; import { getWordsStats, getHomonymnNumber } from './utilities';
import { getMatchingSearchWords, highlightSearchTerm, getSearchFilters, getSearchTerm } from './search'; import { getMatchingSearchWords, highlightSearchTerm, getSearchFilters, getSearchTerm } from './search';
import { showSection } from './displayToggles'; import { showSection } from './displayToggles';
import { setupSearchFilters, setupInfoModal } from './setupListeners'; import { setupSearchFilters, setupInfoModal } from './setupListeners';
@ -155,13 +155,15 @@ export function renderWords() {
details: parseReferences(removeTags(originalWord.details)), details: parseReferences(removeTags(originalWord.details)),
wordId: originalWord.wordId, wordId: originalWord.wordId,
}); });
const homonymnNumber = getHomonymnNumber(originalWord);
const shareLink = window.location.pathname + (window.location.pathname.match(new RegExp(word.wordId + '$')) ? '' : '/' + word.wordId); const shareLink = window.location.pathname + (window.location.pathname.match(new RegExp(word.wordId + '$')) ? '' : '/' + word.wordId);
wordsHTML += renderAd(displayIndex); wordsHTML += renderAd(displayIndex);
wordsHTML += `<article class="entry" id="${word.wordId}"> wordsHTML += `<article class="entry" id="${word.wordId}">
<header> <header>
<h4 class="word">${word.name}</h4> <h4 class="word">${word.name}${homonymnNumber > 0 ? ' <sub>' + homonymnNumber.toString() + '</sub>' : ''}</h4>
<span class="pronunciation">${word.pronunciation}</span> <span class="pronunciation">${word.pronunciation}</span>
<span class="part-of-speech">${word.partOfSpeech}</span> <span class="part-of-speech">${word.partOfSpeech}</span>
<a href="${shareLink}" target="_blank" class="small button word-option-button" title="Link to Word">&#10150;</a> <a href="${shareLink}" target="_blank" class="small button word-option-button" title="Link to Word">&#10150;</a>

View File

@ -100,3 +100,19 @@ export function getHomonymnIndexes(word) {
}); });
return foundIndexes; return foundIndexes;
} }
export function getHomonymnNumber(word) {
const homonyms = getHomonymnIndexes(word);
if (homonyms.length > 0) {
const index = window.currentDictionary.words.findIndex(w => w.wordId === word.wordId);
let number = 1;
for (let i = 0; i < homonyms.length; i++) {
if (index < homonyms[i]) break;
number++;
}
return number;
}
return 0;
}