特定のカテゴリにトップナビにトピックを追加する方法は?

I want to add a topic to a top menu but not on all categories, just a specific one.
What code should I write?
Thanks

Found those topics but none of them was for a specific category…

https://meta.discourse.org/t/how-to-add-external-link-on-top-menu/9508/6

https://meta.discourse.org/t/best-way-to-customize-top-menu/35336

https://meta.discourse.org/t/after-add-a-link-to-top-menu-how-can-custom-the-link-showed-on-mobile/20679

Tested this solution a bit more (modified from this post) try this (replace “Travel” with your category name):


<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.en.js.filters.bugs = { title: "Bugs", help: "Open Bugs" };
  I18n.translations.en.js.filters.google = { title: "Google", help: "Navigate to Google" };

  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);
      if(category && category.name == "Travel") {
        list.push(Discourse.ExternalNavItem.create({href: '/category/bug', name: 'bugs'}));
        list.push(Discourse.ExternalNavItem.create({href: 'https://google.com', name: 'google'}));
      }
      return list;
    }
  });
</script>

Maybe a bug with translation [fr.filters.Liste.title]

And is it possible to move it here?

I18n.translations.en.js.filters.bugs = { title: “Bugs”, help: “Open Bugs” };
I18n.translations.en.js.filters.google = { title: “Google”, help: “Navigate to Google” };

Those are for English-based forums…

Your forum is French, so use I18n.translations.fr instead.

Still the same thing with translations.fr

<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.fr.js.filters.liste = { title: "Liste", help: "Liste des formations" };

  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);
      if(category && category.name == "Formations") {
        list.push(Discourse.ExternalNavItem.create({href: '/t/liste-2-0-des-formations-sur-lautosuffisance-et-la-consommation-ecoresponsable-en-2018/306', name: 'Liste'}));
      }
      return list;
    }
  });
</script>

Try name: 'liste'instead

It’s working, perfect! Doesn’t matter if it’s here. Thanks so much!

Where has that lovely calendar come from??

Discourse.NavItem の非推奨化後、これはもう機能しなくなったようです。この投稿で、カスタムトップナビゲーションリンク が解決策になると言及されていました:

ただし、このコンポーネントは現在の場所に基づいてリンク URL を動的に確認する機能を持っていません。
私のユースケースでは、メインページとサブカテゴリで異なるリンクを設定したいと考えています。例えば、現在のカテゴリに基づいて「未完了/完了」タグフィルターのナビゲーション項目を表示したい場合、以前は以下のコードを使用できていましたが、現在は動作しません:

<script>
Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.en.js.filters.unfinished = { title: "tbc", help: "placeholder" };
  I18n.translations.en.js.filters.finished = { title: "finished", help: "placeholder" };

  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);
      var url = category ? category.url : "";
      // メニューと 2 つの特定のカテゴリでは、異なる URL を持つ 2 つのナビゲーション項目が表示されます
      if(!category || (category && url && (url.includes("mix") || url.includes("other")))) {
        var tbc_url = category ? "/tags" + url + "/tbc" : "/tags/tbc";
        var finish_url = category ? "/tags" + url + "/finished" : "/tags/finished";
        
        list.push(Discourse.ExternalNavItem.create({href: tbc_url, name: 'tbc'}));
        list.push(Discourse.ExternalNavItem.create({href: finish_url, name: 'finish'}));
      }
      return list;
    }
  });
</script>

現在の navigation-item コンポーネントに基づいて、このコードをどのように更新すればよいか、お手伝いいただけますでしょうか?あるいは、より一般的な質問として、Discourse.NavItem の代替となる現在の使い方をどのように見つけることができますか?

よろしくお願いします!

まだ機能していますか?試したときは動作しませんでした。プラグインバージョンを追加すべきでしょうか?