Support for assets in plugins

I think it would be nice to have a way of including static files in plugin releases without having to inline them in the main.js file.

Proposal:

  • assets.zip would be downloaded from the GitHub release if present and extracted into .obsidian/plugins/{PLUGIN_NAME}/assets
  • API call to make reading from the folder convenient (this.plugin.readAsset(relPath: string): TFile)?

Security shouldn’t be much of a concern since plugins can already execute arbitrary code.

2 Likes

Use cases:

  • Including example markdown files with plugin
  • Including images and other static resources needed for the plugin

try this:

export function buildPluginStaticResourceSrc(plug: Plugin_2, assetPath: string) {
  return plug.app.vault.adapter.getResourcePath(pathJoin(plug.app.vault.configDir, "plugins", plug.manifest.id, assetPath))
}

/* usage */
element.createEl("img", { attr: { src: buildPluginStaticResourceSrc(this,  "example.png") }});