obsidian-custom-js icon indicating copy to clipboard operation
obsidian-custom-js copied to clipboard

Hidden folder (dot-directory) is not supported

Open knopki opened this issue 2 years ago • 4 comments

If a folder containing JS files is a hidden dot folder (.customjs, for example) then plugin can't detect files to load. Repro vault https://github.com/knopki/obsidian-custom-js-dot-dir-repro

I think it's because of using the app.vault.getFiles() to get list of files. For example,

// working
app.vault.getFiles().filter(f => f.path.startsWith("customjs"))
  // => [{"path": "customjs/startup.js", ... }]

// not working
app.vault.getFiles().filter(f => f.path.startsWith(".customjs"))
  // => []

// but
await app.vault.adapter.list(".customjs")
  // => { "folders": [], "files": [".customjs/startup.js"]
}

knopki avatar Nov 09 '23 12:11 knopki

Seconded. Is there any way around this? Besides showing a "scripts" folder in the vault, that is

Dartaltram avatar Jan 09 '24 14:01 Dartaltram

It's been a while so I can't remember for sure, but I think app.vault.getFiles() was the only one that works on mobile. Have you tested mobile with your fix?

saml-dev avatar Jan 10 '24 04:01 saml-dev

@saml-dev Working on android! Tested snippet:

    // Get paths in folder
    if (this.settings.jsFolder != '') {
      const { files } = await this.app.vault.adapter.list(this.settings.jsFolder);
      const scripts = files.filter((f) => f.endsWith('.js'));
      filesToLoad.push(...scripts);
    }

knopki avatar Jan 12 '24 10:01 knopki

I use this workaround:

  • My scripts-folder is named "_scripts"
  • I use the plugin "Hide Folders" (→ https://github.com/JonasDoesThings/obsidian-hide-folders) to hide all folders that start with _, with this setting:
    • Folders to hide: Startswith::_

The Hide Folders plugin removes the _scripts folder from the folder sidebar and search results, and most other places.

stracker-phil avatar Apr 17 '24 10:04 stracker-phil