support for hide in filetree (#106)

This commit is contained in:
Utsob Roy 2023-03-17 01:35:38 +06:00 committed by GitHub
parent 71fc4b8d37
commit 80d8ce1463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 9 deletions

View File

@ -46,6 +46,7 @@ function getPermalinkMeta(path, key) {
let permalink = "/";
let name = key.replace(".md", "");
let noteIcon = process.env.NOTE_ICON_DEFAULT;
let hide = false;
try {
const file = fs.readFileSync(`${path}`, "utf8");
const frontMatter = matter(file);
@ -61,11 +62,16 @@ function getPermalinkMeta(path, key) {
if (frontMatter.data.noteIcon) {
noteIcon = frontMatter.data.noteIcon;
}
// Reason for adding the hide flag instead of removing completely from file tree is to
// allow users to use the filetree data elsewhere without the fear of losing any data.
if (frontMatter.data.hide) {
hide = frontMatter.data.hide;
}
} catch {
//ignore
}
return { permalink, name, noteIcon };
return { permalink, name, noteIcon, hide };
}
function populateWithPermalink(tree) {
@ -74,13 +80,8 @@ function populateWithPermalink(tree) {
const isNote = tree[key].path.endsWith(".md");
tree[key].isNote = isNote;
if (isNote) {
let { permalink, name, noteIcon } = getPermalinkMeta(
tree[key].path,
key
);
tree[key].permalink = permalink;
tree[key].name = name;
tree[key].noteIcon = noteIcon;
let meta = getPermalinkMeta(tree[key].path, key);
Object.assign(tree[key], meta);
}
} else {
tree[key].isFolder = true;

View File

@ -1,7 +1,7 @@
{% 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 %}
{%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>