태그 이름을 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>

아, 정말 감사합니다!! 첫 번째 태그를 클릭했을 때는 잘 작동하는데, 다른 태그로 바꾸면 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>