obsidian-binary-file-manager-plugin icon indicating copy to clipboard operation
obsidian-binary-file-manager-plugin copied to clipboard

[Request] Folder Path

Open Mackan1000 opened this issue 1 year ago • 1 comments

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"

Mackan1000 avatar Jul 01 '23 14:07 Mackan1000

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}]]"`
	}
}  
%>
---

Servinjesus1 avatar Feb 17 '24 23:02 Servinjesus1