H2としてのTagsname

タグエリアに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