Richardsl / heatmap-calendar-obsidian

An Obsidian plugin for displaying data in a calendar similar to the github activity calendar
Apache License 2.0
614 stars 102 forks source link

Having trouble with nested frontmatter #82

Closed carolinaqzx closed 1 year ago

carolinaqzx commented 1 year ago

Hello! I am having a lot of trouble getting this plugin to work with nested key/value pairs in my yaml front matter. I tried copying the "social" heatmap calendar example that was provided, but to no avail. ChatGPT couldn't help me either.

This is what my front matter looks like:

---
food:
    smoothie: true
    water-cups: 5
movement:
    rebounding: true
    running: true
---

(I pressed tab to nest key/values, if that matters. )

Here is what my query looks like:

dv.span("smoothie")
const calendarData = {
    year: 2023,
    colors: {
        orange:      ["#ff7800"],
    },
    showCurrentDayBorder: true,
    defaultEntryIntensity: 1,
    entries: [],
}

for (let page of dv.pages('"10 daily notes/2023"').where(p => p.food)) {

    calendarData.entries.push({
        date: page.file.name,
        intensity: page.food.smoothie,
        content: "",       
    })
}

renderHeatmapCalendar(this.container, calendarData)

I have tried changing the where(p=> p.food) to where(p=>p.food.smoothie) but then I get an error message. This code block works perfectly well when the key/value pairs aren't nested.

carolinaqzx commented 1 year ago

Turns out that my front matter was invalid. With YAML, you cannot indent using the tab button, instead you must use spaces (two spaces is the convention).