mirror of
https://github.com/Ascyii/telekasten.nvim.git
synced 2026-01-01 06:14:23 -05:00
Fix #16: templates should be optional
This commit is contained in:
28
README.md
28
README.md
@@ -194,12 +194,15 @@ require('telekasten').setup({
|
||||
weeklies_create_nonexisting = true,
|
||||
|
||||
-- template for new notes (new_note, follow_link)
|
||||
-- set to `nil` or do not specify if you do not want a template
|
||||
template_new_note = home .. '/' .. 'templates/new_note.md',
|
||||
|
||||
-- template for newly created daily notes (goto_today)
|
||||
-- set to `nil` or do not specify if you do not want a template
|
||||
template_new_daily = home .. '/' .. 'templates/daily.md',
|
||||
|
||||
-- template for newly created weekly notes (goto_thisweek)
|
||||
-- set to `nil` or do not specify if you do not want a template
|
||||
template_new_weekly= home .. '/' .. 'templates/weekly.md',
|
||||
|
||||
-- image link style
|
||||
@@ -241,6 +244,13 @@ END
|
||||
| `plug_into_calendar` | activate calendar support if true (needs calendar-vim plugin) | true |
|
||||
| `calendar_opts` | options for calendar, see below | see below |
|
||||
|
||||
**Please note:** If you do not want to use a template, set its associated option to `nil` or remove it from your config.
|
||||
```lua
|
||||
-- template for new notes (new_note, follow_link)
|
||||
-- set to `nil` or do not specify if you do not want a template
|
||||
template_new_note = nil,
|
||||
```
|
||||
|
||||
The calendar support has its own options, contained in `calendar_opts`:
|
||||
|
||||
| calendar setting | description | example |
|
||||
@@ -416,18 +426,18 @@ The functions `goto_today`, `goto_thisweek`, `find_daily_notes`, `find_weekly_no
|
||||
non-existing notes. This allows you to 'go to today' without having to create today's note beforehand. When you just
|
||||
type `[[some link]]` and then call `follow_link`, the 'some link' note can be generated.
|
||||
|
||||
The following table shows which command relies on what config option:
|
||||
The following table shows what action creates what kind of non-existing note:
|
||||
|
||||
| telekasten function | config option | creates what |
|
||||
| ACTION | config option | creates what |
|
||||
| --- | --- | --- |
|
||||
| `goto_today` | `dailies_create_nonexisting` | today's daily note |
|
||||
| `goto_today()` | `dailies_create_nonexisting` | today's daily note |
|
||||
| [ENTER] on a day in the calendar | `dailies_create_nonexisting` | selected day's daily note |
|
||||
| `find_daily_notes` | `dailies_create_nonexisting` | today's daily note |
|
||||
| `goto_thisweek` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `find_weekly_notes` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `follow_link` | `follow_creates_nonexisting` | new note |
|
||||
| `new_note` | always true | new note |
|
||||
| `new_templated_note` | always true | new note |
|
||||
| `find_daily_notes()` | `dailies_create_nonexisting` | today's daily note |
|
||||
| `goto_thisweek()` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `find_weekly_notes()` | `weeklies_create_nonexisting` | this week's weekly note |
|
||||
| `follow_link()` | `follow_creates_nonexisting` | new note |
|
||||
| `new_note()` | always true | new note |
|
||||
| `new_templated_note()` | always true | new note |
|
||||
|
||||
If the associated option is `true`, non-existing notes will be created.
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ telekasten.setup({opts})
|
||||
|
||||
|
||||
-- specific note templates
|
||||
-- set to `nil` or do not specify if you do not want a template
|
||||
template_new_note = '/path/to/file', -- template for new notes
|
||||
template_new_daily = '/path/to/file', -- template for new daily notes
|
||||
template_new_weekly = '/path/to/file', -- template for new weekly notes
|
||||
@@ -182,21 +183,27 @@ telekasten.setup({opts})
|
||||
|
||||
*telekasten.settings.template_new_note*
|
||||
template_new_note: ~
|
||||
Markdown template for new notes.
|
||||
Markdown template for new notes. Set to `nil` if you don't want a
|
||||
template.
|
||||
|
||||
Default: '~/zettelkasten/templates/new_note.md'
|
||||
Default: `nil`
|
||||
Example: `'~/zettelkasten/templates/daily.md'`
|
||||
|
||||
*telekasten.settings.template_new_daily*
|
||||
template_new_daily: ~
|
||||
Markdown template for new daily notes.
|
||||
Markdown template for new daily notes. Set to `nil` if you don't want
|
||||
a template.
|
||||
|
||||
Default: '~/zettelkasten/templates/daily.md'
|
||||
Default: `nil`
|
||||
Example: `'~/zettelkasten/templates/daily.md'`
|
||||
|
||||
*telekasten.settings.template_new_weekly*
|
||||
template_new_weekly: ~
|
||||
Markdown template for new weekly notes.
|
||||
Markdown template for new weekly notes. Set to `nil` if you don't want
|
||||
a template.
|
||||
|
||||
Default: '~/zettelkasten/templates/daily.md'
|
||||
Default: `nil`
|
||||
Example: `'~/zettelkasten/templates/daily.md'`
|
||||
|
||||
|
||||
Valid keys for {opts.calendar_opts}
|
||||
@@ -531,7 +538,7 @@ The specific templates and settings used are:
|
||||
|
||||
See also |telekasten.template_files| below for more on the specific templates.
|
||||
|
||||
The folloet ing table shows you what action creates what kind of non-existing
|
||||
The following table shows you what action creates what kind of non-existing
|
||||
note:
|
||||
|
||||
+----------------------------------+--------------------------------+
|
||||
|
||||
@@ -38,9 +38,9 @@ M.Cfg = {
|
||||
weeklies_create_nonexisting = true,
|
||||
|
||||
-- templates for new notes
|
||||
template_new_note = home .. "/" .. "templates/new_note.md",
|
||||
template_new_daily = home .. "/" .. "templates/daily_tk.md",
|
||||
template_new_weekly = home .. "/" .. "templates/weekly_tk.md",
|
||||
-- template_new_note = home .. "/" .. "templates/new_note.md",
|
||||
-- template_new_daily = home .. "/" .. "templates/daily_tk.md",
|
||||
-- template_new_weekly = home .. "/" .. "templates/weekly_tk.md",
|
||||
|
||||
-- image link style
|
||||
-- wiki: ![[image name]]
|
||||
@@ -208,8 +208,10 @@ end
|
||||
local function create_note_from_template(title, filepath, templatefn, calendar_info)
|
||||
-- first, read the template file
|
||||
local lines = {}
|
||||
for line in io.lines(templatefn) do
|
||||
lines[#lines + 1] = line
|
||||
if file_exists(templatefn) then
|
||||
for line in io.lines(templatefn) do
|
||||
lines[#lines + 1] = line
|
||||
end
|
||||
end
|
||||
|
||||
-- now write the output file, substituting vars line by line
|
||||
@@ -998,13 +1000,6 @@ local function Setup(cfg)
|
||||
M.Cfg.find_command = nil
|
||||
end
|
||||
|
||||
-- refresh templates
|
||||
M.note_type_templates = {
|
||||
normal = M.Cfg.template_new_note,
|
||||
daily = M.Cfg.template_new_daily,
|
||||
weekly = M.Cfg.template_new_weekly,
|
||||
}
|
||||
|
||||
-- this looks a little messy
|
||||
if M.Cfg.plug_into_calendar then
|
||||
cfg.calendar_opts = cfg.calendar_opts or {}
|
||||
@@ -1022,6 +1017,18 @@ local function Setup(cfg)
|
||||
-- setup extensions to filter for
|
||||
M.Cfg.filter_extensions = cfg.filter_extensions or { M.Cfg.extension }
|
||||
|
||||
-- provide fake filenames for template loading to fail silently if template is configured off
|
||||
M.Cfg.template_new_note = M.Cfg.template_new_note or 'none'
|
||||
M.Cfg.template_new_daily = M.Cfg.template_new_daily or 'none'
|
||||
M.Cfg.template_new_weekly = M.Cfg.template_new_weekly or 'none'
|
||||
|
||||
-- refresh templates
|
||||
M.note_type_templates = {
|
||||
normal = M.Cfg.template_new_note,
|
||||
daily = M.Cfg.template_new_daily,
|
||||
weekly = M.Cfg.template_new_weekly,
|
||||
}
|
||||
|
||||
if debug then
|
||||
print("Resulting config:")
|
||||
print("-----------------")
|
||||
|
||||
Reference in New Issue
Block a user