File tree Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Expand file tree Collapse file tree 3 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 24
24
}
25
25
}
26
26
}
27
+
28
+ .custom-header-icon-link img {
29
+ width : 100% ;
30
+ }
Original file line number Diff line number Diff line change 1
1
import { withPluginApi } from "discourse/lib/plugin-api" ;
2
2
import { iconNode } from "discourse-common/lib/icon-library" ;
3
3
import { dasherize } from "@ember/string" ;
4
+ import isValidUrl from "../lib/isValidUrl" ;
5
+ import { h } from "virtual-dom" ;
6
+
7
+ function buildIcon ( icon ) {
8
+ if ( isValidUrl ( icon ) ) {
9
+ return h (
10
+ "img" ,
11
+ {
12
+ attributes : {
13
+ src : icon ,
14
+ } ,
15
+ } ,
16
+ ""
17
+ ) ;
18
+ } else {
19
+ return iconNode ( icon . toLowerCase ( ) ) ;
20
+ }
21
+ }
4
22
5
23
export default {
6
24
name : "header-icon-links" ,
@@ -12,7 +30,7 @@ export default {
12
30
splitLinks . forEach ( ( link , index , links ) => {
13
31
const fragments = link . split ( "," ) . map ( ( fragment ) => fragment . trim ( ) ) ;
14
32
const title = fragments [ 0 ] ;
15
- const icon = iconNode ( fragments [ 1 ] . toLowerCase ( ) ) ;
33
+ const icon = buildIcon ( fragments [ 1 ] ) ;
16
34
const href = fragments [ 2 ] ;
17
35
const className = `header-icon-${ dasherize ( fragments [ 0 ] ) } ` ;
18
36
const viewClass = fragments [ 3 ] . toLowerCase ( ) ;
Original file line number Diff line number Diff line change
1
+ export default function isValidUrl ( string ) {
2
+ try {
3
+ URL ( string ) ;
4
+ } catch ( _ ) {
5
+ return false ;
6
+ }
7
+
8
+ return true ;
9
+ }
You can’t perform that action at this time.
0 commit comments