Skip to content

Commit

Permalink
feat: add option to exlcude category
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Dec 1, 2023
1 parent 5d3ce98 commit 4947411
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
20 changes: 17 additions & 3 deletions javascripts/discourse/components/category-jumbotron.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,23 @@ export default class CategoryJumbotron extends Component {
return (
this.currentRoutesMatch &&
this.category &&
this.category.level <= settings.max_level &&
(!settings.hide_if_no_description ||
isPresent(this.category?.description))
this.validCategoryLevel &&
this.validCategoryName &&
this.validCategoryDescription
);
}

get validCategoryLevel() {
return this.category?.level <= settings.max_level;
}

get validCategoryName() {
return !settings.exceptions.includes(this.category?.name);
}

get validCategoryDescription() {
return (
settings.hide_if_no_description || isPresent(this.category?.description)
);
}

Expand Down
6 changes: 6 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ hide_if_no_description:
default: true
description: "Hide banners if category description is not set"

exceptions:
default: ""
type: list
list_type: simple
description: "Banner will not show for these category NAMES."

plugin_outlet:
default: "above-main-container"
type: "enum"
Expand Down
14 changes: 12 additions & 2 deletions spec/system/category_jumbotron_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@
expect(subcategory_jumbotron).to be_not_visible
end

it "should not display category banner for category when `hide_if_no_description` setting is true and category has no description" do
it "should not display category jumbotron for category when `hide_if_no_description` setting is true and category has no description" do
category.update!(description: "")
theme.update_setting(:hide_if_no_description, true)
theme.save!

visit(category.url)

expect(category_banner).to be_not_visible
expect(subcategory_jumbotron).to be_not_visible
end

it "should not display category jumbotron for categories that have been listed in `exceptions` setting" do
theme.update_setting(:exceptions, "#{category.name}|#{category_subcategory.name}")
theme.save!

visit(category.url)

expect(subcategory_jumbotron).to be_not_visible

visit(category_subcategory.url)
end
end

0 comments on commit 4947411

Please sign in to comment.