SebastianMC / obsidian-custom-sort

Take full control over the order and sorting of folders and notes in File Explorer in Obsidian
GNU General Public License v3.0
255 stars 19 forks source link

[Feature Request] Sorting Notes with specific Metadata Tag #23

Closed blaettlerio closed 1 year ago

blaettlerio commented 1 year ago

Wondering if it would be possible to enhance the functionality of the plugin with the ability to sort notes in a folder with the help of a specific Metadata Tag?

Use Case: If you are creating notes based on books I enter the the page number of the book within the metadata of the note. Therefore it would be beneficial to have the option to sort the notes with that specific tag (e.g. Pages).

SebastianMC commented 1 year ago

Hi @blaettlerio!

the idea of the suggested feature seems promising!

I've done some initial evaluation of how the implementation could behave and I've created a working prototype locally. This resulted in a bunch of questions. I don't want to overcomplicate the solution, at the same time I don't to oversimplify it

Please take a look below points and let me know what you think:

1. First and foremost, do I understand how the feature should work?

A note N1 contains YAML frontmatter with a metadata like:

---
Pages: 5
---

A note N2 at the same time contains:

---
Pages: 1
---

And you want to be able to tell the plugin (via custom sorting specification) to use the value of the metadata Pages to sort.

In result, if the sorting specified is alphabetical, the note N2 should go before N1. For reverse alphabetical order, N2 goes before N1.

2. If my undestanding in 1. is correct, then...

... the potential syntax of specification could look like:

sorting-spec: |
  target-folder: Book notes
  /:files metadata: Pages
    < a-z

The above specification could be read as: in the folder Book notes take the files which contain the Pages metadata in their YAML. Group them together and sort alphabetically by the actual value of the metadata Pages

3. If 1. and 2. are fine, the intentional limitations of the implementation could be:

Let me know what you think :-)

blaettlerio commented 1 year ago

Hi @SebastianMC

Thank you for your answer.

  1. Yes you got my idea exactly. :-)

  2. From a syntax perspective I think that would be perfect. And would fit into the plugins existing plugin functionality.

3.1. Think the a-z ascending or descending would be a neat starting point. 3.2. At least for me unnecessary...but wouldn't it be possible to define/combine those to options via yaml manually or via inheritance? As I would think that some people might have the expectation to sort a-z if two notes have the same metadata tag but I could be wrong?!

First sort priority: Metadata Second sort priority: note name

3.3. Good idea....did not think about that although I use folder notes too ;-)

3.4. Agree....constantly monitoring changes on a file level would be overkill.

Let me know if you have other questions.

SebastianMC commented 1 year ago

A bit more advanced implementation is completed in the branch and ready to merge in the PR #26. The tricky additions are fully covered by unit tests. Some additional live tests have to be done with fresh head before merge

Highlights of this new feature:

The simplest sorting config example discussed in previous notes would look like:

sorting-spec: |
  target-folder: Book notes
  < a-z by-metadata: Pages
blaettlerio commented 1 year ago

Tested it! Works like a charm!

Thank you for the fast implementation.