Skip to content

Commit 7c8dbfb

Browse files
committed
Rename image_name_func to attachments.img_name_func
1 parent 7b9feb6 commit 7c8dbfb

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Added `opts.follow_img_func` option for customizing how to handle image paths.
1313

14+
### Changed
15+
16+
- Renamed `opts.image_name_func` to `opts.attachments.img_name_func`.
17+
1418
### Fixed
1519

1620
- Fixed an edge case with collecting backlinks.

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,13 +349,6 @@ This is a complete list of all of the options that can be passed to `require("ob
349349
-- Either 'wiki' or 'markdown'.
350350
preferred_link_style = "wiki",
351351

352-
-- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
353-
---@return string
354-
image_name_func = function()
355-
-- Prefix image names with timestamp.
356-
return string.format("%s-", os.time())
357-
end,
358-
359352
-- Optional, boolean or a function that takes a filename and returns a boolean.
360353
-- `true` indicates that you don't want obsidian.nvim to manage frontmatter.
361354
disable_frontmatter = false,
@@ -528,6 +521,14 @@ This is a complete list of all of the options that can be passed to `require("ob
528521
-- If this is a relative path it will be interpreted as relative to the vault root.
529522
-- You can always override this per image by passing a full path to the command instead of just a filename.
530523
img_folder = "assets/imgs", -- This is the default
524+
525+
-- Optional, customize the default name or prefix when pasting images via `:ObsidianPasteImg`.
526+
---@return string
527+
img_name_func = function()
528+
-- Prefix image names with timestamp.
529+
return string.format("%s-", os.time())
530+
end,
531+
531532
-- A function that determines the text to insert in the note when pasting an image.
532533
-- It takes two arguments, the `obsidian.Client` and an `obsidian.Path` to the image file.
533534
-- This is the default implementation.

lua/obsidian/commands/paste_img.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ return function(client, data)
1111

1212
---@type string|?
1313
local default_name
14-
if client.opts.image_name_func then
15-
default_name = client.opts.image_name_func()
14+
if client.opts.attachments.img_name_func then
15+
default_name = client.opts.attachments.img_name_func()
1616
end
1717

1818
local path = paste_img {

lua/obsidian/config.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ local config = {}
1717
---@field preferred_link_style obsidian.config.LinkStyle
1818
---@field follow_url_func fun(url: string)|?
1919
---@field follow_img_func fun(img: string)|?
20-
---@field image_name_func (fun(): string)|?
2120
---@field note_frontmatter_func (fun(note: obsidian.Note): table)|?
2221
---@field disable_frontmatter (fun(fname: string?): boolean)|boolean|?
2322
---@field completion obsidian.config.CompletionOpts
@@ -208,6 +207,11 @@ config.ClientOpts.normalize = function(opts, defaults)
208207
opts.templates.subdir = nil
209208
end
210209

210+
if opts.image_name_func then
211+
opts.attachments.img_name_func = opts.image_name_func
212+
opts.image_name_func = nil
213+
end
214+
211215
--------------------------
212216
-- Merge with defaults. --
213217
--------------------------
@@ -465,6 +469,7 @@ end
465469
---@class obsidian.config.AttachmentsOpts
466470
---
467471
---@field img_folder string Default folder to save images to, relative to the vault root.
472+
---@field img_name_func (fun(): string)|?
468473
---@field img_text_func fun(client: obsidian.Client, path: obsidian.Path): string
469474
---@field confirm_img_paste boolean Whether to confirm the paste or not. Defaults to true.
470475
config.AttachmentsOpts = {}

0 commit comments

Comments
 (0)