Hide block automatically based on tag

Hi, new user here! I figured out most of the features through the great documentation, but there is one use case that I couldn’t find anything about.

I’m using the journal pages (among other things) for some sort of bullet point diary. I rarely have to revisit the corresponding block as it is mostly just for some quick reflections. I really like having it matched to the corresponding day though and having the opportunity to see it in context of the things I worked on etc.

What I would like to achieve is these blocks being hidden by default (pressing the little arrow on the left to expand them) as they are quite private in nature and I’d be more comfortable using logreq in public or with other people present.

Is there a way to achieve this behavior? All the blocks in question share a certain tag that I don’t use anywhere else (let’s call it #diary).

I’d greatly appreciate your help, thank you :slight_smile:

Welcome. If you are willing to do some filesystem scripting, you could:

  • iterate all files inside folder journals
  • search inside each file for the string of the tag (#diary in your example)
  • find its parent block
    • i.e. the first block above the tagged block that is less indented
  • append to it a properly indented string collapsed:: true
    • i.e. the property that saves the collapsed state

If the structure of your notes is relatively simple, the script doesn’t need to cover special cases.

1 Like

Not an ideal solution as it requires the use of some external tool but it will probably work for now :slight_smile: Thank you!

Am i mistaking that this could be achieved with CSS “:has” or with custom javascript? I don’t know since what version Logseq should support the “:has” pseudo-class, I tried some and didn’t get any results -I also don’ t know CSS well nor jscript so I can’t help more here, but I am sure there are very knowledgeable people in the forum who could help.

Something like this should be achievable with the :has pseudo-class:

.block-body:has(.tag:contains("#diary")) {
  display: none;
}
1 Like

Beyond what the topic’s title indicates, the OP specifically asked for the ability to expand the hidden block like any other collapsed block:

The difference is that saving the hidden/collapsed state turns a mere change of appearance into a data change, thus beyond what css is about, no matter that the actual information hasn’t changed. If this behavior is not a requirement, it could be possible to come with some hack, css or otherwise.

1 Like

Ok, right. Working with the collapsing arrow is, then, only achievable with what you suggest (collapsed:: true on its own line under the Block’s Title line/paragraph).
If workarounds are acceptable then there are a few. I don’t know if there is an option to have “Toggle Open Blocks” “activated” by default, but doing “T O” right after opening Logseq when in a public area will collapse ALL blocks, then you can expand them with the left arrow as needed. If there was a way to have all toggled closed by default you’d be spared of having to do it every time when in a public space.
Other than this easy one, there are the CSS or javascript options, which are more involved.

I was merely suggesting these options as OP was not keen on external tools/scripts.

1 Like

Thank you, I’m definitely open to suggestions like that! small issue I noticed with using T O: It seems to just work on the currently ‘focused’ page, i.e. the journal page for the current day instead of all journal pages (even after just opening logseq and before actively editing the page). Am I doing something wrong or is this intended behavior?