D3vugu-components/components/navigation/page-info.go
David Vogel df7d956874 Add navigation.PageInfo
- Highlight sidebar entries
- Add PageInfo wiring example
2023-05-12 22:07:04 +02:00

60 lines
1.4 KiB
Go

package navigation
import "github.com/vugu/vugu"
// PageInfo represents the path of a route.
// This is used by navigation components.
type PageInfo struct {
Path string // URL path.
Title string // Title that can be defined by the page component.
LongTitle string
ShortTitle string
MetaDescription string // Meta description tag that can be defined by the page component.
}
func NewPageInfo(path string, component vugu.Builder) PageInfo {
var title, longTitle, shortTitle string
if c, ok := component.(PageTitleGetter); ok {
title, longTitle, shortTitle = c.PageTitle()
}
var metaDescription string
if c, ok := component.(PageMetaGetter); ok {
metaDescription = c.PageMetaDescription()
}
return PageInfo{
Path: path,
Title: title,
LongTitle: longTitle,
ShortTitle: shortTitle,
MetaDescription: metaDescription,
}
}
type PageInfoRef struct {
*PageInfo
}
func (p *PageInfoRef) PageInfoSet(pageInfo *PageInfo) {
p.PageInfo = pageInfo
}
type PageInfoSetter interface {
PageInfoSet(*PageInfo)
}
var _ PageInfoSetter = &PageInfoRef{}
// Can be implemented by page components to define their page title.
type PageTitleGetter interface {
PageTitle() (title, longTitle, shortTitle string)
}
// Can be implemented by page components to define their meta description.
type PageMetaGetter interface {
PageMetaDescription() (metaDescription string)
}