Add data-is-primary attribute to headwords (#1946)

This commit is contained in:
toasted-nutbread 2021-09-11 12:51:51 -04:00 committed by GitHub
parent 6661933d47
commit 88e71f8223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -232,12 +232,21 @@ class DisplayGenerator {
// Private
_createTermHeadword(headword, headwordIndex, pronunciations) {
const {term, reading, tags} = headword;
const {term, reading, tags, sources} = headword;
let isPrimaryAny = false;
for (const {isPrimary} of sources) {
if (isPrimary) {
isPrimaryAny = true;
break;
}
}
const node = this._templates.instantiate('headword');
const termContainer = node.querySelector('.headword-term');
node.dataset.isPrimary = `${isPrimaryAny}`;
node.dataset.readingIsSame = `${reading === term}`;
node.dataset.frequency = DictionaryDataUtil.getTermFrequency(tags);