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

Automatic template insertion in daily notes #195

Merged
merged 5 commits into from
Sep 21, 2023
Merged

Automatic template insertion in daily notes #195

merged 5 commits into from
Sep 21, 2023

Conversation

MunsMan
Copy link
Contributor

@MunsMan MunsMan commented Sep 16, 2023

This pull request adds support for automatic template insertion in daily notes.

To enable the feature, just add the full template name to the daily note config:

{
    daily_note = {
         template = "daily.md"
    }
}

Furthermore, I added support for custom template variables.

It is done by the util.substitute_template_variables with tasks the currently available variables and a map of new variables.
There the variables are a name, function pair. The executed function should return the inserted value.
An Example is in the README.

Currently, custom variables aren't added to the normal templates yet, but that would be just a three line change.
Please give me your thought on this feature.

This should close #163

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.

Hey @MunsMan, this is great.

Currently, custom variables aren't added to the normal templates yet, but that would be just a three line change.

I think it makes sense to add that in this PR, do you mind?

README.md Outdated
@@ -323,7 +327,8 @@ For example, with the following configuration
templates = {
subdir = "my-templates-folder",
date_format = "%Y-%m-%d-%a",
time_format = "%H:%M"
time_format = "%H:%M",
custom = {}
Copy link
Owner

Choose a reason for hiding this comment

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

How about calling this substitutions (or something like that)?

Suggested change
custom = {}
substitutions = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, substitutions or variables would be a better fit.
I will update it to substitutions for now.

README.md Outdated
@@ -214,6 +216,8 @@ This is a complete list of all of the options that can be passed to `require("ob
subdir = "templates",
date_format = "%Y-%m-%d-%a",
time_format = "%H:%M",
-- A map for custom variables, the key should be the variable and the value a function
custom = {}
Copy link
Owner

Choose a reason for hiding this comment

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

We can probably omit this here and just use what's in templates, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought that are the default options. I would list it there with the empty list, just to make the exists of the option clear. Likewise, I will update it to substitutions.
Please correct me if I'm wrong. I thought the default config is from line 135 to 258 and on line 324 to 333 are an example. I will add a proper substitutions example.

@MunsMan
Copy link
Contributor Author

MunsMan commented Sep 21, 2023

I just added the substitution support for the default template as well. Furthermore, I renamed it to substitutions and cleaned one spot in the README.

If you have anything else, just led me know.

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.

Thanks @MunsMan!

lua/obsidian/init.lua Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@epwalsh epwalsh merged commit ea6a89e into epwalsh:main Sep 21, 2023
5 checks passed
FlynnD273 pushed a commit to FlynnD273/obsidian.nvim that referenced this pull request Sep 23, 2023
…tions (epwalsh#195)

* Option for automatic template insertion in daily notes and support for custom daily template variables

* README rename custom to substituetions and clean up example

* rename variable from custom to substitutions and adding substitutions to default template

* Apply suggestions from code review

---------

Co-authored-by: Pete <[email protected]>
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.

Use a specific template with daily or new note?
2 participants