Tutorial: How to Create a Bookshelf in Obsidian.md

How to Create a Bookshelf in Obsidian

This is a tutorial on how to create a book library or database in Obsidian.md. The guide also shows you how to use the Dataview, Templates, and Quick Add plugins.

Update History

  • 04/05/2022: Added a new optional feature (inline dataview query language) and updated the sample vault in Github
  • 01/09/2022: Added a new optional feature (list of read books) and the sample vault
  • 09/04/2021: Added the optional Obsidian Banners plugin
  • 08/23/2021: Added a new optional feature

Things Needed


  • Obsidian
    • Templates (Core Plugin)
    • Dataview (Community Plugin)
    • QuickAdd (Community Plugin)

How to Install the Community Plugins


  1. Click on the Settings button in Obsidian. You can find it in the bottom-left corner.
  2. Go to the Community Plugins tab and turn off Safe Mode to enable plug-in installation.
  3. Click on Browse and type “Dataview“ on the search form.
  4. Click on the Install button and the Enable button. Repeat steps 3 and 4 to install QuickAdd.

How to Create a Book Note using a Template


Screenshot of the book template

Templates are used to automatically fill in the content for your note.

  1. Create a folder called _templates. This will house the templates used for your book notes.
  2. Click on the Settings button on the bottom left corner and select Core Plugins. Turn on Templates to enable this plugin.
Templates plugin in the Core plugins menu
  1. Look for Templates under Plugin Options.
  2. Set the template folder location to _templates.
  1. Create a new note and name it “Book Template”. Type the following on the top of the note:
---
Alias:
Author:
Status:
ISBN:
Cover:
---
💡 What you have just added is called a YAML frontmatter. This is a type of custom metadata that you can put in your notes and it will be used by the Dataview plugin to display your books. You can use it to sort your books by author for example. Note that this frontmatter is hidden when viewed in Preview mode.

Here is an explanation for each YAML frontmatter:

  • Alias:
    • This is an optional metadata you can put if a book has an alternate title. For example, you can put Divina Commedia as an alias for The Divine Comedy, the original Japanese title for a manga, or the full title of a non-fiction book.
  • Author:
    • This is where you put the author of the book. If the book has a translator (in the case for classics or international books) put [Author, Translator].
  • Status:
    • This is where you put if the book is filed under “unread”, “currently reading” and “read”.
  • ISBN:
    • An optional metadata if you want to include the book’s ISBN.
  • Cover:
    • This is where you put the cover of the book. I recommend adding a URL of the picture for it to work. The downside of this method is that you cannot view the image offline.

After creating the template, we can now use it to generate a new book note using the QuickAdd plugin.

How to Add a New Book Note using QuickAdd


QuickAdd command to add a new book

QuickAdd is a plugin that lets you quickly add templates and new content to your vault. Using this plugin allows you to add a new book note from the command palette instead of adding a new note, applying the template, and moving it to the folder (saving you three or more clicks!)

Setting Up QuickAdd

  1. Go to Settings and look for QuickAdd under the Plugin Options.
  1. On the textbox, add a name for the command (I used “Add New Book”) and then click Add Choice.
  1. Click on the gear icon to open up the settings of the Add New Book command.
  1. On Template Path, select the Book Template you just made.
  1. Turn on the Create in folder button and select the folder location of the books (Make sure to add a folder in your vault first!). Press the Add button to confirm.
  1. Optional: Click the toggle on the Open and New Tab settings if you want QuickAdd to open up the newly added book in either a vertical or horizontal tab.
  1. Optional: Click on the lightning bolt icon to add a shortcut to this command on the Command Palette.

How to Use QuickAdd

Once you’ve set up the QuickAdd command, open the Command Palette (or press Ctrl + P) and type QuickAdd. Select the Add New Book command.

A new window will pop up after clicking on the Add New Book command. Type the name of the book and QuickAdd will automatically create a new note with the Book Template applied.

