Skip to content

Commit

Permalink
Add term tags to {tags} Anki field (#1464)
Browse files Browse the repository at this point in the history
* add term tags to {{tags}}

* update tests

* remove unused check
  • Loading branch information
khaitruong922 authored Oct 14, 2024
1 parent 99d00d7 commit 26e843d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 84 deletions.
9 changes: 7 additions & 2 deletions ext/js/templates/anki-template-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ export class AnkiTemplateRenderer {
*/
_mergeTags(args) {
const [object, isGroupMode, isMergeMode] = /** @type {[object: import('anki-templates').TermDictionaryEntry, isGroupMode: boolean, isMergeMode: boolean]} */ (args);
/** @type {import('anki-templates').Tag[][]} */
const tagSources = [];
if (Array.isArray(object.termTags)) {
tagSources.push(object.termTags);
}
if (isGroupMode || isMergeMode) {
const {definitions} = object;
if (Array.isArray(definitions)) {
Expand All @@ -294,12 +298,13 @@ export class AnkiTemplateRenderer {
}
}
} else {
tagSources.push(object.definitionTags);
if (Array.isArray(object.definitionTags)) {
tagSources.push(object.definitionTags);
}
}

const tags = new Set();
for (const tagSource of tagSources) {
if (!Array.isArray(tagSource)) { continue; }
for (const tag of tagSource) {
tags.add(tag.name);
}
Expand Down
Loading

0 comments on commit 26e843d

Please sign in to comment.