Space-Script: Daily Quote

If you’re from Obsidian and have used the Templater plugin, you may have utilised the tp.web.dailyquote() module to pull a daily quote into your journal etc.

I quickly knocked up the following space-script to bring that functionality into SB using the same Quotables API as Templater:

silverbullet.registerFunction({name: "dailyQuote"}, async () => {

const quoteAPI = 'https://api.quotable.io/quotes/random';
const response = await fetch(quoteAPI);

if (!response.ok) {
  throw new Error('Failed to fetch quote');
}

const data = await response.json();
const quoteData = Array.isArray(data) ? data[0] : data;

if (quoteData.content && quoteData.author) {
  const quote = quoteData.content;
  const author = quoteData.author;
  const formattedQuote = `${quote}\n> — ${author}`;
  return formattedQuote;
} else {
  throw new Error('No quote in response');
}
})

I then use a custom admonition borrowed from the Additional Admonition Types post, to insert it into my daily journal template.

> **quote** Today's Quote
> {{dailyQuote}}

The script uses the random endpoint to select from the entire Quotables database. If you’d only like to see specific tags, update const quoteAPI to reduce the scope, for example: /quotes/random?tags=technology,famous-quotes.

I am bumbling my way through this as I’m not a developer, so if there is something to improve, do let me know.

4 Likes

So, Quotables is all sorts of broken at the moment (has been for weeks) and the dev is MIA. Instead of spinning up my own instance, I decided to learn a thing and build a PLUG using the Quoteables quote data.

All the quotes have tags (listed in the README) and you can include/exclude tags as needed by defining them in SETTINGS. You do have to be a bit hacky and use a space-script to call the PLUG in a template, but hey, it works.

I’ve also never written typescript before, so please forgive any horrid code.

2 Likes