mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:41:29 +08:00
FEATURE: Onebox local categories (#11311)
* FEATURE: onebox for local categories This commit adjusts the category onebox to look more like the category boxes do on the category page. Co-authored-by: Jordan Vidrine <jordan@jordanvidrine.com>
This commit is contained in:
parent
416f984c5e
commit
51f9a56137
33
lib/onebox/templates/discourse_category_onebox.mustache
Normal file
33
lib/onebox/templates/discourse_category_onebox.mustache
Normal file
|
@ -0,0 +1,33 @@
|
|||
<aside class="onebox" style="border-left: 5px solid #{{color}}">
|
||||
<article class="onebox-body category-onebox">
|
||||
{{#logo_url}}
|
||||
<img src="{{logo_url}}" class="thumbnail" />
|
||||
{{/logo_url}}
|
||||
<h3>
|
||||
<a class="badge-wrapper bullet" href="{{url}}">
|
||||
<span class="clear-badge"><span>{{{name}}}</span></span>
|
||||
</a>
|
||||
</h3>
|
||||
{{#description}}
|
||||
<div>
|
||||
<span class="description">
|
||||
<p>{{{description}}}</p>
|
||||
</span>
|
||||
</div>
|
||||
{{/description}}
|
||||
{{#has_subcategories}}
|
||||
<div class="subcategories">
|
||||
{{#subcategories}}
|
||||
<span class="subcategory">
|
||||
<a class="badge-wrapper bullet" href="{{url}}">
|
||||
<span class="badge-category-bg" style="background-color: #{{{color}}}"></span>
|
||||
<span class="badge-category clear-badge"><span class="category-name">{{{name}}}</span></span>
|
||||
</a>
|
||||
</span>
|
||||
{{/subcategories}}
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
{{/has_subcategories}}
|
||||
</article>
|
||||
<div class="clearfix"></div>
|
||||
</aside>
|
|
@ -188,6 +188,7 @@ module Oneboxer
|
|||
when "uploads" then local_upload_html(url)
|
||||
when "topics" then local_topic_html(url, route, opts)
|
||||
when "users" then local_user_html(url, route)
|
||||
when "list" then local_category_html(url, route)
|
||||
end
|
||||
|
||||
html = html.presence || "<a href='#{url}'>#{url}</a>"
|
||||
|
@ -293,6 +294,25 @@ module Oneboxer
|
|||
end
|
||||
end
|
||||
|
||||
def self.local_category_html(url, route)
|
||||
return unless route[:category_slug_path_with_id]
|
||||
category = Category.find_by_slug_path_with_id(route[:category_slug_path_with_id])
|
||||
|
||||
if Guardian.new.can_see_category?(category)
|
||||
args = {
|
||||
url: category.url,
|
||||
name: category.name,
|
||||
color: category.color,
|
||||
logo_url: category.uploaded_logo&.url,
|
||||
description: category.description,
|
||||
has_subcategories: category.subcategories.present?,
|
||||
subcategories: category.subcategories.collect { |sc| { name: sc.name, color: sc.color, url: sc.url } }
|
||||
}
|
||||
|
||||
Mustache.render(template("discourse_category_onebox"), args)
|
||||
end
|
||||
end
|
||||
|
||||
def self.blocked_domains
|
||||
SiteSetting.blocked_onebox_domains.split("|")
|
||||
end
|
||||
|
|
|
@ -188,5 +188,28 @@ describe OneboxController do
|
|||
get "/onebox.json", params: { url: url }
|
||||
expect(response.body).to include('blockquote')
|
||||
end
|
||||
|
||||
context 'local categories' do
|
||||
fab!(:category) { Fabricate(:category) }
|
||||
|
||||
it 'oneboxes a public category' do
|
||||
get "/onebox.json", params: { url: category.url }
|
||||
expect(response.body).to include('aside')
|
||||
end
|
||||
|
||||
it 'includes subcategories' do
|
||||
subcategory = Fabricate(:category, name: "child", parent_category_id: category.id)
|
||||
|
||||
get "/onebox.json", params: { url: subcategory.url }
|
||||
expect(response.body).not_to include('subcategories')
|
||||
end
|
||||
|
||||
it 'does not onebox restricted categories' do
|
||||
staff_category = Fabricate(:private_category, group: Group[:staff])
|
||||
|
||||
get "/onebox.json", params: { url: staff_category.url }
|
||||
expect(response.body).not_to include('aside')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user