obsidian-binary-file-manager-plugin
obsidian-binary-file-manager-plugin copied to clipboard
[Request] Folder Path
Would love it this could include a Folder path command, currently my PDF have a cover file in the same folder as the PDF named "cover.jpg" och would be awesome if was able to frontmatter like "Cover: {{FOLDER}}cover.jpg"
Here's a Templater script in a markdown snippet to show you how to do this. It adds a source property and only a cover property if its sibling cover.jpg exists.
---
aliases:
tags:
<%*
// Get the value of {{PATH}}
const providedPath = await '{{PATH}}';
// Check if the provided path is not empty
if (providedPath) {
// Get the parent directory (FOLDER) of the provided path
const parentFolder = app.vault.getAbstractFileByPath(providedPath).parent?.path;
// Check if "cover.jpg" exists in the parent directory
const coverPath = `${parentFolder}/cover.jpg`;
const coverFile = app.vault.getAbstractFileByPath(coverPath);
const providedFile = app.vault.getAbstractFileByPath(providedPath);
if (coverFile && coverFile.path !== providedPath) {
// Replace {{PATH}} with "Cover: FOLDER/cover.jpg"
tR += `source: "[[${providedFile.path}|${providedFile.name}]]"\ncover: "[[${coverPath}|cover.jpg]]"`
}
else {
tR += `source: "[[${providedFile.path}|${providedFile.name}]]"`
}
}
%>
---