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

ObsidianNewFromTemplate does not respect config defined note_id_func #737

Open
d-r-jenkins opened this issue Oct 3, 2024 · 2 comments · May be fixed by #774
Open

ObsidianNewFromTemplate does not respect config defined note_id_func #737

d-r-jenkins opened this issue Oct 3, 2024 · 2 comments · May be fixed by #774
Labels
bug Something isn't working

Comments

@d-r-jenkins
Copy link

🐛 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%
@d-r-jenkins d-r-jenkins added the bug Something isn't working label Oct 3, 2024
@bileamScheuvens
Copy link

+1

@cbosvik
Copy link

cbosvik commented Nov 18, 2024

I have the exact opposite problem. {{id}} is overwriting {{title}}. Pull request #774 should fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants