File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change 77 "slices"
88 "strings"
99 "time"
10+
11+ "github.com/yuin/goldmark/ast"
12+ gast "github.com/yuin/goldmark/ast"
1013)
1114
1215var helpers = template.FuncMap {
@@ -19,6 +22,7 @@ var helpers = template.FuncMap{
1922 "isFontAwesome" : IsFontAwesome ,
2023 "includeJS" : includeJS ,
2124 "scripts" : scripts ,
25+ "banner" : Banner ,
2226}
2327
2428var ErrHelperRegistered = errors .New ("Helper already registered" )
@@ -132,3 +136,27 @@ func scripts() template.HTML {
132136func IsFontAwesome (i string ) bool {
133137 return strings .HasPrefix (i , "fa" )
134138}
139+
140+ func Banner (p Page ) string {
141+ _ , a := p .AST ()
142+ if a == nil {
143+ return ""
144+ }
145+
146+ paragraph := a .FirstChild ()
147+ if paragraph == nil || paragraph .Kind () != gast .KindParagraph {
148+ return ""
149+ }
150+
151+ img := paragraph .FirstChild ()
152+ if img == nil || img .Kind () != gast .KindImage {
153+ return ""
154+ }
155+
156+ image , ok := img .(* ast.Image )
157+ if ! ok {
158+ return ""
159+ }
160+
161+ return string (image .Destination )
162+ }
Original file line number Diff line number Diff line change 11< aside class ="menu " dir ="auto ">
22 < div class ="menu-list " dir ="auto ">
33 {{- range . -}}
4- < a href ="/{{.Name}} " dir ="auto ">
4+
5+ < a href ="/{{.Name}} " dir ="auto " class ="is-clearfix ">
6+
7+ {{ with banner . }}
8+ < img src ="{{.}} " class ="mr-3 is-pulled-left " style ="display: block; border-radius: 0.5em; object-fit: cover; object-position: 0 50%; max-height: 3em; width: 6em; " />
9+ {{ end }}
10+
511 < span class ="is-block ">
612 {{ .Emoji }}
713 {{ $props := properties . }}
814 {{ with $props.title }} {{ .Value }} {{ else }} {{ .Name }} {{ end }}
915 </ span >
1016 < time class ="has-text-grey is-size-7 " dir ="auto "> {{ ago .ModTime }}</ time >
11- </ a >
17+ </ a >
18+
1219 {{- end -}}
1320 </ div >
1421</ aside >
You can’t perform that action at this time.
0 commit comments