@@ -7,44 +7,44 @@ import { withPluginApi } from "discourse/lib/plugin-api";
77import { escapeExpression } from " discourse/lib/utilities" ;
88import isValidUrl from " ../lib/isValidUrl" ;
99
10- function buildIcon (iconNameOrImageUrl , title ) {
10+ const beforeIcon = [" chat" , " search" , " hamburger" , " user-menu" ];
11+
12+ function buildIconTemplate (iconNameOrImageUrl , title ) {
1113 if (isValidUrl (iconNameOrImageUrl)) {
1214 return <template >
1315 <img src ={{iconNameOrImageUrl }} aria-hidden =" true" />
1416 <span class =" sr-only" >{{title }} </span >
1517 </template >;
16- } else {
17- return <template >{{icon iconNameOrImageUrl label =title }} </template >;
1818 }
19+
20+ return <template >{{icon iconNameOrImageUrl label =title }} </template >;
1921}
2022
2123export default {
2224 name: " header-icon-links" ,
2325 initialize () {
2426 withPluginApi ((api ) => {
2527 try {
26- let links = settings .header_links ;
28+ const links = settings .header_links || [] ;
2729
2830 links .forEach ((link , index ) => {
29- const iconTemplate = buildIcon (link .icon , link .title );
31+ const iconTemplate = buildIconTemplate (link .icon , link .title );
3032 const className = ` header-icon-${ dasherize (link .title )} ` ;
3133 const target = link .target === " blank" ? " _blank" : " " ;
3234 const rel = link .target ? " noopener" : " " ;
3335 const isLastLink =
3436 index === links .length - 1 ? " last-custom-icon" : " " ;
3537
36- let style ;
37- if ( link . width && ! isNaN ( link . width )) {
38- style = htmlSafe (` width: ${ escapeExpression (link . width )} px` );
39- }
38+ const numericWidth = Number ( link . width ) ;
39+ const style = Number . isFinite (numericWidth)
40+ ? htmlSafe (` width: ${ escapeExpression (numericWidth )} px` )
41+ : undefined ;
4042
4143 const iconComponent = class extends Component {
4244 static shouldRender (args , context ) {
43- if (context .site .mobileView ) {
44- return link .view === " vmo" || link .view === " vdm" ;
45- } else {
46- return link .view === " vdo" || link .view === " vdm" ;
47- }
45+ return context .site .mobileView
46+ ? link .view === " vmo" || link .view === " vdm"
47+ : link .view === " vdo" || link .view === " vdm" ;
4848 }
4949
5050 <template >
@@ -70,8 +70,6 @@ export default {
7070 </template >
7171 };
7272
73- const beforeIcon = [" chat" , " search" , " hamburger" , " user-menu" ];
74-
7573 api .headerIcons .add (link .title , iconComponent, {
7674 before: beforeIcon,
7775 });
0 commit comments