You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#23 feature request sorting notes with metadata (#26)
* #23 - support for sorting by metadata
- added support for grouping items by the presence of specified metadata
- new keyword `with-metadata:` introduced for that purpose in lexer
- if metadata field name is omitted, the default `sort-index-value` is used
- added support for sorting items by notes and folders metadata
- new keyword 'by-metadata:' introduced for that purpose
- if metadata field name is omitted, the default `sort-index-value` is used (or metadata name inheritance is used)
- unit tests of sorting spec processor extended accordingly
- documentation and code example in README.md
- extended to also support true alphabetical on metadata fields
- release unnecessary references after sorting completed
Copy file name to clipboardExpand all lines: README.md
+83-1Lines changed: 83 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ Take full control of the order of your notes and folders:
7
7
- support for fully manual order
8
8
- list notes and folders names explicitly, or use prefixes or suffixes only
9
9
- wildcard names matching supported
10
+
- group and sort notes and folders by notes custom metadata
10
11
- support for automatic sorting by standard and non-standard rules
11
12
- mixing manual and automatic ordering also supported
12
13
- order by compound numbers in prefix, in suffix (e.g date in suffix) or inbetween
@@ -15,7 +16,7 @@ Take full control of the order of your notes and folders:
15
16
- different sorting rules per group even inside the same folder
16
17
- simple to use yet versatile configuration options
17
18
- order configuration stored directly in your note(s) front matter
18
-
- use a dedicated key in YAML
19
+
- use a dedicated `sorting-spec:`key in YAML
19
20
- folders not set up for the custom order remain on the standard Obsidian sorting
20
21
- support for imposing inheritance of order specifications with flexible exclusion and overriding logic
21
22
@@ -35,6 +36,7 @@ Take full control of the order of your notes and folders:
35
36
-[Example 11: Sample book structure with compound Roman number suffixes](#example-11-sample-book-structure-with-compound-roman-number-suffixes)
36
37
-[Example 12: Apply same sorting to all folders in the vault](#example-12-apply-same-sorting-to-all-folders-in-the-vault)
37
38
-[Example 13: Sorting rules inheritance by subfolders](#example-13-sorting-rules-inheritance-by-subfolders)
39
+
-[Example 14: Grouping and sorting by metadata value](#example-14-grouping-and-sorting-by-metadata-value)
38
40
-[Alphabetical, Natural and True Alphabetical sorting orders](#alphabetical-natural-and-true-alphabetical-sorting-orders)
39
41
-[Location of sorting specification YAML entry](#location-of-sorting-specification-yaml-entry)
40
42
-[Ribbon icon](#ribbon-icon)
@@ -412,6 +414,86 @@ sorting-spec: |
412
414
---
413
415
```
414
416
417
+
### Example 14: Grouping and sorting by metadata value
418
+
419
+
Notes can contain metadata, let me use the example inspired by the [Feature Request #23](https://github.com/SebastianMC/obsidian-custom-sort/issues/23).
420
+
Namely, someone can create notes when reading a book and use the `Pages` metadata field. In that field s/he enters page(s) number(s) of the book, for reference.
421
+
422
+
For example:
423
+
424
+
```yaml
425
+
---
426
+
Pages: 6
427
+
...
428
+
---
429
+
```
430
+
431
+
or
432
+
433
+
```yaml
434
+
---
435
+
Pages: 7,8
436
+
...
437
+
---
438
+
```
439
+
440
+
or
441
+
442
+
```yaml
443
+
---
444
+
Pages: 12-15
445
+
...
446
+
---
447
+
```
448
+
449
+
Using this plugin you can sort notes by the value of the specific metadata, for example:
450
+
451
+
```yaml
452
+
---
453
+
sorting-spec: |
454
+
target-folder: Remarks from 'The Little Prince' book
455
+
< a-z by-metadata: Pages
456
+
---
457
+
```
458
+
459
+
In that approach, the notes containing the metadata `Pages` will go first, sorted alphabetically by the value of that metadata.
460
+
The remaining notes (not having the metadata) will go below, sorted alphabetically by default.
461
+
462
+
In the above example the syntax `by-metadata: Pages` was used to tell the plugin about the metadata field name for sorting.
463
+
The specified sorting `< a-z` is obviously alphabetical, and in this specific context it tells to sort by the value of the specified metadata (and not by the note or folder name).
464
+
465
+
In a more advanced fine-tuned approach you can explicitly group notes having some metadata and sort by that (or other) metadata:
466
+
467
+
```yaml
468
+
---
469
+
sorting-spec: |
470
+
target-folder: Remarks from 'The Little Prince' book
471
+
with-metadata: Pages
472
+
< a-z by-metadata: Pages
473
+
...
474
+
> modified
475
+
---
476
+
```
477
+
478
+
In the above example the syntax `with-metadata: Pages` was used to tell the plugin about the metadata field name for grouping.
479
+
The specified sorting `< a-z` is obviously alphabetical, and in this specific context it tells to sort by the value of the specified metadata (and not by the note or folder name).
480
+
Then the remaining notes (not having the `Pages` metadata) are sorted by modification date descending.
481
+
482
+
> NOTE
483
+
>
484
+
> The grouping and sorting by metadata is not refreshed automatically after change of the metadata in note(s) to avoid impact on Obsidian performance.
485
+
> After editing of metadata of some note(s) you have to explicitly click the plugin ribbon button to refresh the sorting. Or issue the command `sort on`. Or close and reopen the vault. Or restart Obsidian.
486
+
> This behavior is intentionally different from other grouping and sorting rules, which stay active and up-to-date once enabled.
487
+
488
+
> NOTE
489
+
>
490
+
> For folders, metadata of their 'folder note' is scanned (if present)
491
+
492
+
> NOTE
493
+
>
494
+
> The `with-metadata:` keyword can be used with other specifiers like `/:files with-metadata: Pages` or `/folders with-metadata: Pages`
495
+
> If the metadata name is omitted, the default `sort-index-value` metadata name is assumed.
496
+
415
497
## Alphabetical, Natural and True Alphabetical sorting orders
416
498
417
499
The 'A-Z' sorting (visible in Obsidian UI of file explorer) at some point before the 1.0.0 release of Obsidian actually became the so-called 'natural' sort order.
0 commit comments