tiddly-gittly / tidgi-obsidian-manager

Import Obsidian Vault in TiddlyWiki5
https://tiddly-gittly.github.io/tidgi-obsidian-manager/
MIT License
7 stars 0 forks source link

目录树实现 #25

Closed Zacharia2 closed 1 year ago

Zacharia2 commented 1 year ago

tree宏

<<tree prefix:"tree-macro-example-" separator:"-">>

我想根据vaulttree字段的路径进行展开树。

Zacharia2 commented 1 year ago

tree 呈现基于条目名称中的前缀和分隔符号的可展开的树状视图。

参数 prefix 从其生成树状视图的前缀,默认值为 $:/ separator 条目名称的各个部分之间的分隔符号,默认值为 /

应该改为从条目字段中获取才可以

Zacharia2 commented 1 year ago
\define leaf-link(full-title,chunk,separator: "/")
<$link to=<<__full-title__>>><$text text=<<__chunk__>>/></$link>
\end

\define leaf-node(prefix,chunk)
\whitespace trim
<li>
<$list filter="[<__chunk__>is[shadow]] [<__chunk__>is[tiddler]]" variable="full-title">
<span>{{$:/core/images/file}}</span>&#32;<$macrocall $name="leaf-link" full-title=<<full-title>> chunk=<<chunk>>/>
</$list>
</li>
\end

\define branch-node(prefix,chunk,separator: "/")
\whitespace trim
<li>
<$set name="reveal-state" value={{{ [[$:/state/tree/]addsuffix<__prefix__>addsuffix<__chunk__>] }}}>
<$reveal type="nomatch" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="show" class="tc-btn-invisible">
{{$:/core/images/folder}}&#32;<$text text=<<__chunk__>>/>
</$button>
</$reveal>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$button setTitle=<<reveal-state>> setTo="hide" class="tc-btn-invisible">
{{$:/core/images/folder}}&#32;<$text text=<<__chunk__>>/>
</$button>
</$reveal>
&#32;
<span>(<$count filter="[all[shadows+tiddlers]get[vaulttree]removeprefix<__prefix__>removeprefix<__chunk__>] -[<__prefix__>addsuffix<__chunk__>]"/>)</span>
<$reveal type="match" stateTitle=<<reveal-state>> text="show">
<$macrocall $name="tree-node" prefix={{{ [<__prefix__>addsuffix<__chunk__>] }}} separator=<<__separator__>>/>
</$reveal>
</$set>
</li>
\end

\define tree-node(prefix,separator: "/")
\whitespace trim
<ol>
<$list filter="[get[vaulttree]removeprefix<__prefix__>splitbefore<__separator__>sort[]!suffix<__separator__>]" variable="chunk">
<$macrocall $name="leaf-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
<$list filter="[get[vaulttree]removeprefix<__prefix__>splitbefore<__separator__>sort[]suffix<__separator__>]" variable="chunk">
<$macrocall $name="branch-node" prefix=<<__prefix__>> chunk=<<chunk>> separator=<<__separator__>>/>
</$list>
</ol>
\end

\define tree(prefix: "$:/",separator: "/")
\whitespace trim
<div class="tc-tree">
<span><$text text=<<__prefix__>>/></span>
<div>
<$macrocall $name="tree-node" prefix=<<__prefix__>> separator=<<__separator__>>/>
</div>
</div>
\end

<!-- 
1. 条目名必须和字段路径中的名字一致。
2. 显示方式改为多个库列表 
-->
Zacharia2 commented 1 year ago

不过还不能显示条目或文件,只有路径。但是没关系,vaulttree最后都会等同于条目名,只不过多了具体路径。

Zacharia2 commented 1 year ago

[is[system]removeprefix[$:/]splitbefore[/]sort[]!suffix[/]]

筛选出系统条目 然后去掉$:/ 前缀,core/macros/list -> core/ -> core

Zacharia2 commented 1 year ago

算了,还不如用js实现,然后wikitext显示呢,就是混用js与wikitext。

Zacharia2 commented 1 year ago

[[$:/]addsuffix[]is[shadow]] [[$:/]addsuffix[]is[tiddler]]

core -> $:/core