Publish UI: Change sort order

Use case or problem

When scanning through files/folders in Publish window, there is no ability to change the sort order. This is a helpful feature in File Explorer.

Proposed solution

Add the same sort feature to the Obsidian Publish window, or at minimum, sort by file name.

  • File name (A to Z)
  • File name (Z to A)
  • Modified time (new to old)
  • Modified time (old to new)
  • Created time (new to old)
  • Created time (old to new)

Related feature requests (optional)

Publish UI: Collapse/expand folders

2 Likes

I can’t remember where I found this or figured it out, but you can manually give a sort order of individual elements in a publish.js file.

My code looks like this:

var siteLeft = document.querySelector('.site-body-left-column');

let navOrderAsc = ["welcome.md", "start here.md"]; /* these go on top*/

let navOrderDsc = []; /* these go at the bottom */

/* items not mentioned go in between in alphabetical order */

var siteNav = siteLeft.querySelector('.nav-view-outer');

var navContainer = siteNav.querySelector('.tree-item').querySelector('.tree-item-children');

for (const item of navOrderAsc.reverse()){

    querytext = '[data-path="' + item + '"]';

    navItem = navContainer.querySelector(querytext);

    if (navItem == null) continue;

    moveItem = navItem.parentElement;

    navContainer.prepend(moveItem);

}

for (const item of navOrderDsc.reverse()){

    querytext = '[data-path="' + item + '"]';

    navItem = navContainer.querySelector(querytext);

    if (navItem == null) continue;

    moveItem = navItem.parentElement;

    navContainer.append(moveItem);

}
5 Likes

I would think this would be easier to do in CSS but I haven’t been able to do it myself. Thanks for sharing this Javascript!

Do you happen to know if this could also be applied for inverting the default sort order of backlinks in Obsidian Publish? If yes, how? :innocent: