我也注意到了这一点,似乎只有外部链接没有出现在“更多”下方。
我在此组件中使用了内部链接,例如,我有一个打开用户邀请的链接:/my/invited/pending/
从侧边栏打开链接时,我得到:哎呀!该页面不存在或已设为私有。
从 URL 栏访问时,链接可以正常工作。
输入完整 URL (https://domain.com/my/invited/pending/) 时,URL 会这样打开:
https://domain.com/https://domain.com/my/invited/pending/
是的。已知问题。
你好,
这应该可以正常工作:Chat,/chat/browse/open ![]()
是的,我知道。我发送评论可能有点太快了。嗯,绝对是太快了,因为我应该说那里必须使用路径而不是完整的 URL。
聊天的额外链接……嗯,新的侧边栏完全改变了游乐场,它不再需要了。
我查看了 Discourse 的侧边栏代码,以及 @manuel 的图标添加。
看起来目前无法自定义图标的自定义链接,因为汉堡菜单装饰方法不考虑 prefixValue 常量(其中包含图标名称)或类似的东西……
在我看来,使用 api.decorateWidget 的汉堡菜单装饰也将被弃用。请参阅:
https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.js#L534
此外,外部链接不再有效可能源于此:
https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/lib/plugin-api.js#L524
因此,核心代码应该会有一些更改才能实现此功能。
我对 Discourse 的工作原理几乎一无所知,所以我可能完全错了。
我的发现正确吗?
可能与以下内容相关:
至今,外部链接仍然无法正常工作。
内部链接必须以相对路径开头,而不是完整路径。
非常感谢这个有用的组件。我需要添加一些重要的内部链接,但现在汉堡菜单已集成到侧边栏中,我发现它们在“更多”菜单下不太显眼。用户通常很难找到东西,所以我真的需要将它们放在顶层,最好是在“我的帖子”之后。有什么 CSS 技巧可以实现这一点吗?
我认为这超出了 CSS 的能力范围。Discourse 团队已将此功能列入路线图,但进展缓慢(我认为):
我用的是:
<script>
const customHeader = document.createElement("div")
customHeader.className = "sidebar-section-wrapper sidebar-section-community"
customHeader.innerHTML = `
<div class="sidebar-section-header-wrapper sidebar-row">
<button id="ember11" class="sidebar-section-header sidebar-section-header-collapsable btn-flat btn no-text" type="button">
<span class="sidebar-section-header-text"> 法律声明 </span>
</button>
</div>
<div class="sidebar-section-content" id="customNavigation"/>
`
$(document).ready(function () {
// Create the links
const links = [
{ title: "Impressum", src: "/impressum" },
{ title: "Datenschutz", src: "/privacy" },
]
// Mobile
let hamburger = document.getElementById("toggle-hamburger-menu")
if (hamburger) {
hamburger.addEventListener("click", addCustomLinks)
} else {
addCustomLinks()
}
let bool = false;
function addCustomLinks() {
setTimeout(function () {
// Force to wait until navigation has been loaded
const sidebar = document.getElementsByClassName("sidebar-sections")[0]
if (sidebar) {
sidebar.append(customHeader)
if (bool) return;
// Get the customNav Id
const customNavigation = document.getElementById("customNavigation")
if (customNavigation) {
links.filter(function (link) {
let linkDiv = document.createElement("div")
linkDiv.className = "sidebar-section-link-wrapper"
linkDiv.innerHTML = `<a href="${link.src}" class="sidebar-section-link sidebar-section-link-everything sidebar-row ember-view">
<span class="sidebar-section-link-prefix icon"></span>
<span class="sidebar-section-link-content-text"> ${link.title} </span>
</a>
`
customNavigation.append(linkDiv)
let linkIcon = document.getElementById("link_" + link.title)
})
}
}
bool = true
}, 0)
}
})
</script>
您可以在 https://forum.courservio.de/ 看到结果
这个代码的 原始 版本来自 https://meta.discourse.org/t/add-custom-links-to-sidebar/246848。也许能帮到你。
@hosch 哇,非常好,正是我想要的!非常感谢。
@hosch 顺便问一下,有可能把它移到上面一点吗?我想让它出现在“社区”部分之后,甚至可能出现在它之前。
编辑: 看起来可以通过对此进行修改来实现:
Rearrange Existing Hamburger Menu Items - #3 by awesomerobot
.sidebar-sections {
display: flex; /* 设置 flex 布局以便重新排序 */
flex-direction: column;
.sidebar-section-community {
order: -1;
}
}
我想知道是否可以把它移到最高位置?
此方法有一个怪癖,即自定义 div 在切换侧边栏可见性时会消失,例如当浏览器窗口变窄时。这对于平板电脑来说尤其是个问题,平板电脑通常会获得 Discourse 的桌面版本,并且需要点击汉堡菜单才能显示侧边栏。有什么可能的解决方法吗?谢谢!
编辑: 在此处已解决:
感谢 @hosch 和 @Olivier_Lambert 完成此项工作。
能否请您向我这个新手解释一下,我应该在哪里插入这个?![]()
如何重新排列侧边栏/汉堡菜单部分中的元素?
例如,我想将“所有类别”放在“类别”部分中的类别上方,同样将“所有标签”放在标签上方。
谢谢!
您现在知道如何使用组件进行 CSS 了,对吧?将其添加到 head 部分。
您现在还不能轻松做到。它目前还没有完全完成和完善。
我试过了,在使用 src 附近的冒号时出现了一个错误。
再试一次。谢谢。
这仍然存在,之后的解决方案并未解决问题。
设置:Invite friends,/my/invited/pending/,f
离题:
我以前见过这种压缩侧边栏样式,但我似乎找不到它了。这是一个主题组件吗?
您可以使用此 CSS:
#sidebar-section-content-categories,
#sidebar-section-content-tags {
display: flex;
flex-direction: column;
li:last-child {
order: -1;
}
}
![]()

