Add category targeting (#4)

Add category targeting (#4)

Co-authored-by: Dan Ungureanu dan@ungureanu.me

diff --git a/javascripts/discourse/widgets/category-header-widget.js.es6 b/javascripts/discourse/widgets/category-header-widget.js.es6
index 9946494..376a1df 100644
--- a/javascripts/discourse/widgets/category-header-widget.js.es6
+++ b/javascripts/discourse/widgets/category-header-widget.js.es6
@@ -44,13 +44,31 @@ export default createWidget("category-header-widget", {
       route.params &&
       route.params.hasOwnProperty("category_slug_path_with_id")
     ) {
+      const categories = settings.categories
+        .split("|")
+        .reduce((categories, item) => {
+          item = item.split(":");
+          if (item[0]) {
+            categories[item[0]] = item[1] || "all";
+          }
+          return categories;
+        }, {});
+
       const category = Category.findBySlugPathWithID(
         route.params.category_slug_path_with_id
       );
+
       const isException = settings.exceptions
         .split("|")
         .filter(Boolean)
         .includes(category.name);
+      const isTarget =
+        Object.keys(categories).length === 0 ||
+        categories[category.name] === "all" ||
+        categories[category.name] === "no_sub" ||
+        (category.parentCategory &&
+          (categories[category.parentCategory.name] === "all" ||
+            categories[category.parentCategory.name] === "only_sub"));
       const hideMobile = !settings.show_mobile && this.site.mobileView;
       const isSubCategory =
         !settings.show_subcategory && category.parentCategory;
@@ -58,6 +76,7 @@ export default createWidget("category-header-widget", {
         settings.hide_if_no_description && !category.description_text;
 
       if (
+        isTarget &&
         !isException &&
         !hasNoCategoryDescription &&
         !isSubCategory &&
diff --git a/settings.yml b/settings.yml
index aefa943..8e6a3d0 100644
--- a/settings.yml
+++ b/settings.yml
@@ -20,6 +20,16 @@ exceptions:
   list_type: simple
   description: "Banner will not show for these categories NAMES. This is case sensitive."
 
+categories:
+  default: ""
+  type: list
+  description: |
+    Banner will only show for these categories. Format: name:target.
+    Accepted targets:
+      all - named category and subcategories (default);
+      no_sub - only the named category;
+      only_sub - only subcategories of the named category.
+
 show_above_site_header:
   default: false
   type: bool

GitHub sha: ff09b877

This commit appears in #4 which was approved by udan11. It was merged by udan11.