oleeskild / obsidian-digital-garden

MIT License
1.41k stars 128 forks source link

[Feature Request] Custom item order in sidebar #423

Open ThatOtherAndrew opened 1 year ago

ThatOtherAndrew commented 1 year ago

For the navigation sidebar, it would be very helpful to be able to customise the order of elements - e.g. having certain files appear before directories, or rearranging elements otherwise. Currently I have a few root-level pages which appear at the very bottom after all directories, which is not very helpful.

image
oleeskild commented 1 year ago

You could use the pinning feature: https://dg-docs.ole.dev/advanced/note-specific-settings/#pinning-notes-to-filetree This will cause the note to be at the top of the folder it's in.

ThatOtherAndrew commented 1 year ago

That appears to be a partial solution, and I didn't know about that - thanks for sharing! However, that still doesn't fully solve my issue, as I wish to be able to arbitrarily sort my notes (or at least sort by creation date so I can use the frontmatter to set a custom creation date), to reflect the order of topics in the course I'm taking notes on. Is there any other feature or workaround for this?

julesvirallinen commented 1 year ago

I'm wondering if replacing pin (or adding) dg-sort-weight that would

  1. (pin)
  2. sort by sort-weight
  3. sort by default

would make sense.

If it's not something that would be widely used it might not be worth it though.

ProAlexUSC commented 2 months ago

dg-sort-weight is not a good idea in some ways. If you want to sort by sort-weight, you have to add weight to every note. But you can use the created by default as shown below. @julesvirallinen @ThatOtherAndrew

--- a/src/helpers/filetreeUtils.js
+++ b/src/helpers/filetreeUtils.js
@@ -35,6 +35,14 @@ const sortTree = (unsorted) => {
         return aNum - bNum; //Fast comparison between numbers
       }

+     // compare with createTime
+     let a_createTime = unsorted[a].createTime;
+     let b_createTime = unsorted[b].createTime;
+
+     if (a_createTime && b_createTime) {
+         return a_createTime > b_createTime ? 1 : -1;
+     }
+
       if (a.toLowerCase() > b.toLowerCase()) {
         return 1;
       }
@@ -63,6 +71,7 @@ function getPermalinkMeta(note, key) {
   let noteIcon = process.env.NOTE_ICON_DEFAULT;
   let hide = false;
   let pinned = false;
+  let createTime = null;
   let folders = null;
   try {
     if (note.data.permalink) {
@@ -93,11 +102,12 @@ function getPermalinkMeta(note, key) {
         .split("/");
     }
     folders[folders.length - 1]+= ".md";
+   createTime = note.data.created;
   } catch {
     //ignore
   }

-  return [{ permalink, name, noteIcon, hide, pinned }, folders];
+  return [{ permalink, name, noteIcon, hide, pinned, createTime }, folders];
 }