为群组定制的主页

Overview

When installed and added to the active theme, this theme component enables you to control the ‘homepage’, allowing it to be different from the set of pages Discourse allows by default, as well as having different groups have different “homepages” (e.g., group members care only or mostly about a particular category). This can be for all users, anon (non-logged in), mobile users, or according to a user’s primary group. Initially developed by @pfaffman. See User-specific Discourse home page.

Use-cases:

  1. You want something other than the ‘normal’ homepage
  2. You want a different homepage for Anonymous users
  3. You want a different homepage for Mobile users
  4. You have a group of folk only interested in using a small slice of your instance. They want to only see their specific category.
  5. Temporarily redirect a group of your punters to a special event or the like.
  6. Have different landing pages for different groups.

Settings

custom default homepage

Allows you to set a global custom homepage.

anon page

This enables you to use a specified page for those who aren’t logged into your site. Over-rides the global one above.

mobile homepage

As per Force Mobile Homepage this allows you to set a different homepage for mobile users. This will override the options chosen above.

group page map

This allows for multiple entries. Each entry should be of the format group_name:path , where group_name is the group slug (not the group Full Name ) and the path is the desired home page (e.g., “/c/great-category/4”).

Ensure that the target users have the specified group denoted as their primary group and you are away. If the theme setting or the user primary group is changed, a reload will be required to have the change take effect.

:warning: The users with a specified group as primary will not be able to reach your ‘normal’ homepage unless you ensure that there is a way for them to do that (such as the native sidebar functionality)

Known Issue - limited to relative URLs

And that doesn’t include Page Publishing, unfortunately. However, you can workaround this by creating a permalink that will redirect to the external site and point to that permalink.

  • @pfaffman tested this with a permalink at /go-google that redirects to https://google.com and something like group-name:/go-google
  • you create Permalinks via the admin settings /admin/customize/permalinks
42 个赞

这是一个群组修改器! :crazy_face:

干得好!相当强大的TC……

我们在 PR 阶段进行了一些调整,解决了以下问题:

并且还增加了对移动主页的控制,如果您希望它有所不同(根据 https://meta.discourse.org/t/force-mobile-homepage/95705)。

这大大增强了它的功能,希望您喜欢。

6 个赞

你好!!这太棒了!! :slight_smile:
非常感谢,这对我(用例 1)的案例来说确实很重要。
我必须问一下,“具有指定组作为主要的用户将无法访问您的‘普通’主页”这句话,您说的“积极提供一种让他们这样做的途径”是什么意思?
另外,根据这个概念,在主页上根据用户所属的组显示类别的特定顺序也会很有用。例如,将他们的类别显示在顶部,而所有其他类别显示在下方。您认为这是否可行?(如果还没有的话?)。

这意味着站点设置中设置的任何主页都将被覆盖。因此,如果您希望用户能够访问它,那么您需要确保有一个链接可以让他们到达那里……以某种方式。

我无法想象那会如何运作(也许是我想象力不好 :man_shrugging:)。我想到的用例是让用户将不同的类别设置为他们的主页,如果他们属于某个组。例如,汽车网站可以让你选择福特组作为你的主页。

如果您希望为不同的组提供不同的内容,我认为您可以通过设置默认的静音类别来实现。

1 个赞

嗨 Jay!
感谢您的回复 :slight_smile:
假设我想根据用户所属的组,将不同的类别“固定”在顶部。我的意思是,每个不同的用户都会看到一个不同的“固定”类别。我不想向用户隐藏其他类别,只是想让他们在主页上(如果可能的话!)轻松看到并随时可用他们最常使用的类别。
(当然,我在这里不是“强求”任何东西,只是询问是否可以使用现有的设置/组件来实现)

1 个赞

@lisandro_iaffar

我有一个完全相同的用例,我在这里发布了:Showcased Categories - #18 by jrgong

在我的例子中,我设置了广告客户的客户端类别作为主页,使用了这个 TC,但他们觉得很困惑,并要求我再次删除它。因此,我认为带有此类修改的展示类别 TC 将是完美的解决方案。

3 个赞

你好 @jrgong:slight_smile:
非常感谢你向我介绍这个话题!是的!那将是完美的!我将支持这个想法 :muscle:
再次感谢!

我刚刚提交了一个更新,解决了 preLoadStore 导致首次加载时显示错误主题的问题。

5 个赞

嘿 Jay,我注意到上次 Discourse 更新后出现了一个错误:

1 个赞

您确定那是 GitHub 上最新的版本吗?(不是您的分支或静态/本地版本?)我刚刚运行了一次升级,它正在工作。另外,查看代码,api 只在一个地方使用:

        const user = api.getCurrentUser();

而这在一个定义了 api 的块内。

这很奇怪。我已将其从该实例中删除,因为它已有多余。它似乎在另一个实例中更新后运行正常。奇怪。感谢您的查看!

您知道它如何与侧边栏交互吗?我需要尝试一下,因为它看起来解决了返回论坛主页的路由问题。

1 个赞

我还没有测试过,但我无法想象为什么不行。请注意,我的想象力可能不是很好。

1 个赞

我正在对此进行测试,但有两个评论:

  1. 匿名路径对我们不起作用——它是否需要与组映射相同的格式?
  2. 如果有一个默认设置可以应用于所有人,那就太好了。

1 个赞

嗯。我以为我在列表提交上测试过它。

确实如此。我猜那些需要它的人不需要更改为不支持的主页。

我明天会试着看看,不过可能要到下周了。

1 个赞

供参考,昨天我玩的时候它对我来说是有效的(我里面有 tag/featured/

对我来说,它工作正常。它只需要相对路径。

但我遇到了和你一样的问题,直到我将组件添加到主题中!你做到了吗?

是的,我确实认为需要添加这个。在这里:

2 个赞

是的,登录时同一个主题可以正常工作,只是匿名用户不行。为了确保万无一失:相对 URL 需要以 / 开头吗?我问是因为 Jammy 使用了 tag/featured/ 而我使用的是 /c/artwork/8

我解决了这个问题——是我的错。

太好了,谢谢!但它还没有显示为更新——应该吗?

1 个赞

它在我的 fork 中。如果你愿意,可以先直接从这里安装它,直到 Jay 合并它:

有或没有 / 都可以

顺便说一句

你的配置方式将无法正常工作,因为用户不能将任何信任级别组作为其主要组。

仔细想想——它是否已添加到站点的默认主题(匿名用户使用此主题)?我曾因为将组件添加到我的“开发”主题而不是默认主题而遇到麻烦。

2 个赞

是的,我找到了错误——它与那个有关 :man_facepalming:

2 个赞