epwalsh / obsidian.nvim

Obsidian 🤝 Neovim
Apache License 2.0
3.98k stars 184 forks source link

ObsidianNewFromTemplate does not respect config defined note_id_func #737

Open d-r-jenkins opened 6 days ago

d-r-jenkins commented 6 days ago

🐛 Describe the bug

For demonstrations sake, in my config I have

note_id_func = function(title)
    return "hello"
end,

and when I run :ObsidianNew test I get a file with

---
id: hello
aliases:
  - test
tags: []
---

# test

as expected.

But when I run :ObsidianNewFromTemplate test and use any template (with or without the yaml metadata explicitly being in the template using {{id}}), I get

---
id: test
aliases: []
tags: []
---

# test

It seems that somehow the title is being used in place of the id in templates.

Config

require("obsidian").setup({
    workspaces = {
        { name = "personal", path = "~/obsidian/personal" },
    },
    preferred_link_style = "markdown",
    daily_notes = {
        date_format = "%Y-CW%V",
        alias_format = "%Y-CW%V",
        default_tags = { "weekly-notes" },
    },
    mappings = {
        -- Smart action depending on context, either follow link or toggle checkbox.
        ["<cr>"] = {
            action = function()
                return require("obsidian").util.smart_action()
            end,
            opts = { buffer = true, expr = true },
        },
    },
    templates = {
        folder = "templates",
        date_format = "%Y-%m-%d",
        time_format = "%H:%M",
    },

    -- Optional, customize how note file names are generated given the ID, target directory, and title.
    ---@param spec { id: string, dir: obsidian.Path, title: string|? }
    ---@return string|obsidian.Path The full path to the new note.
    note_path_func = function(spec)
        -- This is equivalent to the default behavior.
        local path = spec.dir / tostring(spec.title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower())
        return path:with_suffix(".md")
    end,

    -- Optional, customize how note IDs are generated given an optional title.
    ---@param title string|?
    ---@return string
    note_id_func = function(title)
        return "hello"
    end,
})

Environment

NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713484068
Obsidian.nvim v3.9.0 (ae1f76a75c7ce36866e1d9342a8f6f5b9c2caf9b)
Status:
  • buffer directory: nil
  • working directory: /home/daniel_jenkins
Workspaces:
  ✓ active workspace: Workspace(name='personal', path='/home/daniel_jenkins/obsidian/personal', root='/home/daniel_jenkins/obsidian/personal')
Dependencies:
  ✓ plenary.nvim: 2d9b06177a975543726ce5c73fca176cedbffe9d
  ✓ nvim-cmp: ae644feb7b67bf1ce4260c231d1d4300b19c6f30
  ✓ telescope.nvim: eae0d8fbde590b0eaa2f9481948cd6fd7dd21656
Integrations:
  ✓ picker: TelescopePicker()
  ✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
    all sources:
      • path
      • nvim_lsp
      • nvim_lsp_signature_help
      • luasnip
Tools:
  ✓ rg: ripgrep 13.0.0
Environment:
  • operating system: Linux
Config:
  • notes_subdir: nil%
bileamScheuvens commented 5 days ago

+1