https://meta.discourse.org/t/custom-top-navigation-links/87225를 참고하여 대부분 해결했습니다.
<script type="text/discourse-plugin" version="0.8.18">
if (I18n.translations.en) {
I18n.translations.en.js.filters.needsreply = {title: "Needs Reply", help: "Unanswered Topics"};
}
// CUSTOMIZE THESE VALUES
// Set the search query
let search_query = '?max_posts=1';
// Exclude certain categories from showing the needs reply menu item
let excludeList = ['pitches', 'weekly-recap', 'staff'];
api.addNavigationBarItem({
name: "needsreply",
displayName:"Needs Reply",
title: "Needs Reply",
href: "/latest" + search_query
});
// Add active class to Needs Reply button
api.modifyClass('component:navigation-item', {
active: Ember.computed("contentFilterMode", "filterMode", function () {
let contentFilterMode = this.get('content').get('filterMode');
console.log(window.location.search.split('&')[0], search_query.split('&')[0])
if (window.location.search && window.location.search.split('&')[0] === search_query.split('&')[0]) {
return contentFilterMode === "needsreply";
} else {
return this._super(contentFilterMode, this.get('filterMode'));
}
}),
});
// Remove max_posts filter and tags filter
api.modifyClass('controller:discovery/topics', {
resetParams: function () {
this.setProperties({max_posts: null});
this.setProperties({tags: null});
this._super();
}
});
</script>
아직 해결하지 못한 부분은 이 스크립트에서 현재 카테고리에 접근하는 방법입니다.
원래 코드에서는 Discourse.NavItem을 통해 현재 카테고리에 접근할 수 있습니다. 이 코드를 기반으로 링크의 동작을 동적으로 변경합니다(숨기거나, 이 카테고리 내의 게시글만 보기 위해 href를 변경).
사용자가 보고 있는 카테고리에 따라 링크의 동작을 커스터마이즈할 수 있도록, 위 스크립트에 현재 카테고리를 주입하는 방법에 대한 해결책을 추천해 주실 분이 있을까요?