Programmatically create daily notes for a whole month

What I’m trying to do

I’m now using a physical journal but I would like to “backup” some of my entries into Obsidian.
I would like to be able to navigate between daily notes for a given month using the “Open next/prev daily note” action but that will open the next/prev CREATED daily note, not the next/prev daily note for the current day

I could do this with a command line automation but things like template won’t work

I have coded my own solution, using a mix of templater and dataviewjs. This is how it looks (actual look customisable via css):

Every daily note contains that blue header, which shows in the center (bold) the date of that note (same than the one in the title, but including the weekday, which I find useful), and two previous dates to the left, and two next dates to the right (if available, in this case there is a single one). Those contents are dynamics, showing only the actual existing notes. In this example, the next existing note after 30 may is 03 jun. There is no notes for 31 may, 01 jun or 02 jun. But if you create any of those intermediary dates, the header will update automatically.

The dates are clickable and lead to the corresponding daily note.

How

Using templater, I define the following template for my daily notes:

```dataviewjs
await dv.view("Templates/views/DailyHeader", "00-Journal")
```
## Log
- <% tp.file.cursor(1) %>

The dataviewjs block does the magic, via custom views.

The first argument for dv.view() is the name of a folder which contains a custom view (more
on that later), in my case Templates/views/DailyHeader (you can put it wherever you want). The second argument is the name of the folder where your daily notes are stored (00-Journal in my case). That folder can contain a flat structure with single notes for each day, or (like in my case) have other subfolder structure, such as YEAR/Month/daily-note.md. It works anyway.

Now, the interesting part, the custom view. You have to create the folder Templates/views/DailyHeader (if you decide to put it in the same place than me), and in that folder create two files, named:

  • view.js
  • view.css

You have to do that but using your system file explorer and a suitable text editor (eg: Notepad++ or VSCode).

The contents of those files are:

view.js

const locale = "en";   // Set the locale for date formatting
const dateFormat = "dd LLL (ccc)"; // Define the date format , see Luxon docs

function dailyHeader(folder) {
    const daily_notes = dv.pages('"' + folder + '"');

    // Generate 'before' , 'today', and 'after' sections, as concatenated strings
    const before = daily_notes
        .where(p => p.file.day && p.file.day < dv.current().file.day)
        .sort(p => p.file.day, "asc")
        .slice(-2)
        .map(p => dv.fileLink(p.file.name, false, p.file.day
            .toFormat(dateFormat, { locale: locale })))
        .join(" · ") || "No dates before";

    const today = `<b class="currentdate">${dv.current().file.day
        .toFormat(dateFormat, { locale: locale })}</b>`;

    const after = daily_notes
        .where(p => p.file.day && p.file.day > dv.current().file.day)
        .sort(p => p.file.day, "asc")
        .limit(2)
        .map(p => dv.fileLink(p.file.name, false, p.file.day
            .toFormat(dateFormat, { locale: locale })))
        .join(" · ") || "No more dates";

    // Mix the sections into a single string, using a dot as a separator
    const content = `${before} · ${today} · ${after}`;

    // Render the content as a div with a specific class, for stylingy
    return dv.el("div", content, { cls: "daily-header" });
}

// Call the function
dailyHeader(input);

view.css

b.currentdate {
    background-color: var(--color-highlight);
    color: var(--color-accent);
    font-size: 1.2em;
    padding: 3pt;
    border-radius: 5pt;
}
.daily-header {
    text-align: center;
    margin-bottom: 1em;
    padding-bottom: 1ex;
    border-bottom: 1px solid var(--color-accent);
}

Customizations

You can change the first line of view.js if you use a different locale. It will affect the name of the weekday and month. You can also adjust the dateFormat variable to your taste (see Luxon Date Formatting)

You can change the css to customize the look of the “current date” and the whole header.

I believe the Calendar community plugin can be setup to create daily notes (using your existing daily note template if you have one) when you click the date in the calendar. It’s not an automation, but I mention it in case quickly clicking a bunch of dates might be good enough for you for now.