Hi
I use this theme component. One of the items in the menú points to a category and I would like to inform the unread topics for this category.

Instead of Agora I would like Agora (3) for an user who has three unread topics in this category (same behaviour as standard link “Unread”).
Any idea?
Thanks in advance.
manuel
(Manuel Kostka)
52
有人知道如何添加一个实际相对于当前路由的标签链接吗?我想使用一个名为“关于”的标签,并将其作为顶部链接提供给用户所在分类中的“关于”主题。
例如,用户在分类 /c/feedback/7 中。选择“关于”将指向 /tags/c/feedback/7/about。
2 个赞
sok777
(sok)
55
快速提问-
我正在尝试创建此内容,并将 URL 设置为 ?order=created,以便用户可以浏览最新主题。
这在桌面端运行完美,但在移动端却失败了——导航栏只是重新加载,不会显示下拉菜单。
我想我知道为什么会这样……
该组件有下面这行:
if (window.location.pathname.match(sec2)) {
$(navHeader).html(filter + markd);
}
因为 reg…? 本身被用作特殊 reg 标记,并且该参数应该与 window.location.search 进行比较。
我 fork 了该组件,并将其更改为以下代码,它就可以工作了。
if (sec[2].indexOf("?") === -1) {
if (window.location.pathname.match(sec[2])) {
$(navHeader).html(filter + markd);
}
} else {
// reg ?->/?
sec[2] = sec[2].replace(/\?/g, "/?");
const pathWithSearch = window.location.pathname + window.location.search;
if (pathWithSearch.match(sec[2])) {
$(navHeader).html(filter + markd);
}
}
1 个赞
Discourse-nav-links-component/mobile/head_tag.html ,替换匹配的代码。
1 个赞
nathank
(Nathan Kershaw)
60
为什么不将其作为一个PR提交,以便大家都能受益呢?
4 个赞
我可以这样做吗?我一直觉得我的代码水平太差……有点不好意思这么做。谢谢你的建议!!!我会修改它并创建一个 PR!
1 个赞
nathank
(Nathan Kershaw)
62
我也这么觉得我的贡献尝试!!
不过,@team(以及他们的自动化工具)似乎很擅长整理代码。
一旦你把它做成一个PR,你就可以在这里的Meta上发布PR链接,它会显示一个很棒的嵌入式PR状态实时更新。
5 个赞
piffy
65
我无法说我找到了一个理想的解决方案,但我找到了对我来说问题的根源。
问题可以在这里找到
https://github.com/discourse/Discourse-nav-links-component/blob/main/desktop/head_tag.html
特别是这部分:
api.modifyClass("component:navigation-item", {
pluginId: "discourse-nav-links-component",
active: Ember.computed("contentFilterMode", "filterMode", function() {
let contentFilterMode = this.get("content").get("filterMode");
if (window.location.pathname === location) {
return contentFilterMode === filter;
} else {
return this._super(contentFilterMode, this.get("filterMode"));
}
})
});
看起来这会设置每个导航链接的“活动”状态。坦率地说,它如何决定以及所有这些变量是什么的逻辑对我来说相当不透明。但问题在于:
if (window.location.pathname === location) {
return contentFilterMode === filter;
} else {
return this._super(contentFilterMode, this.get("filterMode"));
}
对我来说,这会检查页面 URL 是否与导航栏 URL 的位置相同,如果是,则返回 contentFilterMode === filter 的结果,这两个变量对我来说都有些不清楚。如果条件失败,它似乎只是运行常规逻辑来判断是否应将某项标记为活动(这就是为什么我的非自定义链接似乎工作正常)。问题是,虽然这段代码为每个导航链接正确运行一次,但 location 变量似乎始终是“categories”,因此对于自定义链接,if 语句始终为 false。此外,即使我通过将 location 替换为 this.get("content").href 来修复 location 变量,返回的值也始终为 false,因为 filter 变量也始终设置为“categories”。
通常我会做一个 PR 来修复这个问题,但实际的根本问题仍然让我感到困惑。我提出了一个对我有用的解决方法,但它稍微改变了这个组件的文档功能,所以我宁愿不提交 PR。我认为在某些边缘情况下它也可能不起作用,例如如果你的主页设置为 /latest
api.modifyClass("component:navigation-item", {
pluginId: "discourse-nav-links-component",
active: Ember.computed("contentFilterMode", "filterMode", function() {
return window.location.pathname.includes(this.get("content").href);
})
});
基本上它只是检查当前 URL 是否包含导航栏 URL 作为子字符串。如果是,则突出显示它。
4 个赞
Tris20
(Tristan)
拆分了此话题
67
您好。我正在浏览此帖子。请问是否有办法标记未读主题?谢谢。
carbonrich
(Richard Hawkins)
70
这可能是一个非常有用的组件,但似乎有一些基本(但超出我修复能力)的错误阻碍了它的广泛使用。这些问题会得到修复吗?
carbonrich
(Richard Hawkins)
73
是的,抱歉,我遇到的主要问题是:
我猜它只需要一些更有针对性的 CSS,但我也可能弄错了!
1 个赞