如何修改TiddlyTools TagCloud代码以仅展示指定标签
TiddlyTools TagCloud 仅展示指定标签修改方案
修改思路
原工具默认会加载所有系统和普通标签,我们只需要给所有标签读取的过滤器加上白名单限制即可,无需调整其他渲染和排序逻辑。
具体修改步骤
- 新增白名单标签宏,方便后续统一调整要展示的标签
在代码最开头的\define config() $:/config/TiddlyTools/TagCloud下方新增一行:
\define allowed-tags() [[TiddlyTools]] [[$:/tags/ControlPanel]]
后续需要调整展示的标签,直接修改这行的内容即可,新增标签按[[标签名]]格式追加即可。
- 修改3处标签读取的过滤器
找到
tagcloud_get宏内的过滤器,把原代码<$list filter="[all[tiddlers+shadows]tags[]]">
修改为<$list filter="[all[tiddlers+shadows]tags[]filter<allowed-tags>]">找到
tagcloud_showbyname宏内的过滤器,把原代码<$list filter="[all[tiddlers+shadows]tags[]sort[]]">
修改为<$list filter="[all[tiddlers+shadows]tags[]filter<allowed-tags>sort[]]">找到底部标签统计行的过滤器,把原代码
<$text text={{{ [all[tiddlers+shadows]tags[]count[]]" }}}/>
修改为<$text text={{{ [all[tiddlers+shadows]tags[]filter<allowed-tags>count[]]" }}}/>
(可选)如果需要统计的总打标条目数只算白名单标签的关联条目,把下方统计总数的过滤器也同样加上filter<allowed-tags>即可。
修改后完整代码
\define config() $:/config/TiddlyTools/TagCloud \define allowed-tags() [[TiddlyTools]] [[$:/tags/ControlPanel]] \define tag-pill-styles() ---------- copied from $:/core/macros/tag - use $(count)$ to set font-size \define tag-pill-styles() background-color:$(backgroundColor)$; fill:$(foregroundColor)$; color:$(foregroundColor)$; font-size:calc(0.5em + (0.2em * ($(count)$ / 5) ) ); \end \define tag-pill-inner() ---------- copied from $:/core/macros/tag - added $(count)$ display in pill \define tag-pill-inner(tag,icon,colour,fallbackTarget,colourA,colourB,element-tag,element-attributes,actions) <$vars foregroundColor=<<contrastcolour target:"""$colour$""" fallbackTarget:"""$fallbackTarget$""" colourA:"""$colourA$""" colourB:"""$colourB$""">> backgroundColor="""$colour$"""> <$element-tag$ $element-attributes$ class="tc-tag-label tc-btn-invisible" style=<<tag-pill-styles>>> $actions$<$transclude tiddler="""$icon$"""/> <$view tiddler=<<__tag__>> field="title" format="text" /> ($(count)$) </$element-tag$> </$vars> \end \define tagcloud_get() <$list filter="[all[tiddlers+shadows]tags[]filter<allowed-tags>]"> <$text text="[["/>{{{ [<currentTiddler>tagging[]count[]divide[10000]] }}};<<currentTiddler>><$text text="]]"/> </$list> \end \define tagcloud_sort() <$list filter="[enlist<items>!nsort[]]"> <$list filter="[<currentTiddler>split[;]last[]]"><$text text="[["/> <<currentTiddler>><$text text="]]"/></$list> </$list> \end \define tagcloud_showbycount() <$wikify name="items" text=<<tagcloud_get>> > <$wikify name="sorted" text=<<tagcloud_sort>> > <$list filter=<<sorted>>> <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}> <<tag>> </$vars> </$list> </$wikify> </$wikify> \end \define tagcloud_showbyname() <$list filter="[all[tiddlers+shadows]tags[]filter<allowed-tags>sort[]]"> <$vars count={{{ [<currentTiddler>tagging[]count[]] }}}> <<tag>> </$vars> </$list> \end <style> .tt-tagcloud input { width:auto !important; } </style> <div class="tt-tagcloud"> There are ''<$text text={{{ [all[tiddlers+shadows]tags[]filter<allowed-tags>count[]]" }}}/> tags'' and a total of ''<$text text={{{ [all[tiddlers+shadows]tags[]filter<allowed-tags>tagging[]count[]]" }}}/> tagged tiddlers''<br> sort by: <$radio tiddler=<<config>> field="sortorder" value="count"> tagging count </$radio> <$radio tiddler=<<config>> field="sortorder" value="name"> tag name </$radio> <p> <$reveal default={{{ [<config>get[sortorder]] ~[[count]] }}} type="match" text="count"> <<tagcloud_showbycount>> </$reveal> <$reveal default={{{ [<config>get[sortorder]] }}} type="match" text="name"> <<tagcloud_showbyname>> </$reveal> </p>
内容的提问来源于stack exchange,提问作者ruhagen
相关产品推荐
相关产品推荐

