Skip to content

Instantly share code, notes, and snippets.

@selfire1
Last active December 7, 2022 19:23
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save selfire1/cf3e97f07f9aa99b59f9a9f5487a5cdd to your computer and use it in GitHub Desktop.
Save selfire1/cf3e97f07f9aa99b59f9a9f5487a5cdd to your computer and use it in GitHub Desktop.

2022

Daily Journaling

const dayInMonth = moment().format("D");
const currentMonth = moment().format("M");
var i = 1;
while (currentMonth > i) {
    var entries = entriesSum(i);
    var max = daysInMonth(i);
    var perc = entries + "/" + max;
    dv.span(
        `### ${monthName(i)} <sup>[[${monthNote(i)}|${perc}]]</sup><br>${progressBar(entries, max)}`
        );
    // Current month
    i++;
    entries = entriesSum(i);
    max = dayInMonth;
    perc = entries + "/" + max;
    if (currentMonth == i) {
    dv.span(
        `### 🟢 ${monthName(i)} <sup>[[${monthNote(i)}|${perc}]]</sup><br>${progressBar(entries, max)}`
        );
    }
}

function monthName(month) {
    return moment(`2022-${month}`).format("MMMM");
}

function entriesSum(month) {
    var month = month.toString().padStart(2, '0');
    const re = new RegExp(`2022-${month}-\\d{2}`);
    return dv.pages('"10 Journals/2022.11 Dailies"').where(p => re.test(p.file.name)).array().length;
}

function daysInMonth(month) {
    var month = month--;
    return moment([2022, month]).daysInMonth();
}

function progressBar(entries, max) {
    return `<progress value="${entries}" max="${max}">${entries}</progress>`;
}

function monthNote(month) {
    return moment(`2022-${month}`).format("YYYY-MM-MMMM");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment