Hidden folder (dot-directory) is not supported
knopki opened this issue · 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"]
}
Seconded. Is there any way around this? Besides showing a "scripts" folder in the vault, that is
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 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);
}
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::_
- Folders to hide:
The Hide Folders plugin removes the _scripts folder from the folder sidebar and search results, and most other places.