File tree Expand file tree Collapse file tree 2 files changed +16
-0
lines changed
Jellyfin.Plugin.Webhook/Helpers Expand file tree Collapse file tree 2 files changed +16
-0
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Globalization ;
3+ using System . Web ;
34using HandlebarsDotNet ;
45
56namespace Jellyfin . Plugin . Webhook . Helpers ;
@@ -46,6 +47,18 @@ public static class HandlebarsFunctionHelpers
4647 }
4748 } ;
4849
50+ private static readonly HandlebarsHelper UrlEncodeHelper = ( writer , context , parameters ) =>
51+ {
52+ if ( parameters . Length != 1 )
53+ {
54+ throw new HandlebarsException ( "{{url_encode}} helper must have exactly one argument" ) ;
55+ }
56+
57+ var valueToEncode = GetStringValue ( parameters [ 0 ] ) ;
58+ var encodedValue = HttpUtility . UrlEncode ( valueToEncode ) ;
59+ writer . WriteSafeString ( encodedValue ) ;
60+ } ;
61+
4962 /// <summary>
5063 /// Register handlebars helpers.
5164 /// </summary>
@@ -57,6 +70,7 @@ public static void RegisterHelpers()
5770 {
5871 writer . WriteSafeString ( $ "<a href='{ parameters [ "url" ] } '>{ context [ "text" ] } </a>") ;
5972 } ) ;
73+ Handlebars . RegisterHelper ( "url_encode" , UrlEncodeHelper ) ;
6074 }
6175
6276 /// <summary>
Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ See [Templates](Jellyfin.Plugin.Webhook/Templates) for sample templates.
4747 - if the value of the parameter is not null or empty
4848- link_to
4949 - wrap the $url and $text in an ` <a> ` tag
50+ - url_encode
51+ - encode the given text to url-encoded format (useful for including text with spaces in urls)
5052
5153#### Variables:
5254
You can’t perform that action at this time.
0 commit comments