summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-05-17 20:18:37 -0400
committerGitHub <noreply@github.com>2021-05-17 20:18:37 -0400
commit76276e78dac387df66384a10bc1179c90ebd93fe (patch)
treeba11d7bf4375aa76ae45646b45953df9e71f1d78 /ext
parent12451eaf61281e588fb8ef5f911d604ba34aca92 (diff)
Expose search query to anki template renderer (#1686)
* Expose query and fullQuery to Anki context * Add {search-query} marker * Update test data * Update tests * Wrap search query in multiLine
Diffstat (limited to 'ext')
-rw-r--r--ext/data/templates/anki-field-templates-upgrade-v12.handlebars3
-rw-r--r--ext/data/templates/default-anki-field-templates.handlebars4
-rw-r--r--ext/js/data/anki-note-data-creator.js4
-rw-r--r--ext/js/data/options-util.js6
-rw-r--r--ext/js/display/display.js4
-rw-r--r--ext/js/pages/settings/anki-controller.js2
-rw-r--r--ext/js/pages/settings/anki-templates-controller.js4
-rw-r--r--ext/settings.html4
8 files changed, 26 insertions, 5 deletions
diff --git a/ext/data/templates/anki-field-templates-upgrade-v12.handlebars b/ext/data/templates/anki-field-templates-upgrade-v12.handlebars
new file mode 100644
index 00000000..9fe3c9d0
--- /dev/null
+++ b/ext/data/templates/anki-field-templates-upgrade-v12.handlebars
@@ -0,0 +1,3 @@
+{{#*inline "search-query"}}
+ {{~#multiLine}}{{context.fullQuery}}{{/multiLine~}}
+{{/inline}}
diff --git a/ext/data/templates/default-anki-field-templates.handlebars b/ext/data/templates/default-anki-field-templates.handlebars
index ec57a826..97359aa0 100644
--- a/ext/data/templates/default-anki-field-templates.handlebars
+++ b/ext/data/templates/default-anki-field-templates.handlebars
@@ -372,4 +372,8 @@
{{~/scope~}}
{{/inline}}
+{{#*inline "search-query"}}
+ {{~#multiLine}}{{context.fullQuery}}{{/multiLine~}}
+{{/inline}}
+
{{~> (lookup . "marker") ~}}
diff --git a/ext/js/data/anki-note-data-creator.js b/ext/js/data/anki-note-data-creator.js
index d1bbec18..4cf62788 100644
--- a/ext/js/data/anki-note-data-creator.js
+++ b/ext/js/data/anki-note-data-creator.js
@@ -141,9 +141,11 @@ class AnkiNoteDataCreator {
}
_getPublicContext(context) {
- let {documentTitle} = this._asObject(context);
+ let {documentTitle, query, fullQuery} = this._asObject(context);
if (typeof documentTitle !== 'string') { documentTitle = ''; }
return {
+ query,
+ fullQuery,
document: {
title: documentTitle
}
diff --git a/ext/js/data/options-util.js b/ext/js/data/options-util.js
index cb58206f..00ad890d 100644
--- a/ext/js/data/options-util.js
+++ b/ext/js/data/options-util.js
@@ -461,7 +461,7 @@ class OptionsUtil {
{async: false, update: this._updateVersion9.bind(this)},
{async: true, update: this._updateVersion10.bind(this)},
{async: false, update: this._updateVersion11.bind(this)},
- {async: false, update: this._updateVersion12.bind(this)}
+ {async: true, update: this._updateVersion12.bind(this)}
];
}
@@ -813,9 +813,11 @@ class OptionsUtil {
return options;
}
- _updateVersion12(options) {
+ async _updateVersion12(options) {
// Version 12 changes:
// Changed sentenceParsing.enableTerminationCharacters to sentenceParsing.terminationCharacterMode.
+ // Added {search-query} field marker.
+ await this._applyAnkiFieldTemplatesPatch(options, '/data/templates/anki-field-templates-upgrade-v12.handlebars');
for (const profile of options.profiles) {
const {sentenceParsing} = profile.options;
sentenceParsing.terminationCharacterMode = sentenceParsing.enableTerminationCharacters ? 'custom' : 'newlines';
diff --git a/ext/js/display/display.js b/ext/js/display/display.js
index 7bfe3add..fe5b5c9a 100644
--- a/ext/js/display/display.js
+++ b/ext/js/display/display.js
@@ -1400,7 +1400,9 @@ class Display extends EventDispatcher {
return {
url,
sentence,
- documentTitle
+ documentTitle,
+ query: this._query,
+ fullQuery: this._fullQuery
};
}
diff --git a/ext/js/pages/settings/anki-controller.js b/ext/js/pages/settings/anki-controller.js
index 91cd4641..28bb21a3 100644
--- a/ext/js/pages/settings/anki-controller.js
+++ b/ext/js/pages/settings/anki-controller.js
@@ -101,6 +101,7 @@ class AnkiController {
'pitch-accent-positions',
'reading',
'screenshot',
+ 'search-query',
'sentence',
'tags',
'url'
@@ -119,6 +120,7 @@ class AnkiController {
'kunyomi',
'onyomi',
'screenshot',
+ 'search-query',
'sentence',
'stroke-count',
'tags',
diff --git a/ext/js/pages/settings/anki-templates-controller.js b/ext/js/pages/settings/anki-templates-controller.js
index eab0681f..9502a2fd 100644
--- a/ext/js/pages/settings/anki-templates-controller.js
+++ b/ext/js/pages/settings/anki-templates-controller.js
@@ -161,7 +161,9 @@ class AnkiTemplatesController {
text: sentenceText,
offset: 0
},
- documentTitle: document.title
+ documentTitle: document.title,
+ query: sentenceText,
+ fullQuery: sentenceText
};
let template = options.anki.fieldTemplates;
if (typeof template !== 'string') { template = this._defaultFieldTemplates; }
diff --git a/ext/settings.html b/ext/settings.html
index 1b167e22..aade3345 100644
--- a/ext/settings.html
+++ b/ext/settings.html
@@ -2878,6 +2878,10 @@
<td>Screenshot of the web page taken at the time the term or kanji was added.</td>
</tr>
<tr>
+ <td><code class="anki-field-marker">{search-query}</code></td>
+ <td>The full search query shown on the search page.</td>
+ </tr>
+ <tr>
<td><code class="anki-field-marker">{sentence}</code></td>
<td>Sentence, quote, or phrase that the term or kanji appears in from the source content.</td>
</tr>