I checked out the plugin Review and it’s interesting, but it means I would have to manually touch every quote file, which would be painful. I can use a bash script to quickly generate the Markdown files and the hope is that I should be able just to find the one I need when I need it.
I’ve opted to try and learn Templater and DataviewJS.
I figured I might as well learn something new and it looks like for a first timer I got something working.
My test notes have the following YAML:
---
attribution: W. C. Fields
comments:
quoteCategory: Humor
quoteTitle: "Try, try, try again..."
quoteText: "If at first you don't succeed, try, try again. Then quit. No use being a damn fool about it."
source: Unknown
subject: Persistence
surfaceDayOfYear: 152
url:
---
---
attribution: "Anonymous"
comments:
quoteCategory: Humor
quoteTitle: "A Funny Quote"
quoteText: "Laughter is the best medicine."
source: Unknown
subject: Persistence
surfaceDayOfYear: 152
---
The following dataview code block finds all notes that have a quoteCategory of “Humor” and a surface day of today. It can be modified for different categories or none just to get all of the quotes of the day.
dataviewjs
const currentDate = new Date();
const start = new Date(currentDate.getFullYear(), 0, 0);
const diff = currentDate - start;
const oneDay = 1000 * 60 * 60 * 24;
const currentDayOfYear = Math.floor(diff / oneDay);
// Perform the Dataview query
dv.table(
["quoteTitle", "quoteCategory", "quoteText", "attribution", "surfaceDayOfYear"],
dv.pages()
.where(p => p.surfaceDayOfYear == currentDayOfYear && p.quoteCategory == "Humor")
.map(p => [p.quoteTitle, p.quoteCategory, p.quoteText, p.attribution, p.surfaceDayOfYear])
);
The following Templater code will find any note with the surfaceDayOfYear of today (current day of the year (1-366)) with a quoteCategory of “Humor”, “Inspiration”, or “Wisdom” (these can be changed or added to as desired) and add the quotes in separate quote callouts in the current note. There’s a lot of calls to log results in the console as I was testing.
<%*
const currentDate = new Date();
const start = new Date(currentDate.getFullYear(), 0, 0);
const diff = currentDate - start;
const oneDay = 1000 * 60 * 60 * 24;
const currentDayOfYear = Math.floor(diff / oneDay);
console.log(`Current Day of Year: ${currentDayOfYear}`);
const quoteCategories = ["Humor", "Inspiration", "Wisdom"];
const quotes = {};
const dv = app.plugins.plugins["dataview"].api;
for (const category of quoteCategories) {
const query = `
TABLE without id quoteTitle, quoteCategory, quoteText, attribution, surfaceDayOfYear
WHERE surfaceDayOfYear = ${currentDayOfYear} AND quoteCategory = "${category}"
`;
console.log(`Running query for category: ${category}`);
console.log(query);
const categoryQuotes = await dv.query(query);
console.log(`Results for category ${category}:`, categoryQuotes);
if (categoryQuotes && categoryQuotes.value && categoryQuotes.value.values.length > 0) {
// Extract the first result
const firstQuote = categoryQuotes.value.values[0];
quotes[category] = {
quoteTitle: firstQuote[0],
quoteCategory: firstQuote[1],
quoteText: firstQuote[2],
attribution: firstQuote[3],
surfaceDayOfYear: firstQuote[4]
};
} else {
console.log(`No quotes found for category: ${category}`);
}
}
let output = "";
for (const category of quoteCategories) {
if (quotes[category]) {
const quote = quotes[category];
output += `> [!quote] ${quote.quoteTitle}\n`;
output += `> ${quote.quoteText}\n`;
output += `> —— ${quote.attribution}\n\n`;
} else {
output += `> [!quote] No ${category} quote for today.\n\n`;
}
}
tR = output
%>
I like this solution because:
- It gives me the flexibility to have quotes as source notes to which I can add thoughts and backlinks.
- I can render the notes anywhere (Daily Notes, Canvas Dashboards, etc.) and with one piece of Templater code.)
- I can have a dynamic list of the notes (MOC) using Dataview.
I’ve never used Templater or Dataview and this is my first go. I am very open to suggestions about tweaking or alternate ways of doing this.