修改 Discourse 文档以仅允许按标题排序

Discourse Docs 是我选择使用 Discourse 而不是其他论坛软件的主要原因。但是,对我来说,它有一个主要的缺点——默认情况下,它按活动排序。我想完全移除按活动排序的功能,但却找不到如何做到这一点。

我找到了 代码的这一部分,并删除了用于活动排序的 elsif 语句,但这并没有帮助。

      if @filters[:order] == "title"
        if @filters[:ascending].present?
          results = results.reorder('topics.title')
        else
          results = results.reorder('topics.title DESC')
        end
      elsif @filters[:order] == "activity"
        if @filters[:ascending].present?
          results = results.reorder('topics.last_posted_at')
        else
          results = results.reorder('topics.last_posted_at DESC')
        end
      end

我也在 这个文件 中做了同样的操作,但它仍然提供了相同的排序功能。

   context 'when ordering results' do
      context 'by title' do
        it 'should return the list ordered descending' do
          get "/docs.json?order=title"

          expect(response.status).to eq(200)

          json = response.parsed_body
          topics = json['topics']['topic_list']['topics']

          expect(topics[0]['id']).to eq(topic2.id)
          expect(topics[1]['id']).to eq(topic.id)
        end

        it 'should return the list ordered ascending with an additional parameter' do
          get "/docs.json?order=title&ascending=true"

          expect(response.status).to eq(200)

          json = response.parsed_body
          topics = json['topics']['topic_list']['topics']

          expect(topics[0]['id']).to eq(topic.id)
          expect(topics[1]['id']).to eq(topic2.id)
        end
      end

      context 'by date' do
        before do
          topic2.update(last_posted_at: Time.zone.now + 100)
        end

        it 'should return the list ordered descending' do
          get "/docs.json?order=activity"

          expect(response.status).to eq(200)

          json = response.parsed_body
          topics = json['topics']['topic_list']['topics']

          expect(topics[0]['id']).to eq(topic.id)
          expect(topics[1]['id']).to eq(topic2.id)
        end

        it 'should return the list ordered ascending with an additional parameter' do
          get "/docs.json?order=activity&ascending=true"

          expect(response.status).to eq(200)

          json = response.parsed_body
          topics = json['topics']['topic_list']['topics']

          expect(topics[0]['id']).to eq(topic2.id)
          expect(topics[1]['id']).to eq(topic.id)
        end
      end
    end

我直接在服务器上的文件中进行了编辑,也对 Discourse Docs 的一个分支进行了编辑,然后进行了安装。

有人有什么建议吗?我真的以为这会是一个 3 分钟就能搞定的任务,但现在已经花了几个小时了……

谢谢!

1 个赞

算了,我解决了。不知何故,我的 VS Code 中有一个过滤器,它隐藏了 JavaScript 文件。因此,当我搜索 Order、Sort、Activity 等内容时,我没有得到 JS 文件的结果(这些文件显然处理像排序这样的交互功能……)。

我 fork 了该仓库并进行了修改。欢迎任何人使用。它删除了按活动排序的功能,将主题列表默认设置为按标题升序排序,并将类别过滤器默认设置为按字母升序排序。

我不知道如何为用户添加自定义设置,因此在官方插件引入此功能之前,只能这样了。

https://github.com/nickchomey/discourse-docs

4 个赞

如果能将此内容合并到官方版本,那就太好了,可以提交一个 PR 吗?:slight_smile: 这样的话,Discourse Docs Card Filter 中的顺序也会相应调整,对吗?

1 个赞

我真的不知道该怎么做。请随意!理想情况下,应该有一个管理员设置,可以在字母顺序和活动以及/或计数之间进行选择。

1 个赞

谢谢,有人知道如何正确设置吗?我还在配置插件的初学者阶段。

据我所知,这个添加(按字母顺序排序)是由 @Nick_Chomey 作为原始插件的 Fork 添加的。

我该如何最好地使用它?

我可以简单地修改原始 Docs 插件中的一些代码吗?还是需要卸载原始插件并重新安装这个 Fork?

谢谢!

1 个赞

是的,卸载 Discourse Docs 并像安装任何插件一样安装此插件。我不会定期监控/维护其文档更新,但只要有人提醒我,我很乐意这样做。或者,您可以分叉它并自行监控更改。

当然,最好的选择是 Discourse 将其作为官方插件中的设置/功能包含进来。

1 个赞

嘿,感谢你对文档所做的更改(即使是本地更改)!

我已将此移至 Feature 并标记为 docs,以便我们今后更好地跟踪。

3 个赞

太好了,谢谢!

正如您将看到的,我刚刚添加了一些字母排序功能,并注释掉了活动排序。所以它不是一个适合所有人的解决方案。但我相信您可以轻松地集成我的添加,并添加一个设置来允许我们选择/切换可用的排序类型——我对此一无所知。

3 个赞