60 lines
1.4 KiB
Go
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)
|
||
|
}
|