Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: erroneous title in daily note creation from template #496

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zDonik1
Copy link

@zDonik1 zDonik1 commented Mar 16, 2024

The {{title}} template parameter would get incorrectly replaced with the alias, which is a big number, presumably being the creation timestamp. The expected behavior is to replace it with filename.

Example

The template:

# {{title}}

The created daily note (filename: 2024-03-16.md):

# 1710608450

@zDonik1 zDonik1 force-pushed the zdonik1/daily-note-template-title-fix branch from c6bdca2 to 2b5f928 Compare March 16, 2024 17:03
@epwalsh
Copy link
Owner

epwalsh commented Mar 18, 2024

@zDonik1 I'm confused why your alias ends up as a timestamp and not a formatted date. Can you share your config? In particular I'm curious what you have set for daily_notes.alias_format.

@zDonik1
Copy link
Author

zDonik1 commented Mar 19, 2024

I don't have anything set for the daily_notes.alias_format.

Here is my entire config:

require("obsidian").setup({
    sort_by = "accessed",
    disable_frontmatter = true,
    workspaces = {
        {
            name = "personal",
            path = "~/iCloudDrive/iCloud~md~obsidian/SecondBrain",
        },
    },
    daily_notes = {
        folder = "periodic_notes",
        template = "daily_template.md",
    },
    templates = {
        subdir = "templates",
        time_format = "%X",
        substitutions = {
            ["time:HH:mm:ss"] = function()
                return os.date("%X")
            end,
        },
    },
    completion = {
        nvim_cmp = true,
        min_chars = 1,
    },
    new_notes_location = "current_dir",
    note_id_func = function(title)
        return title
    end,
    wiki_link_func = "use_path_only",
    mappings = {
        ["gf"] = {
            action = function()
                return require("obsidian").util.gf_passthrough()
            end,
            opts = { noremap = false, expr = true, buffer = true },
        },
        ["<leader>oh"] = {
            action = function()
                return require("obsidian").util.toggle_checkbox()
            end,
            opts = { buffer = true },
        },
    },
    callbacks = {
        ---@param client obsidian.Client
        ---@param workspace obsidian.Workspace
        post_set_workspace = function(client, workspace)
            client.log.info("Changing directory to %s", workspace.path)
            vim.cmd.cd(tostring(workspace.path))
        end,
    },
    ui = {
        hl_groups = {
            ObsidianTodo = { bold = true, fg = mocha.peach },
            ObsidianDone = { bold = true, fg = mocha.sapphire },
            ObsidianRightArrow = { bold = true, fg = mocha.peach },
            ObsidianTilde = { bold = true, fg = mocha.red },
            ObsidianBullet = { bold = true, fg = mocha.sky },
            ObsidianRefText = { underline = true, fg = mocha.mauve },
            ObsidianExtLinkIcon = { fg = mocha.mauve },
            ObsidianTag = { italic = true, fg = mocha.blue },
            ObsidianHighlightText = { bg = mocha.flamingo },
        },
    },
})

@zDonik1
Copy link
Author

zDonik1 commented Mar 19, 2024

I have done some tests, and it seems that the alias is getting set to a timestamp because lua doesn't understand what is going on when doing date printing. It seems like there is an extra - in the day section. Here:

local alias
if self.opts.daily_notes.alias_format ~= nil then
alias = tostring(os.date(self.opts.daily_notes.alias_format, datetime))
else
alias = tostring(os.date("%B %-d, %Y", datetime))
end

When I removed it, the alias was properly getting initialized.

The only thing is that it still doesn't solve the issue with the wrong {{title}} replacement. That is why I believe the change in this PR is also valid.

Copy link
Owner

@epwalsh epwalsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, the "-" must be a typo, but oddly it works fine on my computer. Fixed via 02f0136.

Anyway, I don't agree that in general the note's title should be its ID. But you can achieve the same result by setting daily_notes.alias_format to the same formatting string as daily_notes.date_format.

@zDonik1
Copy link
Author

zDonik1 commented Mar 19, 2024

It doesn't have to be the Id. Obsidian replaces {{title}} with the file name, while obsidian.nvim doesn't. Thats the core of the issue. We should make the documentation more obvious of this fact if the behavior will not be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants