skip to content
Jakob Osterberger

Collect quotes from your Obsidian notes

/ 3 min read

Last Updated:

How to create a collection of quotes from your notes

Quotes are all over the place in every other note in my vault. In this post we will explore how one can pull these quotes out of our notes into a collection and display them in a nice formated list. The only requirement for this is to install the dataview plugin and activate the “dataview js” option in the plugin settings.

Formating & structuring quotes

At first we need to make sure that our Quotes have a certain structure that we can read with our dataview script. A quote should look like the following in your notes:

[quote text] - [Author] #common/tag

So a quote could be like this example:

> I am some really inspirational quote - Herbert Einstein #quote

or

I am another really inspirational quote - August Einstein #quote

The quote can also be part of a callout, that’s just fine as long as all the quotes text is inside one block / on one line.

The imporant thing is that the quote has a common tag in the end that is shared by all the quotes in your vault. This tag is necessary to collect them with dataview.

The Quotes Note data fields

Create a “Quotes.md” note and make sure that your “Quotes” Collection Note has the following dataview fields:

searchtag:: #quote  
searchterm::

The searchtag field is used to tell dataview which notes to collect (put the common quote tag there), the searchterm field can be used to filter the notes additonally.

The Dataview code necessary


 /**  
 * List quotes 
 * URL: https://www.reddit.com/r/ObsidianMD/comments/rgoch0/transclude_entire_blocks_from_other_pages_via/?utm_medium=android_app&utm_source=share 
 */
let searchtag = dv.current().searchtag;
let searchterm = dv.current().searchterm;
const pagesWithQuotes = await Promise.all(  
    dv  
        .pages((searchtag ?? "#quote") + (searchterm ?? ''))
		.where(p => p.file.name != dv.current().file.name)
        .map(pageWithQuote => new Promise(async (resolve, reject) => {  
            const content = await dv.io.load(pageWithQuote.file.path);  
 resolve({  
                link: pageWithQuote.file.link,  
 content  
            });  
 }))  
);  
dv.paragraph(`Number of found Pages: ${pagesWithQuotes.length}\n\n---`);
// Create an array of pages containing quotes,  
// where each page is:  
// {  
//   quotes: [], // array of quotes  
//   link: { path: '' } // Link  
// }  
let number = 0;
const quotesByPage = pagesWithQuotes.map(({  
    link,  
 content  
}) => ({  
    link,  
 quotes: content  
        // Split into paragraphs  
 .split('\n')  
  
        // Get only paragraphs that have the #quote tag  
 .filter(content => content.includes(searchtag))  
  
        // Remove the "#quote" tag from each quote string  
 .map(content => content.replace(searchtag, ''))  
}));  
quotesByPage.forEach(  
    page =>  
    page.quotes.forEach(  
        quote => {
			number++;
			let string = `${page.link} | \n ${quote}`;
			dv.paragraph(string.replaceAll('>', ''));  
		}
    )  
);
dv.paragraph(`---\nNumber of found Qoutes: ${number}`);

The output should look like this: Quotes Collection v1

Alternative version using Obsidian native embedded queries

To create a collection of all your notes you can also use the Obsidian native embedded queries feature in combination with the “Better Search Views” plugin. This is a lot easier and does not require the dataview. The “Better Search Views” plugin is necessary to display the full quote content and it will also beautifully render callouts.

Here is the code for the embedded query:

tag:#quote

To learn more about embedded queries check out the official Obsidian docs.

The output should look like this: Quotes Collection v2

The complete notes for you to copy


Jakob's Newsletter

Stay updated about my latest ideas, thoughts, journeys and projects. I'll send you the best of what I discover on the internet, what I've learned, and what I'm working on.

No spam, ever. Unsubscribe at any time.

Powered by Buttondown.

Enjoying the content?

Buy Me a Coffee at ko-fi.com