From 4f54d82f7bb7e3be65915b30c239f70c70f32d27 Mon Sep 17 00:00:00 2001 From: ktf Date: Thu, 16 Feb 2023 21:37:10 -0800 Subject: [PATCH] Use hard-coded `/` as path delimiter in markdown attachment path --- CHANGELOG.md | 5 +++++ src/Kept.hs | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02fb954..f6ed73a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ and this project adheres to the it is expanded (non-recursively) into the list of the `.json` files in that directory. +### Fixed + +- Windows: embedded media attachments display correctly now. (Turns out + Obsidian wants `/` as a path delimiter even in Windows.) + ## 0.2.0 - 2023-02-13 diff --git a/src/Kept.hs b/src/Kept.hs index e6bfff4..bfdc097 100644 --- a/src/Kept.hs +++ b/src/Kept.hs @@ -116,9 +116,14 @@ updateNoteAttachments note = note {metadata = newMetadata} -- Prepend the `media` directory to our attachment paths. Note this is the -- final RELATIVE path that will be written to the markdown note. newAttachmentPath :: [Attachment] -> [Attachment] -newAttachmentPath = map (mediaDirectory ) +newAttachmentPath = map prependMediaDir where - mediaDirectory = ".." attachmentDir + -- NOTE: Using a hard-coded path-delimiter here (`/`) rather than the + -- saner, cross-platform function (``). This path, written to the + -- markdown note, needs to use `/` for embedded attachments to work, EVEN + -- in Windows. (At least in Obsidian.) + mediaDirectory = "../" <> attachmentDir + prependMediaDir dir = mediaDirectory <> "/" <> dir printNoteFile :: KeptOptions -> Note -> IO () printNoteFile opts note = do