@@ -5,33 +5,39 @@ package xlog
55type Property interface {
66 // Icon returns the fontawesome icon class name or emoji
77 Icon () string
8- // Name returns the link text
8+ // Name returns the name of the property
99 Name () string
10+ // Value returns the value of the property
11+ Value () any
1012}
1113
12- var props = []func (Page ) []Property {defaultProps }
14+ var propsSources = []func (Page ) []Property {defaultProps }
1315
1416// RegisterProperty registers a function that returns a set of properties for
1517// the page
1618func RegisterProperty (a func (Page ) []Property ) {
17- props = append (props , a )
19+ propsSources = append (propsSources , a )
1820}
1921
2022// Properties return a list of properties for a page. It executes all functions
2123// registered with RegisterProperty and collect results in one slice. Can be
2224// passed to the view to render a page properties
23- func Properties (p Page ) []Property {
24- ps := []Property {}
25- for pr := range props {
26- ps = append (ps , props [pr ](p )... )
25+ func Properties (p Page ) map [string ]Property {
26+ ps := map [string ]Property {}
27+ for _ , source := range propsSources {
28+ for _ , pr := range source (p ) {
29+ ps [pr .Name ()] = pr
30+ }
2731 }
32+
2833 return ps
2934}
3035
3136type lastUpdateProp struct { page Page }
3237
3338func (a lastUpdateProp ) Icon () string { return "fa-solid fa-clock" }
34- func (a lastUpdateProp ) Name () string { return ago (a .page .ModTime ()) }
39+ func (a lastUpdateProp ) Name () string { return "Modified" }
40+ func (a lastUpdateProp ) Value () any { return ago (a .page .ModTime ()) }
3541
3642func defaultProps (p Page ) []Property {
3743 return []Property {
0 commit comments