Collapse namespace prefixes

I think @cannibalox covered most of the reasons. One last reason, I’d add is that it makes search faster.

I like to track Goals and progress. I create a page for each goal with a namespace Goal. The goal pages are empty, but I refer to them from the daily page. Even if I don’t exactly remember the name of the page, typing Goal/ restricts the search and makes it much easier to find the right page

6 Likes

backlinking the related topic with recent discussion :

Totally agree. I already use namespaces for organizing my notes when searching and differentiating notes of the same name, but proper support for them would be great.

+1 for this – one of the only features that I still miss from Roam.

Namespaces are helpful when searching for pages of a particular type. For example, if I need to create a link to a project, I can easily see all projects when searching for it. Same for Books, People, etc. Tags do not help when performing a page search when adding a link.

There are two ways to do namespaces, adding type:: book to every page that describes a book or adding it to the page title, like described here. The latter can be searched for, using:

#+BEGIN_QUERY 
{:title [:h2 "📚 Books Namespace"]
:query [:find (pull ?page [*])
:in $ ?ns
:where
  [?page :block/name ?title]
  [(clojure.string/starts-with? ?title ?ns)] ]
 :inputs [ "book/" ]
}
#+END_QUERY

It will find all pages called book/book title (not Book/book title!).

It’s not optimal, but it’s a start.

PS, welcome @egfrenzy!

2 Likes

Huge +1 — while there isn’t a difference in function here, it cuts wayyyyyy down on visual noise, especially for folks like me who use a lot of namespaces.

I like Roam’s 3 options for simplifying the view (full, abbreviated, do not display namespaces). I use the “do not display” option most commonly. The UI color change helps to differentiate between normal pages.


CleanShot 2022-01-11 at 15.35.53@2x

3 Likes

You can try using aliases.

The syntax Text to be displayed

And also you can add the alias:: property to the namespace page to define a new way you can link to it. If you add alias::A guide to the good life to a page titled Book/Stoicism/A guide to the good life, you can link to it using [[A guide to the good life]]

1 Like

Decent workaround, actually! I’ll try to use this for some of the high-traffic ones. Would still like this as a preference, but aliases might be ok for now.

The problem with alias is that you have to create one for every page you whant to shorten and when you rename the name of the page, you have to change all the “sub pages” aliases one by one.

2 Likes

I’ve released a custom.js snippet to collapse namespaces here (the prefixes are collapsed as ../ with a hardcoded color, to see the full page-name, either enterr Edit Mode or use the Hover Preview Tooltip) :

demo:

it’s bundled with another snippet to adjust the width of query tables, but it’s easy to extract/copy the namespace section only (just be careful to copy the mutation observer section at the top of tfile too).

6 Likes

Would it be possible to maintain last prefix? for example:

“region/country/company” to “…/country/company”

or select n last prefixes

thank you

sure, edit line 93, read this javascript - JS Get Second To Last Index Of - Stack Overflow

2 Likes

Hello, I’m sorry to bother you, but since I don’t have a programming base, I refer to the stackoverflow page and modified“

nmsp[i].innerText.substring(nmsp[i].innerText.lastIndexOf("/", innerText.lastIndexOf("/")-1)); , but it doesn’t work.

Can I trouble you to give a demonstration?


您好,很抱歉打扰了,由于我并没有编程的基础,我参照 stackoverflow 页面并修改了:
nmsp[i].innerText.substring(nmsp[i].innerText.lastIndexOf("/", innerText.lastIndexOf("/")-1)); ,但是并没有成功。

能劳烦您给一个示范吗?

hey, sry for the late reply… it looks good though, not sure why it’s not working for you.

I replaced:

  nmsp[i].innerHTML =
          "<span style='color:rgb(133, 211, 81)'>..</span>" +
          nmsp[i].innerText.substring(
            nmsp[i].innerText.lastIndexOf("/"));  

with

    nmsp[i].innerHTML =
          "<span style='color:rgb(133, 211, 81)'>..</span>" +
          nmsp[i].innerText.substring(
            nmsp[i].innerText.lastIndexOf("/",
            nmsp[i].innerText.lastIndexOf("/")-1)
          );

and got: Logseq_Logseq_20220427_1531

1 Like

Thank you for your code, now available! I think maybe I didn’t have the right format before.

I am really good creating at pbkac issues.

I copied the CSS and JS into my graph and refreshed and re-indexed but still not seeing the namespace modification.

Pages/Files used
image

JS Copied

CSS Copied


What am I missing?

try to reindex, then close the app and restart. it should say it detected a custom.js then ask for permission to run it => grant the permission.

I’m risking being pedantic and splitting hairs here, but I think there might be something useful to distinguish between here: I think namespaces serve best as contexts that are narrow enough to unambiguously resolve a name to a particular concept. That’s slightly different from a “type”. Sometimes the namespace will match the type, but sometimes it won’t. Here are two contrasting examples:

  1. Namespace and type happen to line up:

    • Book/Matilda could be a name which refers to the book “Matilda”, while Movie/Matilda could be a name which refers to the movie of the same name.
    • In the context of the concept Book, Matilda refers to one thing, while in the context of the concept Movie, Matilda refers to another.
    • As it happens, Book/Matilda is a book, while Movie/Matilda is a movie.
  2. Namespace and type don’t line up, and that’s okay, too:

    • Acme/Org Structure could be a name which refers to the organizational structure in the Acme Company, while Globex/Org Structure could be a name which refers to the organizational structure in the Globex Corporation.
    • In the context of the concept Acme, Org Structure refers to one thing, while in the context of the concept Globex, Org Structure refers to another.
    • But in both cases, the “type” of the entity the name refers to is an organizational structure. Acme/Org Structure is not "an Acme", and Globex/Org Structure is not "a Globex".

All of which is to say: I think both namespaces and type::s are useful, for separate (if often overlapping) things. I haven’t seen much (or maybe anything?) use type:: yet, but a simple use might be a plugin which puts an icon in front of each link based on the link’s type. You’d expect to see something like:

  • :blue_book: [[Book/Matilda]]
  • :movie_camera: [[Movie/Matilda]]
  • :busts_in_silhouette: [[Acme/Org Structure]]
  • :busts_in_silhouette: [[Globex/Org Structure]]

(And having written all of that out, I now really want to write that plugin.) :slight_smile:

1 Like

Following up: Awesome Links does this! It uses the property page-type:: by default, though I’ve changed that to type:: for myself because I like it a little better. Then links to those pages inherit the icon:: of those pages’ types.

2 Likes