Skip to content

Commit

Permalink
Setting to show category icon from discourse-category-icons theme com…
Browse files Browse the repository at this point in the history
…ponent (discourse#7)
  • Loading branch information
renato authored Nov 30, 2020
1 parent a835aa8 commit eeced5b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
12 changes: 12 additions & 0 deletions common/common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ div[class^="category-title-header"] {
.category-title {
display: inline;
}

.category-icon-widget {
display: inline;

.category-icon {
.d-icon {
height: 1.5em;
width: 1.5em;
margin-right: 0.75em;
}
}
}
}

.category-title-description {
Expand Down
12 changes: 10 additions & 2 deletions javascripts/discourse/widgets/category-header-widget.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import { h } from "virtual-dom";
import { iconNode } from "discourse-common/lib/icon-library";
import { createWidget } from "discourse/widgets/widget";

function buildCategory(category) {
function buildCategory(category, widget) {
const content = [];

if (category.read_restricted) {
content.push(iconNode("lock"));
}

if (settings.show_category_icon) {
try {
content.push(widget.attach("category-icon", { category }));
} catch {
// if widget attaching fails, ignore it as it's probably the missing component
}
}

content.push(h("h1.category-title", category.name));

if (settings.show_description) {
Expand Down Expand Up @@ -63,7 +71,7 @@ export default createWidget("category-header-widget", {
style: `background-color: #${category.color}; color: #${category.text_color};`,
},
},
h("div.category-title-contents", buildCategory(category))
h("div.category-title-contents", buildCategory(category, this))
);
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ show_below_site_header:
default: true
type: bool
description: "Display the banner in the below site header connector."

show_category_icon:
default: false
description: "Show category icon from Discourse Category Icons component"

0 comments on commit eeced5b

Please sign in to comment.