From here, you can add the metadata for the book.

How to Create the Book Library using Dataview


The library note in Edit and Preview mode

In this section, I’ll explain how to use the Dataview plugin to display a list of your books in the Book Library note.

  1. Create a new note called Library. Make sure to put the note outside of the Books folder.
  2. Add the following Dataview code below in the Library note:

Here is a line by line explanation:

  • table Author, ("![coverimg|100](" + Cover + ")") as Cover
    • This tells the Dataview plugin to create a table with the following rows: author and the book cover.
  • from "Books"
    • This tells the Dataview plugin to specifically display the contents from the Books folder.

Add Optional Features


Create a Book Tracker

You can also use the Dataview plugin to create a book tracker to sort the books according to their status.

Add the following Dataview code below in your Library note:

Here is a line by line explanation:

  • table rows.file.link as Book
    • This tells the Dataview plugin to create a table with the row called ‘Book’ to display the files.
  • from "Books"
    • This tells the Dataview plugin to specifically display the contents from the Books folder.
  • group by Status
    • This will group the contents from the Books folder according to their Status metadata.
  • sort Status
    • This sorts the table according to Status. This only works if there are books with multiple statuses (unread, read, currently reading).

Add Lines on a Dataview Table

Add a line per entry in a Dataview table

If you want to add a line in between each entry on a Dataview table, you can use the following CSS Snippet:

.table-view-table tr {
    border-bottom: 1px solid;
}
💡If you want to change the thickness of the lines, change the number on the border-bottom field. I use 0.5px on my vault as an example.

To add this to Obsidian, open Notepad and copy-paste the snippet. Save the document as a .css file and move it to the snippets folder (Vault Name -> .obsidian -> snippets).

If the snippets folder is missing, go to your Settings and select Appearance. Under CSS Snippets, click on the folder icon for Obsidian to create the snippets folder automatically.

Click on the folder icon if the snippets folder is missing

After adding it to the snippets folder, open Settings in Obsidian and select Appearance. Under CSS Snippets, click on the refresh icon to reload the snippets and click the toggle to enable it.

Add a Top Banner

An example top banner in a library note

If you want to add a top banner to your Library (just like in Notion pages) you can either add a local image (a picture from your attachments folder) or link an image online.

For local images, add ![[Top Banner Image.png]]. To add an image from the Internet, add ![Banner](Image URL). Use the following dimensions: 1500px x 300px to match the size of the image shown above.

Optional: Install the Obsidian Banners Plugin

You can also use the Obsidian Banners plugin to add a top banner using a local image or an image from the internet.

Install the plugin from the Community Plugins and add the following on top of the Library note:

---
banner:
---

If you want to add an image from the Internet, simply add the image’s URL. See the example code below:

---
banner: https://images.unsplash.com/photo-1519052537078-e6302a4968d4?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1050&q=80
---

For local images, press Ctrl + P, type Add Local Image, and select Banners: Add/Change banner with local image.

Type the name of the image you want to use as a banner and press enter.

Once you have a banner in place, you can click and hold the image to reposition it. This adds banner_x and banner_y in the YAML frontmatter. You can manually input the number or reposition the image to change the numbers.

Repositioning the banner adds two fields (banner_x and banner_y) in the YAML frontmatter

Sort Books in Alphabetical Order

Three books in alphabetical order in the Library note

If you want to sort multiple books in alphabetical order, add the following in your Dataview code:

sort file.name asc

Display a Specific Book Based on Its Type

If you want to display a specific type of book (like books about fitness), you can add the Type: YAML frontmatter on the book note.

A book note with the Type: Fitness on the YAML frontmatter

Once you have added the frontmatter, go back to your Library note and add the following in your Dataview code:

where Type = "Fitness"

This code will tell Dataview to only display books that are listed with “Fitness” on their Type.

Display Books with Multiple Types

