Prevent rendering reference if specified does not exist

This commit is contained in:
Robbie Antenesse 2019-05-29 15:36:44 -06:00 committed by Robbie Antenesse
parent 4a1dd7aae4
commit 08cadfb121
1 changed files with 9 additions and 5 deletions

View File

@ -50,26 +50,30 @@ export function parseReferences(detailsMarkdown, references) {
new Set(references).forEach(reference => { new Set(references).forEach(reference => {
let wordToFind = reference.replace(/\{\{|\}\}/g, ''); let wordToFind = reference.replace(/\{\{|\}\}/g, '');
let homonymn = 0; let homonymn = 0;
if (wordToFind.includes(':')) { if (wordToFind.includes(':')) {
const separator = wordToFind.indexOf(':'); const separator = wordToFind.indexOf(':');
homonymn = wordToFind.substr(separator + 1); homonymn = wordToFind.substr(separator + 1);
wordToFind = wordToFind.substring(0, separator); wordToFind = wordToFind.substring(0, separator);
if (homonymn && homonymn.trim() && !isNaN(parseInt(homonymn.trim()))) { if (homonymn && homonymn.trim()
&& !isNaN(parseInt(homonymn.trim())) && parseInt(homonymn.trim()) > 0) {
homonymn = parseInt(homonymn.trim()); homonymn = parseInt(homonymn.trim());
} else { } else {
homonymn = 0; homonymn = false;
} }
} }
let existingWordId = false; let existingWordId = false;
const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 }); const homonymnIndexes = getHomonymnIndexes({ name: wordToFind, wordId: -1 });
console.log(homonymn, homonymnIndexes);
if (homonymn > 0) { if (homonymn !== false && homonymn > 0) {
if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') { if (typeof homonymnIndexes[homonymn - 1] !== 'undefined') {
existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId; existingWordId = window.currentDictionary.words[homonymnIndexes[homonymn - 1]].wordId;
} }
} else { } else if (homonymn !== false) {
existingWordId = wordExists(wordToFind, true); existingWordId = wordExists(wordToFind, true);
} }
if (existingWordId !== false) { if (existingWordId !== false) {
if (homonymn < 1 && homonymnIndexes.length > 0) { if (homonymn < 1 && homonymnIndexes.length > 0) {
homonymn = 1; homonymn = 1;