Import a YiNote into Obsidian using Templater and DataView
- Use your own markdown template for importing your YiNotes
- Use oembed metadata in your template
- Download and save attached images to your vault
- Only attach images with certain keywords appearing in the note
import_example.mp4
- Copy
import_yinote.js
into yourscripts
folder* - Copy
yinote_template.md
into yourscripts
folder* - Copy
Import YiNote.md
into yourtemplates
folder*
*Your folders may have different names. Check your Templater settings (Template folder location
and Script files folder location
) and adjust accordingly. You also need to adjust some config options in Import YiNote.md
(see below for details).
- In your browser, open a new tab, click the YiNote icon and go to
Settings
- Click the
Export
button next toExport all data in JSON format
and save the JSON file - In Obsidian, create a new empty note. You don't need to set a title, the file will be renamed automatically
- Drag-and-drop the YiNote JSON file into the new note. The file will be automatically imported into your vault and linked in the new note
- Using Templater, insert the template
Import YiNote
(shortcut:CTRL+T
orCMD+T
) // todo: verify shortcut - Select a note from the list
- The importer script will now
- replace the content of the Obsidian note with the content of the selected YiNote using the template in
yinote_template.md
, - download metadata using oembed,
- download and save attached images,
- rename the note,
- move the JSON file in your vault to the trash.
- replace the content of the Obsidian note with the content of the selected YiNote using the template in
If that's the case, you need to adjust the following config options in Import YiNote.md
:
default_template_path
oembed_registry_path
See below on how to set the options.
The template used for creating the notes (found in yinote_template.md
) uses a syntax derived from Mustache.
To find the values that are available for utilization in your custom template, I recommend opening the developer console in Obsidian (CTRL+SHIFT+I
or CMD+ALT+I
) and importing a YiNote like documented above. In the console, you'll find a line yinote is ready for being inserted into the template:
followed by the object that's being used in the template.
Note: You can find full examples in the scripts folder in this repository.
For example, if you want to insert the meta.title
into your note, you'd write the following line in your template:
{{#meta}}{{title}}{{/meta}}
For the oembed.author_name
, you'd write:
{{#oembed}}{{author_name}}{{/oembed}}
Note: If the
oembed
key is not available, the whole section will be removed.
For the individual timestamped notes
, you could write:
{{#notes}}
### {{time}}
{{content}}
{{/notes}}
Note: Since
notes
is a list, this block will be repeated for each object of the list.
Depending on the provider, your demands on the template may vary. The metadata that's available to your template certainly will. You can set different template paths based on the provider in your Import YiNote.md
like so:
<%* tp.user.import_yinote({
tp: tp,
default_template_path: "scripts/yinote_template.md",
note_template_path_by_provider: {
"YouTube": "scripts/yinote_template_youtube.md",
"Vimeo": "scripts/yinote_template_vimeo.md"
}
}) _%>
In this example, there's a custom template for YouTube and Vimeo. All other providers will use the default template at yinote_template.md
.
YiNote creates still frames for all of your timestamped notes. Those images are available in notes[].image
(not showing the full mustache-like syntax for brevity) in base64 encoded form. It is possible, but highly discouraged to embed those base64 encoded images directly in your note, since your plain text file can easily bloat to up to several megabytes in size. Instead, you should use the _local
version of the image in your template, ie. notes[].image_local
. This way, the attached images will be saved to disk.
Note: By default, the images will be saved to your vault's root directory. You can change the location by adjusting the
images_directory
option accordingly (see the table below).
Note 2: Image URLs will be automatically downloaded if the local version is used in your template, ie. For
meta.image_local
oroembed.thumbnail_url_local
.
You may only want to attach a still frame for particular timestamped notes. You can do so by writing one of the keywords into your note, ie. screenshot
or still frame
.
Note: You can view and adjust the list of keywords using the
conditional_image_keywords
option, see the table below.
If there's one of the keywords present in your note, a notes[].conditional_image
object will be created like so:
In your template, embedding a frame only if there's a keyword present, could look like this:
{{#notes}}
### {{time}}
{{#conditional_image}}![frame]({{image_local}}){{/conditional_image}}
{{content}}
{{/notes}}
Note: If you want to attach images by default but treat the keyword list as a blacklist (for removing the image for particular notes), you can do so by setting the
conditional_image_keywords_is_blacklist
option totrue
(see table below). You may also want to adjust yourconditional_image_keywords
list to["noimage", "noscreenshot"]
or alike.
The script can use DataView and a value in your front matter block of your notes to find and ignore already existing notes. For this to work, DataView must be installed and there must be the following lines in the top of your template files:
---
yinote_id: {{id}}
---
Note: You can change the name of the key (
yinote_id
) using theyinote_id_frontmatter_key
config option (see table below).
Your Import YiNote.md
is the place to configure the importer script. It will look like this:
<%* tp.user.import_yinote({
tp: tp,
<key>: <value>
}) _%>
For <key>
and <value>
there are the following options:
key | Description |
---|---|
tp | (required) This is the templater instance and must always be included Example: tp |
default_template_path | The path of your default template. You only need to change this if your Templater scripts folder is not called scripts or if you rename yinote_template.md Default: "scripts/yinote_template.md" Example: "my_scripts_folder/default_yinote_template.md" |
note_template_path_by_provider | A 'list' of different templates based on the provider (see above for details). Default: {} Example: see above |
filename_template | The template to use for the new file name. This follows the same syntax as the templates. Default: "{{#meta}}{{provider}} - {{/meta}}{{#oembed}}{{author_name}} - {{/oembed}}{{#meta}}{{title}}{{/meta}}" |
make_images_available_offline | In your template, you can use the _local version of an image to make the image available offline. When setting this option to false , you disable this feature completely.Default: true |
images_directory | Save the attached images to this directory in your vault (directory must exist). Default: "" (your vault's root directory)Example: "resources/yinote" |
conditional_image_keywords | When any of this keywords appear in your note, create a conditional_image object (see above for details)Default: ["screenshot", "screen shot", "freeze frame", "still frame", "saveimage"] |
conditional_image_keywords_is_blacklist | Treat the keyword list above as a blacklist. A conditional_image object will be created by default but omitted if there's a keyword present.Default: false |
yinote_id_frontmatter_key | Search for this key in the frontmatter section of other notes for identifying already imported YiNotes (see above for details). Default: yinote_id |
custom_created_date_format | Create a createdAt_customformat string using this moment.js format.Default: "L LT" Example: "YYYY-MM" |
delete_json | Delete the drag-and-dropped JSON file after import? Default: true |
delete_permanently | Delete the JSON permanently (otherwise it will be moved to trash)? Only available, if delete_json is true .Default: false |
delete_only_if_all_imported | Delete the JSON only if all notes are imported? May come handy if you use scripts to further automate the import. Default: false |
oembed_registry_path | Cache the oembed registry at this path. You only need to change this if your Templater scripts folder is not called scripts. Default: "scripts/oembed_registry.json" |
oembed_registry_cache_days | Cache the oembed registry for this amount of days. Default: 7 |
loglevel | Increase/decrease the amount of messages logged to the developer console: 0: Silent 1: Error 2: Warning 3: Info 4: Debug Default: 3 |
The Filename Heading Sync plugin automatically changes the file name based on the first heading of the file (and vice-versa).
Since this script is based on Templater, you need to disable the Use File Open Hook in the settings.
If your file name does not match the heading, you need to add an Ignore Regex Rule that matches your filename_template
, ie. ^\+.*
for file names that start with a +
.
Also, until this bug is resolved, you need to add a Regex Rule that matches your default file name for new notes, ie. ^Untitled
. Both combined could look like ^Untitled|^\+.*
For bug reports, ideas for improvement or questions please open an issue. I'm also happy to receive pull requests if it doesn't contain breaking changes. It may also be favorable to discuss an issue before implementing anything mayor.