-
Notifications
You must be signed in to change notification settings - Fork 8.2k
/
hashtag-css-generator.js
42 lines (36 loc) · 1.38 KB
/
hashtag-css-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { getHashtagTypeClasses } from "discourse/lib/hashtag-autocomplete";
export default {
name: "hashtag-css-generator",
after: "category-color-css-generator",
/**
* This generates CSS classes for each hashtag type,
* which are used to color the hashtag icons in the composer,
* cooked posts, and the sidebar.
*
* Each type has its own corresponding class, which is registered
* with the hastag type via api.registerHashtagType. The default
* ones in core are CategoryHashtagType and TagHashtagType.
*/
initialize(container) {
this.site = container.lookup("service:site");
// If the site is login_required and the user is anon there will be no categories
// preloaded, so there will be no category color CSS variables generated by
// the category-color-css-generator initializer.
if (!this.site.categories) {
return;
}
let generatedCssClasses = [];
Object.values(getHashtagTypeClasses()).forEach((hashtagType) => {
hashtagType.preloadedData.forEach((model) => {
generatedCssClasses = generatedCssClasses.concat(
hashtagType.generateColorCssClasses(model)
);
});
});
const cssTag = document.createElement("style");
cssTag.type = "text/css";
cssTag.id = "hashtag-css-generator";
cssTag.innerHTML = generatedCssClasses.join("\n");
document.head.appendChild(cssTag);
},
};