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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| {% import ( "fmt" "net/url" "strings"
"{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/util" "{{{ .Package }}}/views/components" ) %}
{% func URL(u any, content string, includeExternalIcon bool, ps *cutil.PageState) %}{% stripspace %} {% if u == nil %} <em>nil</em> {% else %} {% code var href string switch t := u.(type) { case string: href = t case url.URL: href = t.String() case *url.URL: href = t.String() default: href = fmt.Sprint(u) } if content == "" { content = href } showIcon := includeExternalIcon && strings.HasPrefix(href, "http") %} <a target="_blank" rel="noopener noreferrer" href="{%s href %}">{%s content %}{% if showIcon %}{%= components.SVGLinkPadded(`external`, ps) %}{% endif %}</a> {% endif %} {% endstripspace %}{% endfunc %}
{% func URLTable(title string, value *url.URL, indent int, ps *cutil.PageState) %}{% stripspace %} <tr> {%= components.Indent(true, indent + 1) %} <th class="shrink">{%s title %}</th> {%= components.Indent(true, indent + 1) %} <td>{%= URL(value, "", false, ps) %}</td> {%= components.Indent(true, indent) %} </tr> {% endstripspace %}{% endfunc %}
{% func CodeLink(path string, title string, ps *cutil.PageState) %}{% stripspace %} {%- code origPath := path if title == "" { title = path } if !strings.HasPrefix(path, "/") { path = "/" + path } u := util.AppSource + "/blob/main" + path -%} {%= URL(u, origPath, false, ps) %} {% endstripspace %}{% endfunc %}
|