If you have added multiple values on the Type frontmatter (like Type: [Fiction, Sci-Fi]) and only want to specify one, add the following in your Dataview code:

where contains(Type, "Sci-Fi")

This will tell Dataview to display books that contains Sci-Fi on their Type. It will not display any books that only have Fiction or [Fiction, Other Genre] on the table.

Create a List of Read Books

A list of books read in 2021

If you want to display a list of books that you have read in a year, add the Date-Read YAML frontmatter on the book note.

A book note with the Date-Read: 2021-04-09 on the YAML frontmatter

Go to your Library note and add the following Dataview code:

The Dataview code used to display a list of read books in 2022.

Here is a line by line explanation:

  • table rows.file.name as Book
    • This tells the Dataview plugin to create a table with the row called ‘Book’ to display the files.
  • from "Library/Books"
    • This tells the Dataview plugin to specifically display the contents from the Books folder.
  • where Status = "Read" and Date-Read >= date(2022-01-01) AND Date-Read <=date(2022-12-31)
    • This tells the Dataview plugin to only display books with Read on the Status and with the year 2022 on the Date-Read.
  • group by Date-Read
    • This will group the books according to their Date-Read metadata.
  • sort Date-Read asc
    • This will sort the Date-Read data in ascending order.

Display the YAML Values in Your Note

The book note in both Editing Mode and Reading Mode. The Metadata list displays the YAML frontmatter values via an inline dataview query language.

You can use an inline dataview query language (DQL) to display the values that you have added in the YAML frontmatter of your book note without manually copying them over.

The format for this code looks like this:

Using this code allows you to view the YAML values in Reading Mode. In addition, if you make any changes to the YAML frontmatter, such as changing the Status to “Read”, the inline code will auto-update to match the value.

Download the Sample Vault


The sample Bookshelf vault containing all files and folders

I have created a sample vault of this bookshelf that includes all the files, folders, plugins, and optional features. You can find it in this Github link.

To download and open the vault in Obsidian, follow the instructions below:

  1. Click on this Github link to take you to the download link.
  2. Select the latest version of the ObsidianBookshelf.zip file and download it to your computer.
  3. Unzip the file.
  4. On Obsidian, click on the vault icon and press the Open button.
  5. Select the Bookshelf folder to open it as a vault in Obsidian.

Credits


