Published

February 20, 2025

Options for creating Vaults

The Vault type represents the contents of an Obsidian vault, which is simply a directory tree of Markdown files. We’ve defined a variable repo with the value of the root directory of this repository, and will use a sample vault with a notes about a couple of U.S. Presidents. It has 13 notes altogether.

using Obsidian
vaultdir = joinpath(repo, "test", "data", "presidents-vault")
v = Vault(vaultdir)
"Obsidian vault with 13 notes"
A shorthand

The Vault constructor assumes a default value of the current working directory for the root of the Obsidian vault, so if you’re working in the root directory of your Obsidian vault, you can omit the path value and achieve the same result:

cd(vaultdir)
impliedvault = Vault()
"Obsidian vault with 13 notes"

Omitting parts of your vault

To exclude material when reading the contents of the Obsidian vault, use the optional omit parameter with a list of file or directory names. The default value of the omit parameter is [Templates], a directory for configuring Obsidian’s templating system rather than for keeping data. Here we’ll add the name of a subdirectory that has a single file in it.

v2 = Vault(vaultdir; omit = ["Templates", "census-districts"])
"Obsidian vault with 12 notes"

Omitting dataview’s metadata tags

By default, the Vault type includes an index of dataview key-value properties. You retrieve all of the key-value properties in the vault with the kvtriples function, grouping together the page’s wikiname, the key and the value. There are 17 such properties in the example vault.

kvtriples(v)
17-element Vector{NoteKV}:
 NoteKV("Springfield, Sangamon, Illinois", "geo", Dict{Any, Any}[Dict("lon" => "39°47′58″"), Dict("lat" => "89°39′18″")])
 NoteKV("Springfield, Sangamon, Illinois", "admin", Dict{Any, Any}[Dict("state" => "Illinois"), Dict("county" => "Sangamon"), Dict("town" => "Springfield")])
 NoteKV("Abraham Lincoln 1860 census", "Refersto", "[[Abraham Lincoln]]")
 NoteKV("Abraham Lincoln 1860 census", "Enumeration", "[[Springfield, Sangamon, Illinois]]")
 NoteKV("Abraham Lincoln 1860 census", "Date", "1860-07-14")
 NoteKV("Abraham Lincoln 1860 census", "House", "1002")
 NoteKV("Abraham Lincoln 1860 census", "Family", "989")
 NoteKV("Abraham Lincoln 1860 census", "Name", "Abraham Lincoln")
 NoteKV("Abraham Lincoln 1860 census", "Age", "51")
 NoteKV("Abraham Lincoln 1860 census", "Sex", "M")
 NoteKV("Abraham Lincoln 1860 census", "Occupation", "Sawyer")
 NoteKV("Abraham Lincoln 1860 census", "Real estate value", "5000")
 NoteKV("Abraham Lincoln 1860 census", "Personal estate value", "12000")
 NoteKV("Abraham Lincoln 1860 census", "Birthplace", "Ill.")
 NoteKV("Abraham Lincoln", "sequence", "16")
 NoteKV("Abraham Lincoln", "hiddensequence", "16")
 NoteKV("yamltest", "obj", Dict{Any, Any}("key2" => 3, "key3" => ["List1", "List2", "List3"], "key1" => "Val"))

If you prefer to exclude dataview indexing, use the dataview parameter with a value of false. When dataview indexing is turned off, kvtriples returns a value of nothing.

v3 = Vault(vaultdir; dataview=false)
kvtriples(v3) |> isnothing
true
Caution

Omtting the Templates directory should have no side effects, but if you omit files or directories that other notes link to, the links will fail in the resulting Markdown.