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

Feature request: hide entire folders from the filetree #356

Open
inputsh opened this issue Jul 30, 2023 · 1 comment
Open

Feature request: hide entire folders from the filetree #356

inputsh opened this issue Jul 30, 2023 · 1 comment

Comments

@inputsh
Copy link

inputsh commented Jul 30, 2023

I know you can hide individual notes with dg-hide, but the folder will still be displayed in the filetree even if it's "empty" (as in all notes within it are hidden).

Would be cool to have some sort of a setting that would hide entire folders from the filetree.

@4anghyeon
Copy link

I solved it with a little code modification.

filetreeUtils.js

function assignNested(obj, keyPath, value) {
  lastKeyIndex = keyPath.length - 1;
  for (var i = 0; i < lastKeyIndex; ++i) {
    key = keyPath[i];
    if (!(key in obj)) {
      obj[key] = { isFolder: true, isEmpty: true }; // added
    }
    obj = obj[key];
    if (!value.hide) obj.isEmpty = false; // added
  }
  obj[keyPath[lastKeyIndex]] = value;
}

filetree.njk

{% macro menuItem(fileOrFolderName, fileOrFolder, step, currentPath) %}
    {%if fileOrFolder.isNote or fileOrFolder.isFolder%}
        <div x-show="isOpen" style="display:none" class="{{'filelist' if step>0}}">
            {%if fileOrFolder.isNote and not fileOrFolder.hide %}
                <div @click.stop class="notelink {{ 'active-note' if fileOrFolder.permalink === permalink}}">
                    {%- if not meta.noteIconsSettings.filetree -%}<i icon-name="sticky-note" aria-hidden="true"></i>{%- endif -%}
                    <a data-note-icon="{{fileOrFolder.noteIcon}}" style="text-decoration: none;" class="filename" href="{{fileOrFolder.permalink}}">{{fileOrFolder.name}} </a>
                </div>
            {% elif fileOrFolder.isFolder and not fileOrFolder.isEmpty %} // modified
                <div class="folder inner-folder"  x-data="{isOpen: $persist(false).as('{{currentPath}}')}" @click.stop="isOpen=!isOpen">
                    <div class="foldername-wrapper align-icon">
                    <i x-show="isOpen" style="display: none;"  icon-name="chevron-down"></i>
                    <i x-show="!isOpen"  icon-name="chevron-right"></i>
                    <span class="foldername">{{fileOrFolderName}}</span>
                    </div>
                    {% for fileOrFolderName, child in fileOrFolder %}
                        {{menuItem(fileOrFolderName, child, step+1, (currentPath+"/"+fileOrFolderName))}}
                    {% endfor %}
                </div>
            {% endif %}
        </div>
        {%endif%}
    {% endmacro %}

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