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 分钟就能搞定的任务,但现在已经花了几个小时了……
谢谢!