obsidian-releases icon indicating copy to clipboard operation
obsidian-releases copied to clipboard

Add `obsidian-meta-bind-plugin` plugin

Open mProjectsCode opened this issue 3 years ago • 5 comments

I am submitting a new Community Plugin

Repo URL

Link to my plugin: https://github.com/mProjectsCode/obsidian-meta-bind-plugin

Release Checklist

  • [x] I have tested the plugin on
    • [x] Windows
    • [ ] macOS
    • [ ] Linux
    • [ ] Android (if applicable)
    • [ ] iOS (if applicable)
  • [x] My GitHub release contains all required files
    • [x] main.js
    • [x] manifest.json
    • [x] styles.css (optional)
  • [x] GitHub release name matches the exact version number specified in my manifest.json (Note: Use the exact version number, don't include a prefix v)
  • [x] The id in my manifest.json matches the id in the community-plugins.json file.
  • [x] My README.md describes the plugin's purpose and provides clear usage instructions.
  • [x] I have read the tips in https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md and have self-reviewed my plugin to avoid these common pitfalls.
  • [x] I have added a license in the LICENSE file.
  • [x] My project respects and is compatible with the original license of any code from other plugins that I'm using. I have given proper attribution to these other projects in my README.md.

mProjectsCode avatar Jun 29 '22 19:06 mProjectsCode

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L53 You don't need to cast here, TypeScript will that for you as you already did a instanceof check.

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L99-L101 You can move this after the metadata check, as it will be used after this, saving you some unnecessary operations

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L139-L166 Obsidian already has the frontmatter indexed in the metadata cache: https://github.com/obsidianmd/obsidian-api/blob/d4b79f95ccf3838a305915a137a844250766d023/obsidian.d.ts#L2151 this.app.metadataCache.getFileCache(yourFile)?.frontmatter

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L121 This will also include all non markdown files. You might want to only use the markdown files, this.app.vault.getMarkdownFiles().

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/master/src/parsers/DateParser.ts Obsidian includes Moment(https://momentjs.com/), then you are also not limited to a few preset date formats.

joethei avatar Jul 05 '22 08:07 joethei

@joethei thanks for the review :)

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L53 You don't need to cast here, TypeScript will that for you as you already did a instanceof check.

Fixed

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L99-L101 You can move this after the metadata check, as it will be used after this, saving you some unnecessary operations

Fixed

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L139-L166 Obsidian already has the frontmatter indexed in the metadata cache: https://github.com/obsidianmd/obsidian-api/blob/d4b79f95ccf3838a305915a137a844250766d023/obsidian.d.ts#L2151 this.app.metadataCache.getFileCache(yourFile)?.frontmatter

I found the metadata cache to be unreliable when calling it from the vault file modify event. I am guessing there are some race conditions involved.

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/1ce297e664aeac05ab02343d20c8dd333ccc63d1/src/main.ts#L121 This will also include all non markdown files. You might want to only use the markdown files, this.app.vault.getMarkdownFiles().

fixed

https://github.com/mProjectsCode/obsidian-meta-bind-plugin/blob/master/src/parsers/DateParser.ts Obsidian includes Moment(https://momentjs.com/), then you are also not limited to a few preset date formats.

I switched the parser

mProjectsCode avatar Jul 05 '22 10:07 mProjectsCode

I haven't issued a new release with those changes, I want to wait for further reviews

mProjectsCode avatar Jul 05 '22 15:07 mProjectsCode

I found the metadata cache to be unreliable when calling it from the vault file modify event. I am guessing there are some race conditions involved

Instead of listening for the vault modify event, you can listen for "changed" (https://github.com/obsidianmd/obsidian-api/blob/4583a6b8305b05139c6b1bf226ad15e50a9a5987/obsidian.d.ts#L2185). Then you will be sent the most up to date metadata from the cache.


Otherwise it looks good to me. Let me know when you're ready for this to be released.

liamcain avatar Jul 21 '22 17:07 liamcain

Thanks, I will look into that. But since my PC is currently broken, it will probably take me another week to do that and get the other stuff I have been working on release ready.

mProjectsCode avatar Jul 21 '22 22:07 mProjectsCode

I finally managed to come back to the plugin. It should be ready for release (the docs are still unfinished, but I will do that later).

Instead of listening for the vault modify event, you can listen for "changed" (https://github.com/obsidianmd/obsidian-api/blob/4583a6b8305b05139c6b1bf226ad15e50a9a5987/obsidian.d.ts#L2185). Then you will be sent the most up to date metadata from the cache.

that is now implemented

mProjectsCode avatar Oct 09 '22 14:10 mProjectsCode

Nice looks good! Something I noticed after merging this, you have the plugin name as "meta bind plugin" but it might be weird having the word 'plugin' in the plugin name itself.

liamcain avatar Oct 11 '22 02:10 liamcain