13 comments

  1. I have entered exactly what was listed above, but the table leaves all of the content (Auther, Cover, etc.) blank.

    Like

      1. Hi Cobbi, have you checked if there’s a “Metadata Invalid” message that appears on top of your note if you are viewing it in Reading Mode? If there’s one, then it means that the format on your YAML is incorrect.

        If not, then I think Dataview may not be loading the YAML frontmatter data properly. You can close and open Obsidian again and hopefully, this will fix the issue. Sometimes the 0 queries thing happens to me if I sync my vault from desktop to mobile device and restarting Obsidian fixes it.

        Like

  2. Thank you, I’ve been using your library system for a while and recently I wanted to add links of other pages to book pages. I have both book pages and author pages and I want to reach the author page by clicking on the name of the author in the table display just like it functions with the book names under the “File” column. When I insert the link in the metadata section such as [[J. R. R. Tolkien]], I saw that both in the table view and in the YAML frontmatter section, they don’t function as links. It’s just that in the table display that we created with dataview plugin, there are two bullet points preceding the name of the author and I cannot click it.

    Briefly, is there any way that we can insert links with double brackets into the metadata section and view them in the table view just like we can click the name of the book and go directly to the page of that book? Hopefully, I could explained myself.

    Like

    1. Hi Harun, if I understand your question right, you can add the double brackets inside the values in the YAML frontmatter section.

      The format goes like this for books with one author:
      Author: [[J. R. R. Tolkien]]

      For books with two or more authors, you can format it like this:
      Author:"[[Thomas Mallory]], [[Helen Cooper]], [[Author 3]], [[Author 4]]"

      After adding the double brackets, go back to your Library note and check to see if the Author names appear as links. Please check this screenshot as an example.

      Please let me know if this answers your question!

      Liked by 1 person

      1. Thank you for the quick reply.

        After adding the quotation marks outside of double brackets, it worked!

        But what I didn’t understand is why we need to add quotation marks. Is this a special requirement for YAML in order to establish a link? I have so limited knowledge of coding, that’s why I’m asking out of curiosity.

        This has helped very well, thanks again. Love your blog!

        Like

      2. I think adding the quotation marks allows us to use special characters in the YAML front matter and a way for Obsidian to interpret that the authors we’ve indicated are separate links.

        Normally you can indicate multiple authors using this format (without using the double brackets):
        Author: [Thomas Mallory, Helen Cooper]

        However, if we want to add links to those authors by using the double brackets [[]] that’s when it will cause an error since those brackets are already being used to group the two values on the Author: field. Adding the quotation marks fixes it.

        I hope this explains things clearly. I don’t have much coding experience as well aside from testing stuff out in Obsidian.

        Like

  3. Thanks so much for this tutorial!
    Fwiw, I had the same issue of wanting author’s names to be linked, and I discovered completely by accident that if you indicate the author (or any attribute) outside of the YAML frontmatter but using a double colon, then it will be picked up by Dataview and show up in the table. So, in this example:


    Alias: Divina Commedia
    Status: Unread
    ISBN: 978-0451208637
    Cover: https://images-na.ssl-images-amazon.com/images/I/91096cQuABL.jpg

    Author:: [[Dante Alighieri]], [[John Ciardi]]

    Note the author tag outside the bottom line and followed by two colons. Both author and translator names are linked with double brackets as usual in Obsidian. Both will be clickable from the Dataview table and from the book note itself.

    Thanks again!

    Like

    1. Nice, thank you for sharing! I actually use the same double colon method to add links on my notes so they show up when displayed in a Dataview table like this:

      Link:: [Divine Comedy - Wikipedia](https://en.wikipedia.org/wiki/Divine_Comedy)

      For my book notes, I still put the Author in the YAML frontmatter but I use an inline dataview query language (DQL) to display what’s written on the frontmatter to the book note. You can use the following code to do this:

      • Author: = this.Author <- add a backtick (') at the start and end of the code for it to work

      This method works best for YAML frontmatter fields that don’t use internal links [[like this]] since it doesn’t work.

      Liked by 1 person

  4. Many thanks for creating and sharing the guide.

    Here are some queries that other people might like to add to their templates.

    On the page for each author, the following query creates a list of all the books written by the named author (for this to work, the author’s name has to be the file name):

    TABLE WITHOUT ID
    ("![coverimg|100](" + cover +")") AS Cover,
    file.link AS "Title"
    FROM
    "books"
    WHERE
    author = this.file.link

    And on the same author pages, this query creates links to all the author pages in the library (this is useful for speedy navigation between books and authors):

    TABLE WITHOUT ID
    author AS Author
    FROM
    "books"
    SORT
    author ASC
    GROUP BY
    author

    Also for speedy navigation I add a similar query to the bottom of each book page, but adding authors and books:

    TABLE WITHOUT ID
    author AS Author,
    file.link AS Book
    FROM
    "books"
    SORT
    author ASC
    title ASC

    On the individual book pages, this query loads the cover for the specific book:

    TABLE WITHOUT ID
    ("![coverimg|90](" + cover +")") AS Cover
    FROM
    "books"
    WHERE
    file.name = this.file.name

    The top of each page looks like this:

    = this.title

    by = this.author
    “`dataview
    TABLE WITHOUT ID
    (“”) AS Cover
    FROM
    “books”
    WHERE
    file.name = this.file.name

    ““

    Thanks, again.

    Angel

    Liked by 1 person

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: