让 Discourse 的 UI 更像 Flarum 会有多难?

Scale of 1-10 how difficult would it be? Hopefully this question doesn’t peeve anyone but Im torn between the two. Flarum has a really clean interface:

  1. Topic list is centered with no lines in between, yet its still easy to read.
  2. Search bar is all in the same sticky header and not a ‘nook’
  3. Category markers look better, not just a 4x4 square.

Hmm… thats about it I think… Does this make sense? Sorry if this is posted to the wrong section.

Sidenote info: Im currently testing out both software even though having a hard time putting discourse on the same server vs my other 1 click install server. At least I have this working because for some reason I get a blank page when finalizing the flarum install. Really if Discourse had the same Flarum UI and features discourse currently has it be a much easier pick :smiley:

6 个赞
10 个赞

The answer is that it would be easy.

Discourse has a Theming system (see themes tag) that makes the kind of changes you’re talking about just a matter of adding the right CSS rules.

You can add CSS either directly in the “Site Customisations” Admin Panel UI, or on your local machine in your editor of choice via the CLI, with the ability to preview changes instantly on your site.

If you’re not a coder, you can hire one in the marketplace.

As has already been mentioned, you can use my header search theme component for the header search part of your list.

16 个赞

I like the Flarum homepage as shown in the second screenshot! Not sure how doable that would be with CSS given that the categories in Discourse are a dropdown. But I like the idea of having the categories as permanent sidebar on the left hand side (while browsing topics).

8 个赞

It’s a nice looking design, but only when you are at the top of the page. Then the color banner disappears and you are left with just the white main header.
If you want to have a color header, then the topic banner won’t look as sexy. (would look like having two headers).
Also, the categories bullet list in Flarum doesn’t show descriptions. Did you try Material Design Stock Theme for Discourse?

2 个赞

It could be done with a theme component, though it would require some javascript.

2 个赞

I just remembered there’s some prior art on this by @bts here:

Once there’s a published theme available for this it’d be great if the two of you could compare notes and ideally end up with a single codebase.

9 个赞

感谢 @erlend_sh 的敏锐发现!我之前还没看到这个话题。是的,去年我们确实花了一些时间专门研究这个问题,试图实现类似 Flarum 风格的标题栏。以下是我们网站上的效果:我们的网站



以下是我们为此设计的 HTML / CSS 核心代码:

CSS:
(以下内容全部放在“common”中——除此之外,针对桌面端和移动端还有一些细微的边距/内边距调整,此处未列出。)

/* 通用 */

body {
    overflow-x: hidden;
}

.custom-cat-header {
	display: block;
	margin-left: -9999px!important;
	padding-left: 9999px!important;
	margin-right: -9999px!important;
	padding-right: 9999px!important;
	text-align: center;
	margin-top: -18px;
}

.custom-cat-header p {
    color: #dddddd;
}

.custom-cat-header h1 {
    display: inline-block;
    margin-top: 20px;
    color: #dddddd;
    background-color: #222222;
    border-radius: 5px;
    width: inherit;
}

/* 所有分类 */
.custom-cat-header-all-categories {display: none;}
body.navigation-categories .custom-cat-header-all-categories, body.navigation-topics .custom-cat-header-all-categories {
    display: block; 
    background-color: #b1880b;
}
.custom-cat-header-all-categories h1 {color: #d4a411;}

/* 演奏技巧 */
.custom-cat-header-playing-technique {display: none;}
body.category-playing-technique .custom-cat-header-playing-technique {
    display: block; 
    background-color: #9c2116;
}
.custom-cat-header-playing-technique h1 {color: #d62e1f;}
body.category-playing-technique .custom-cat-header-all-categories {display: none;}

/* 为所有其他分类重复此操作!*/

HTML(放在“标题后”部分):

<!-- 所有分类 -->
<div class="custom-cat-header custom-cat-header-all-categories">
    <a href="https://forum.troygrady.com/"><h1>所有分类</h1></a>
    <p>欢迎来到 Cracking the Code 论坛!</p>
</div>

<!-- 演奏技巧 -->
<div class="custom-cat-header custom-cat-header-playing-technique">
    <a href="https://forum.troygrady.com/c/playing-technique"><h1>演奏技巧</h1></a>
    <p>关于拨片角度、分块、按弦、动作机制等技术问题,请在此提问。</p>
</div>

<!-- 为所有其他分类重复此操作!-->

这在视觉上已经相当精致了……但也非常定制化/ hacky,需要大量重复的手动编辑。对于我们大约十几个分类来说还算容易处理,但如果想要更高的灵活性,我觉得将其做成一个简单的插件会很有趣,该插件可以:

  • 自动获取并插入分类描述
  • 自动处理颜色计算(我们的颜色与分类颜色相似,但我们手动将标题背景色调暗了一些,并将 h1“胶囊”文本颜色调亮了一些,以获得更好的对比度/可读性)。

我没有制作插件的经验。不过目前看来,将 @lll 和我构思的内容结合成一个主题组件,似乎是不错的下一步!

16 个赞

Hey @lll I didnt see your reply before, and I didn’t test yours out before seeing bts’s version but I like that you did Javascript, leads to more connection when editing/change styles. It would be awesome if this was a theme component, idk how to do that yet but here’s what I did with bts’ code:

<!-- After Header section -->

<!-- PLAYING TECHNIQUE -->
<div class="custom-cat-header custom-cat-header-nites-cinema">
    <a href="https://forum.troygrady.com/c/playing-technique"><h1>Playing Technique</h1></a>
    <p>Pickslanting, chunking, fretting, motion mechanics — ask your technical questions here.</p>
    <img src="https://d11a6trkgmumsb.cloudfront.net/original/3X/c/b/cb4bec8901221d4a646e45e1fa03db3a65e17f59.png">
</div>

I added that img src things as a random idea I had after I was done with doing the below edit. Obviously you gotta make another style rule to make sure the img/icon fits in the header (I did it via inspect elements), the main thing I was going for:

/* In common CSS */

/* PLAYING TECHNIQUE */
.custom-cat-header-nites-cinema {display: none;}
body.category-nites-cinema  .custom-cat-header-nites-cinema {
    display: block; 
    background: url('http://wallpaperscraft.com/image/starry_sky_tree_milky_way_radiance_120245_602x339.jpg') 0px -300px fixed no-repeat;}
.custom-cat-header-playing-technique h1 {color: #d62e1f;}
body.category-playing-technique .custom-cat-header-all-categories {display: none;}

/* repeat for all other categories! */

This is what I did on my old forum version of bbpress which was a edit of a clone to make it look like flarum, Reference: https://github.com/Sceko/bbFlarum

but I added in background image and fixed position to make it look cool :sunglasses:

The result:

What can be done with a theme component if you add in my idea:

  1. javascript to pull in icon banner (if people like that) from category image or wherever
  2. javascript pulling in background img sources vs manually entering
  3. A commentedout CSS section for people who wanna do my edit, explaining what it does.

Thoughts? Again, thanks for the input both of you, and everyone in this topic

7 个赞

I am definitely interested in implementing this once it gets sorted. Thumbs up, guys.

4 个赞

So theres gonna be a bit of redundancy if you choose to have category image and description turned on, unless you wanna have different stuff in the header or just a background. Just gonna have to decide and finagle with the theme because I dont think category image and description is a themeable thing, its a build it setting for discourse.

Still awesome to have these options. All im gonna have is 2 main themes for my forums. Sometimes i get in an indecisive/perfectionist loop

3 个赞

Yea the example you posted and the one I edited, it shows up on 2 of those locations (for category banner)

Off the top of your head is there a way to just show it on one of those pages (ie. Only on topic pages?[ The actual posts inside the category] ) vss CSS? If not do you think JavaScript could do it?

Well my edit I was gonna post is this: (For disabling the category description and logo only in the category page and nowhere else)

.category-heading {
clear: both;
display: none;
}

Then @awesomerobot comes along and totally 1ups me,lol. Yea dude that looks way better than the manual edits I was gonna do :open_mouth:

1 个赞

I put together a rough theme component for this so you don’t have to create a bunch of redundant markup to show/hide… This will pull the appropriate category name, description, and background/text colors when you’re on a category list page.

My JS is hacked up from a few different posts on Meta, so definitely please improve it if you can.

Put this in common/header

<script type="text/discourse-plugin" version="0.8">
    const container = Discourse.__container__;    
    const { h } = require('virtual-dom');
   
    api.createWidget('category-header-widget', {
        tagName: 'span', 
        html(attrs, state) {
        
        const path = window.location.pathname;
        let category;
          
        const controller = container.lookup('controller:navigation/category');
        category = controller.get("category");
        
        if(/^\/c\//.test(path)) {
            $("body").addClass("category-header");            
            return h('div.category-title-header', {
                "attributes" : {
                    "style" : "background-color: #" + category.color + "; color: #" + category.text_color + ";"
                }

            }, h('div.category-title-contents', [
                    h('h1', category.name),   
                    h('p', category.description_text)          
                ])
            );
            } else {
                $("body").removeClass("category-header");
            }   
        }      
    }),

    api.decorateWidget('category-header-widget:after', helper => {
        helper.widget.appEvents.on('page:changed', () => {
            helper.widget.scheduleRerender();
        });
    });

</script> 
  
<script type='text/x-handlebars' data-template-name='/connectors/below-site-header/category-header-widget'>
    {{mount-widget widget="category-header-widget"}}
</script>

This is common/CSS

.category-title-header {
  padding-top: 60px;
  display: flex;
  text-align: center;
  width: 100%;
  justify-content: center;
  .category-title-contents {
    max-width: 500px;
    padding: 40px 0;
  }
}
.category-header {
 #main-outlet {
     padding-top: 20px;
 }
}

You can also target specific category headers with additional custom CSS by using this structure:

body.category-example {
    .category-title-header {
        background: url(example.jpg);
    }
}

With some time this could definitely be improved to support tags & topic titles!

Update: Made some refinements and put this in a repo as a theme component

29 个赞

This already works great @awesomerobot!
Could you please add an “All Categories” banner as well?

4 个赞

Nice work! Anyone having this live on their Discourse? I would like to check it out how looks like…

3 个赞

I add this in my forum and it’s perfect! A little thing is that it takes only the first lines of the description of the categories and don’t show links.

This is my text with links :

We only see the first two lines (and without links)

2 个赞

我希望这里能多一些关于 Flarum 其他潜在优点的讨论。Flarum 终于正式发布了 1.0 版本。尽管我仍然认为 Discourse 在大多数方面更胜一筹,但我 喜欢 Flarum 的设计/用户界面中的一些地方。因此,如果其他人也怀念 Flarum 风格的美学,我希望你们也能在此发声,或许我们最终能共同打造一个主题(遗憾的是,我缺乏相关技能,但如果有人感兴趣,我或许能在资金方面为团队贡献一份力量)。

目前,为了从除页眉之外的部分入手,我认为侧边栏基本可以通过以下方式复现:

不过它不支持标签。或者也可以尝试这个:

问题是,这两个方案似乎都需要更新、维护或重构。

据我所知,Discourse 似乎完全缺失一种更明显的文本框式“回复”区域设计,我认为这是对“回复”按钮的一个不错的替代方案:


请注意,这不仅仅是一种看起来可能“更简单”或“更顺畅”的回复方式。头像图片 直接呈现 在其中,实际上是一个有趣的细节,我个人认为它能鼓励互动,因为它微妙地让你感觉已经参与其中。

事实上,我认为这个想法足够好,值得单独作为一个功能请求提出……

5 个赞

另外请考虑:Layouts Plugin

3 个赞

哦,对,好主意!我会尽快试试。

1 个赞

没错;回复被设计为一个需要主动触发的独立操作,而非预填的输入框,这是 Discourse 从最早期就刻意采用的设计元素。我们希望鼓励用户先阅读,而不是立即回复(因为“网上总有人是错的”)。我认为,当前互联网上的许多问题,都可以追溯到人们反应过快、思考不足。

聊天功能的引入,也应能缓解“必须立即以脑海中浮现的第一种情绪回应”的冲动,并将其引导至更合适的方式。

如果你想要侧边栏功能,那是 Teams 的特性。

8 个赞