Skip to content

More Configuration for Templates #184

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

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

Conversation

bburgess19
Copy link

@bburgess19 bburgess19 commented Jun 4, 2025

Custom Directories and note_id_funcs for templates

This PR implements the features discussed by #165.

In short, it:

  1. Allows notes created using templates to automatically be placed in a specific directory
  2. Allows such notes to have their own note_id_func for naming themselves specially

Testing the Behavior

  1. Create a template and put it in the template folder
  • For this example, I'm using "zettel" as the template ID
  1. Create a configuration for that template, example:
--[[ In configuration ]]
templates = {
  customization = {
     zettel = {
       dir = "existing/path/to/directory,
       note_id_func = function(title)
         return "my-cool-id+" .. title
       end
    }
  }
}

Note

Although some logic is case insensitive, testing on Linux revealed that not all of it is. For this reason,
the case of template specified in the customization ("zettel" in this example") should match the name
and case of the template id

Note

This is a duplicate of #174 because the original forked repository was based on the deprecated epwalsh version, so
I had to delete that fork, and recreate it based on obsidian-nvim/obsidian.nvim

Secondary changes

Add deps/ directory to .gitignore

  • They are generated automatically, so they don't need to be tracked

PR Checklist

  • The PR contains a description of the changes
  • I read the [CONTRIBUTING.md] file
  • The CHANGELOG.md is updated
  • The changes are documented in the README.md file
  • The code complies with make chores (for style, lint, types, and tests)

I found it helpful to have a shared testing library for creating a
temporary client because previously we had multiple implementations for
doing so.

This current implementation, though minimal, covers the bases for
managing creation/teardown.
@bburgess19 bburgess19 changed the title Bburgess/custom templates More Configuration for Templates Jun 4, 2025
@neo451
Copy link
Member

neo451 commented Jun 8, 2025

ok after a while I finally get what the PR is trying to do, pretty cool stuff!!

But that is quite a sign that we need to put docs, you can put a new section in the wiki's template page, named ### customizations, and link to it in the readme's config comments.

Any chance the new_from_template_spec.lua can be rewritten in mini.test? otherwise it is just not tested for the moment.


The following points are not needed to be addressed and just for discussion only.

It feels a bit clunky to change the client's config and then restore it. As I discussed in https://github.com/orgs/obsidian-nvim/discussions/140#discussioncomment-13088512

Having a client that don't hold very many state is just not good for both development and user scripting.

A simple create_note function that takes all the context like template to use, name, and path, would be much nicer, and this PR could be simpler to understand with it.

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.

2 participants