The problem I’m seeing is that the tags route doesn’t respect the max_posts
filter, for example, this doesn’t work: https://meta.discourse.org/tags/pr-welcome?max_posts=1.
A workaround for this is to use tags
as a filter in the URL. Something like this might be close to what you’re looking for. It needs a bit of testing before I’d use it on a live site.
<script type="text/discourse-plugin" version="0.8.18">
if (I18n.translations.en) {
I18n.translations.en.js.filters.unanswered = {title: "Unanswered", help: "Topics that have not be answered"};
}
api.modifyClass('component:navigation-item', {
active: Ember.computed("contentFilterMode", "filterMode", function () {
let contentFilterMode = this.get('content').get('filterMode');
if (window.location.search && window.location.search.split('&')[0] === "?max_posts=1") {
return contentFilterMode === "unanswered";
} else {
return this._super(contentFilterMode, this.get('filterMode'));
}
}),
});
api.modifyClass('controller:discovery/topics', {
resetParams: function () {
this.setProperties({max_posts: null});
this.setProperties({tags: null});
this._super();
}
});
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href: function () {
return this.get('href');
}.property("href")
});
Discourse.NavItem.reopenClass({
buildList: function (category, args) {
let list = this._super(category, args),
tag = args.tagId,
unansweredHref;
if (!category) {
unansweredHref = tag ? '/latest/?max_posts=1&tags=' + tag : '/latest/?max_posts=1';
}
else if (!category.parentCategory) {
unansweredHref = tag ? '/c/' + category.slug + '?max_posts=1&tags=' + tag : '/c/' + category.slug + '?max_posts=1';
} else {
unansweredHref = tag ? '/c/' + category.parentCategory.slug + '/' + category.slug + '?max_posts=1&tags=' + tag :
'/c/' + category.parentCategory.slug + '/' + category.slug + '?max_posts=1';
}
list.push(Discourse.ExternalNavItem.create({href: unansweredHref, name: 'unanswered'}));
return list;
}
});
</script>