aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-15 17:32:31 -0400
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-04-06 18:20:04 -0400
commit4011a091b69475e7096d80103b4dad9aa1b8d80b (patch)
tree2dcf382cd6161114e53c6bbf5c3b9545d007f8c6
parent059db280bba858a3cab3a542aef13f19737aaf6e (diff)
Add support for {document-title}
-rw-r--r--README.md2
-rw-r--r--ext/bg/data/default-anki-field-templates.handlebars4
-rw-r--r--ext/bg/js/options.js9
-rw-r--r--ext/bg/js/settings/anki-templates.js6
-rw-r--r--ext/mixed/js/display.js6
5 files changed, 25 insertions, 2 deletions
diff --git a/README.md b/README.md
index 631f5a8b..bf217679 100644
--- a/README.md
+++ b/README.md
@@ -156,6 +156,7 @@ Flashcard fields can be configured with the following steps:
`{cloze-prefix}` | Text for the containing `{sentence}` from the start up to the value of `{cloze-body}`.
`{cloze-suffix}` | Text for the containing `{sentence}` from the value of `{cloze-body}` to the end.
`{dictionary}` | Name of the dictionary from which the card is being created (unavailable in *grouped* mode).
+ `{document-title}` | Title of the web page that the term appeared in.
`{expression}` | Term expressed as Kanji (will be displayed in Kana if Kanji is not available).
`{furigana}` | Term expressed as Kanji with Furigana displayed above it (e.g. <ruby>日本語<rt>にほんご</rt></ruby>).
`{furigana-plain}` | Term expressed as Kanji with Furigana displayed next to it in brackets (e.g. 日本語[にほんご]).
@@ -175,6 +176,7 @@ Flashcard fields can be configured with the following steps:
`{cloze-prefix}` | Text for the containing `{sentence}` from the start up to the value of `{cloze-body}`.
`{cloze-suffix}` | Text for the containing `{sentence}` from the value of `{cloze-body}` to the end.
`{dictionary}` | Name of the dictionary from which the card is being created.
+ `{document-title}` | Title of the web page that the Kanji appeared in.
`{glossary}` | List of definitions for the Kanji.
`{kunyomi}` | Kunyomi (Japanese reading) for the Kanji expressed as Katakana.
`{onyomi}` | Onyomi (Chinese reading) for the Kanji expressed as Hiragana.
diff --git a/ext/bg/data/default-anki-field-templates.handlebars b/ext/bg/data/default-anki-field-templates.handlebars
index 0442f7c5..6061851f 100644
--- a/ext/bg/data/default-anki-field-templates.handlebars
+++ b/ext/bg/data/default-anki-field-templates.handlebars
@@ -158,4 +158,8 @@
<img src="{{definition.screenshotFileName}}" />
{{/inline}}
+{{#*inline "document-title"}}
+ {{~context.document.title~}}
+{{/inline}}
+
{{~> (lookup . "marker") ~}} \ No newline at end of file
diff --git a/ext/bg/js/options.js b/ext/bg/js/options.js
index 5c68c403..abb054d4 100644
--- a/ext/bg/js/options.js
+++ b/ext/bg/js/options.js
@@ -91,6 +91,15 @@ const profileOptionsVersionUpdates = [
if (utilStringHashCode(options.anki.fieldTemplates) === 1444379824) {
options.anki.fieldTemplates = null;
}
+ },
+ (options) => {
+ // Version 13 changes:
+ // Default anki field tempaltes updated to include {document-title}.
+ let fieldTemplates = options.anki.fieldTemplates;
+ if (typeof fieldTemplates === 'string') {
+ fieldTemplates += '\n\n{{#*inline "document-title"}}\n {{~context.document.title~}}\n{{/inline}}';
+ options.anki.fieldTemplates = fieldTemplates;
+ }
}
];
diff --git a/ext/bg/js/settings/anki-templates.js b/ext/bg/js/settings/anki-templates.js
index 88bca024..e3852eb4 100644
--- a/ext/bg/js/settings/anki-templates.js
+++ b/ext/bg/js/settings/anki-templates.js
@@ -99,7 +99,11 @@ async function ankiTemplatesValidate(infoNode, field, mode, showSuccessResult, i
const definition = await ankiTemplatesValidateGetDefinition(text, optionsContext);
if (definition !== null) {
const options = await apiOptionsGet(optionsContext);
- const context = {};
+ const context = {
+ document: {
+ title: document.title
+ }
+ };
let templates = options.anki.fieldTemplates;
if (typeof templates !== 'string') { templates = await apiGetDefaultAnkiFieldTemplates(); }
const ankiNoteBuilder = new AnkiNoteBuilder({renderTemplate: apiTemplateRender});
diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js
index ecf92013..646d60e7 100644
--- a/ext/mixed/js/display.js
+++ b/ext/mixed/js/display.js
@@ -935,7 +935,11 @@ class Display {
}
_getNoteContext() {
- return {};
+ return {
+ document: {
+ title: document.title
+ }
+ };
}
async _getAudioUri(definition, source) {