Skip to content

fkuersch/obsidian-import-yinote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

obsidian-import-yinote

Import a YiNote into Obsidian using Templater and DataView

Features

  • 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

Setup

Requirements

  1. Install Templater
  2. Install DataView (optional, used for identifying already imported notes)

Install importer script

  1. Copy import_yinote.js into your scripts folder*
  2. Copy yinote_template.md into your scripts folder*
  3. Copy Import YiNote.md into your templates 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).

Importing your first note

  1. In your browser, open a new tab, click the YiNote icon and go to Settings
  2. Click the Exportbutton next toExport all data in JSON format and save the JSON file
  3. In Obsidian, create a new empty note. You don't need to set a title, the file will be renamed automatically
  4. 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
  5. Using Templater, insert the template Import YiNote (shortcut: CTRL+T or CMD+T) // todo: verify shortcut
  6. Select a note from the list
  7. The importer script will now
    1. replace the content of the Obsidian note with the content of the selected YiNote using the template in yinote_template.md,
    2. download metadata using oembed,
    3. download and save attached images,
    4. rename the note,
    5. move the JSON file in your vault to the trash.

Configuration

In my Templater settings, Script files folder location is not called scripts

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.

Creating your own note template

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.

devconsole_example.png

Template examples

Note: You can find full examples in the scripts folder in this repository.

For example, if you want to insert the meta.titleinto 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 oembedkey is not available, the whole section will be removed.

For the individual timestamped notes, you could write:

{{#notes}}
### {{time}}
{{content}}
{{/notes}}

Note: Since notesis a list, this block will be repeated for each object of the list.

Using different templates based on the provider (YouTube, Twitch, Vimeo, Twitter, ...)

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.

Saving images to disk

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 _localversion 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 or oembed.thumbnail_url_local.

Only attach image if there's a keyword in the note

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. screenshotor 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:

conditional_image_example.png

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_blacklistoption to true (see table below). You may also want to adjust your conditional_image_keywords list to ["noimage", "noscreenshot"] or alike.

Ingore already imported notes

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 the yinote_id_frontmatter_keyconfig option (see table below).

All configuration options

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 _localversion 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_imageobject (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_imageobject 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_jsonis 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

Compatibility with other plugins

Filename Heading Sync

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|^\+.*


Contributing

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.

About

Import a YiNote into Obsidian using Templater

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published