将Tagsname设为H2

是否可以在标签区域插入 H2 标题?H2 标题应该是标签的名称。

我无法使用标签横幅组件,因为 H2 不在右侧边栏旁边,而是在其上方。

写一些代码来实现你需要的东西。我在这里为你写了一个简单的解决方案。试试吧,它应该能达到你想要的效果


<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-controls-above/tag-h2">
<h2>
    {{#if h2_tag}}
        {{h2_tag}}
    {{/if}}
</h2>
</script>

<script type="text/discourse-plugin" version="0.8">
api.registerConnectorClass("discovery-list-controls-above", "tag-h2", {
  setupComponent(args, component) {
    if (window.location.pathname?.startsWith("/tag/"))
        component.set("h2_tag", /\/tag\/([^?]+)/.exec(decodeURI(window.location.pathname)).at(1));
  },
});
</script>
2 个赞

哦,非常感谢!!它在我点击的第一个标签上起作用,但如果我切换到另一个标签,h2 不会改变。

哦,抱歉,这是我的问题。我为此做了一些调整

<script type="text/x-handlebars" data-template-name="/connectors/discovery-list-controls-above/tag-h2">
<h2 >
    {{#if h2_tag}}
        {{h2_tag}}
    {{/if}}
    {{log this}}

</h2>
</script>

<script type="text/discourse-plugin" version="0.8">
api.registerConnectorClass("discovery-list-controls-above", "tag-h2", {
  setupComponent(args, component) {
    
    function getTagNameFromURL(url) {
        return /\/tag\/([^?]+)/.exec(decodeURI(url)).at(1)
    }  
    
    if (window.location.pathname?.startsWith("/tag/"))
        component.set("h2_tag", getTagNameFromURL(window.location.pathname));
    api.onPageChange(url => component.set("h2_tag", getTagNameFromURL(url)))
  },
});


</script>
1 个赞