Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sorting Folders by Dates in Titles #182

Open
JSG-1 opened this issue Dec 21, 2024 · 2 comments
Open

Sorting Folders by Dates in Titles #182

JSG-1 opened this issue Dec 21, 2024 · 2 comments

Comments

@JSG-1
Copy link

JSG-1 commented Dec 21, 2024

Hi @SebastianMC,

Thank you for this incredible plugin! I’m having trouble configuring it to handle folders with dates in their titles and would appreciate your guidance. I also use the Folder Notes plugin, but I know your plugin supports it, so I suspect the issue is with my configuration.


Problem:

I have folders with dates in the format YYYY-MM-DD, which can appear anywhere in the folder name (start, middle, or end). I need to:

  1. Sort these folders by the date in their title, with newer dates at the top.
  2. If a folder does not contain a date, it should be sorted by its creation date (newer folders first).

What I’ve Tried:

  • Using regexp: \d{4}-\d{2}-\d{2} to match folders with dates.
  • Sorting by > created, but this doesn’t account for the dates embedded in folder names.
  • I ensured folder note metadata is present but still couldn’t extract and sort by the date in the title.

Example:

Initial Structure:

2024-12-01 Important Notes  
Progress Report 2024-11-30  
Weekly Review 2024-12-03  

Desired Output:

Weekly Review 2024-12-03  
2024-12-01 Important Notes
Progress Report 2024-11-30  
  

Is there a way to configure the plugin to sort by dates extracted from folder names while using Folder Notes?

Thank you for your time and help!

Best regards,
JSG

@SebastianMC
Copy link
Owner

SebastianMC commented Dec 23, 2024

Hi @JSG-1

you example involves a series of tricky cases:

1. Sorting by folder dates

In Obsidian, folders don't come with date metadata (no creation date, no modification date). By design. This prevents any sorting based on folder creation/update dates.
To overcome this limitation, the plugin can derive creation/modification from 'Folder Notes' inside a folder and treat them as folder's creation/modification date. To use this feature specify the sorting order as advanced modified or advanced created, for example > advanced modified.

2. Use dates in titles for sorting

The plugin supports part of the scenarios which you describe.
Namely, matching against prefix of suffix numerical sequences and extracting them for sorting.
In your case the syntax would be:

  • ... \-D+ to match titles ending with numerical sequences, allowing the dash - as a separator, and
  • \-D+ ... to to match numerical prefix, accordingly

This works because the dates in format 'YYYY-MM-DD' can be treated as a dash-separated sequence of numbers

An example snippet of sorting specification would be then:

  /+ \-D+ ...
  /+ ... \-D+
    > a-z

The additional syntax /+ is used to combine the two groups of files/notes and sort them as a single group.
I'm using this approach in my vaults.

At the same time, there is no support for infix matching-and-extraction of numbers. It is intentional. Overall, the plugin doesn't support free-form regexp matching against titles intentionally. It is easy to create a regexp introducing backtracking and kill the performance in result, blocking the Obsidian UI even for relatively small vaults. Matching of infix notation (e.g. dates anywhere in the title) is a good example of that.

3. Mixing of different sorting methods for a single-pass sorting

This is not supported, a far too advanced feature.
You can specify up to 4 sorting levels, at the same time they cannot be mixed - they are layered one on top of another.
In other words, you can specify: sort items by creation date first, then within the same date use the title sorting.

You cannot specify: for a folder take the date from tile, and if there is no date in title, take the date from metadata. Not supported.

Recap

There are three unsupported features:

  • sorting by folder creation or modification date (folders in Obsidian don't have date metadata - you can only derive the creation or modification metadata from Folder Notes)
  • extracting a date from 'anywhere in the title' - only numerical date as prefix or suffix are supported
  • mixing of data sources for the same sorting - only layering of up to 4 sorting methods is supported

Excluding these unsupported features, an example sorting spec could look like:

sorting-spec: |
  target-folder: /
  /+ /folders \-D+ ...
  /+ /folder ... \-D+
    > a-z, > advanced created

The resulting sorting would be:

  • find folders which have a dash-separated numerical sequence as a title prefix, e.g. '2024-12-01 Important Notes', AND
  • folders which have a dash-separated numerical sequence as a title suffix, e.g. 'Weekly Review 2024-12-03'
  • order these folders by the numerical sequence in the tile (which works correctly for dates YYYY-MM-DD)
  • if two folders share the same date in title, sort them by creation date (derived from their Folder Notes)

@JSG-1
Copy link
Author

JSG-1 commented Dec 23, 2024

Hi @SebastianMC

Thank you so much for your detailed response and for taking the time to explain the plugin's capabilities and limitations. Your explanation has given me the clarity I need on how best to proceed, and I now have a much better understanding of how to configure my sorting rules effectively.

I really appreciate your help and the work you’ve put into this amazing plugin.

Best regards,
JSG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants