pagewise

package module
v0.0.0-...-a450811 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 9 Imported by: 0

README

PageWise

Installation

go get -u github.com/gowool/pagewise

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	SelfNodeTarget  NodeTarget = "_self"
	BlankNodeTarget NodeTarget = "_blank"

	PageType   NodeType = "page"
	CustomType NodeType = "custom"
)

Variables

This section is empty.

Functions

func Slug

func Slug(s string) string

Types

type Cache

type Cache interface {
	Set(ctx context.Context, key string, value interface{}, tags ...string) error
	Get(ctx context.Context, key string, value interface{}) error
	DelByKey(ctx context.Context, key string) error
	DelByTag(ctx context.Context, tag string) error
}

type CacheMenuNodeRepository

type CacheMenuNodeRepository struct {
	MenuNodeRepository
	Cache Cache
}

func (CacheMenuNodeRepository) DeleteByID

func (r CacheMenuNodeRepository) DeleteByID(ctx context.Context, id uuid.UUID) error

func (CacheMenuNodeRepository) FindByID

func (r CacheMenuNodeRepository) FindByID(ctx context.Context, id uuid.UUID) (node *MenuNode, err error)

func (CacheMenuNodeRepository) FindByMenuIDAndDate

func (r CacheMenuNodeRepository) FindByMenuIDAndDate(ctx context.Context, menuID uuid.UUID, date time.Time) (nodes []*MenuNode, err error)

func (CacheMenuNodeRepository) Save

func (r CacheMenuNodeRepository) Save(ctx context.Context, menuNode *MenuNode) error

type CacheMenuRepository

type CacheMenuRepository struct {
	MenuRepository
	Cache Cache
}

func (CacheMenuRepository) DeleteByID

func (r CacheMenuRepository) DeleteByID(ctx context.Context, id uuid.UUID) error

func (CacheMenuRepository) FindByID

func (r CacheMenuRepository) FindByID(ctx context.Context, id uuid.UUID) (menu *Menu, err error)

func (CacheMenuRepository) FindByIdentifierAndDate

func (r CacheMenuRepository) FindByIdentifierAndDate(ctx context.Context, identifier string, date time.Time) (menu *Menu, err error)

func (CacheMenuRepository) Save

func (r CacheMenuRepository) Save(ctx context.Context, menu *Menu) error

type CachePageRepository

type CachePageRepository struct {
	PageRepository
	Cache Cache
}

func (CachePageRepository) DeleteByID

func (r CachePageRepository) DeleteByID(ctx context.Context, id uuid.UUID) error

func (CachePageRepository) FindByID

func (r CachePageRepository) FindByID(ctx context.Context, id uuid.UUID) (page *Page, err error)

func (CachePageRepository) FindByParentIDAndDate

func (r CachePageRepository) FindByParentIDAndDate(ctx context.Context, parentID uuid.UUID, date time.Time) (pages []*Page, err error)

func (CachePageRepository) FindByPathAndDate

func (r CachePageRepository) FindByPathAndDate(ctx context.Context, path string, date time.Time) (page *Page, err error)

func (CachePageRepository) Save

func (r CachePageRepository) Save(ctx context.Context, page *Page) error
type Menu struct {
	ID         uuid.UUID              `cfg:"id,omitempty" json:"id,omitempty" yaml:"id,omitempty" bson:"id,omitempty"`
	Identifier string                 `cfg:"identifier,omitempty" json:"identifier,omitempty" yaml:"identifier,omitempty" bson:"identifier,omitempty"`
	Created    time.Time              `cfg:"created,omitempty" json:"created,omitempty" yaml:"created,omitempty" bson:"created,omitempty"`
	Updated    time.Time              `cfg:"updated,omitempty" json:"updated,omitempty" yaml:"updated,omitempty" bson:"updated,omitempty"`
	Published  *time.Time             `cfg:"published,omitempty" json:"published,omitempty" yaml:"published,omitempty" bson:"published,omitempty"`
	Expired    *time.Time             `cfg:"expired,omitempty" json:"expired,omitempty" yaml:"expired,omitempty" bson:"expired,omitempty"`
	Nodes      []*MenuNode            `cfg:"nodes,omitempty" json:"nodes,omitempty" yaml:"nodes,omitempty" bson:"nodes,omitempty"`
	Metadata   map[string]interface{} `cfg:"metadata,omitempty" json:"metadata,omitempty" yaml:"metadata,omitempty" bson:"metadata,omitempty"`
}

func ToTree

func ToTree(menu *Menu) *Menu
func (m *Menu) Enabled(now time.Time) bool
func (m *Menu) String() string
type MenuNode struct {
	ID uuid.UUID `cfg:"id,omitempty" json:"id,omitempty" yaml:"id,omitempty" bson:"id,omitempty"`

	ParentID *uuid.UUID  `cfg:"parent_id,omitempty" json:"parent_id,omitempty" yaml:"parent_id,omitempty" bson:"parent_id,omitempty"`
	Parent   *MenuNode   `cfg:"parent,omitempty" json:"parent,omitempty" yaml:"parent,omitempty" bson:"-"`
	Children []*MenuNode `cfg:"children,omitempty" json:"children,omitempty" yaml:"children,omitempty" bson:"-"`

	MenuID uuid.UUID `cfg:"menu_id,omitempty" json:"menu_id,omitempty" yaml:"menu_id,omitempty" bson:"menu_id,omitempty"`
	Menu   *Menu     `cfg:"menu,omitempty" json:"menu,omitempty" yaml:"menu,omitempty" bson:"-"`

	PageID *uuid.UUID `cfg:"page_id,omitempty" json:"page_id,omitempty" yaml:"page_id,omitempty" bson:"page_id,omitempty"`

	Title    string                 `cfg:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty" bson:"title,omitempty"`
	URL      string                 `cfg:"url,omitempty" json:"url,omitempty" yaml:"url,omitempty" bson:"url,omitempty"`
	Target   NodeTarget             `cfg:"target,omitempty" json:"target,omitempty" yaml:"target,omitempty" bson:"target,omitempty"`
	NodeType NodeType               `cfg:"node_type,omitempty" json:"node_type,omitempty" yaml:"node_type,omitempty" bson:"node_type,omitempty"`
	Position int                    `cfg:"position" json:"position,omitempty" yaml:"position,omitempty" bson:"position,omitempty"`
	Metadata map[string]interface{} `cfg:"metadata,omitempty" json:"metadata,omitempty" yaml:"metadata,omitempty" bson:"metadata,omitempty"`

	Created time.Time `cfg:"created,omitempty" json:"created,omitempty" yaml:"created,omitempty" bson:"created,omitempty"`
	Updated time.Time `cfg:"updated,omitempty" json:"updated,omitempty" yaml:"updated,omitempty" bson:"updated,omitempty"`

	Published *time.Time `cfg:"published,omitempty" json:"published,omitempty" yaml:"published,omitempty" bson:"published,omitempty"`
	Expired   *time.Time `cfg:"expired,omitempty" json:"expired,omitempty" yaml:"expired,omitempty" bson:"expired,omitempty"`
}

func FirstActiveMenuNode

func FirstActiveMenuNode(nodes []*MenuNode, urlPath string) *MenuNode

func LastActiveMenuNode

func LastActiveMenuNode(nodes []*MenuNode, urlPath string) *MenuNode
func (n *MenuNode) ActiveChild(urlPath string) *MenuNode
func (n *MenuNode) Enabled(now time.Time) bool
func (n *MenuNode) IsActive(urlPath string) bool
func (n *MenuNode) String() string
type MenuNodeRepository interface {
	Find(ctx context.Context, criteria *cr.Criteria) ([]*MenuNode, int, error)
	FindByID(ctx context.Context, id uuid.UUID) (*MenuNode, error)
	FindByMenuIDAndDate(ctx context.Context, menuID uuid.UUID, date time.Time) ([]*MenuNode, error)
	DeleteByID(ctx context.Context, id uuid.UUID) error
	Save(ctx context.Context, menuNode *MenuNode) error
}
type MenuRepository interface {
	Find(ctx context.Context, criteria *cr.Criteria) ([]*Menu, int, error)
	FindByID(ctx context.Context, id uuid.UUID) (*Menu, error)
	FindByIdentifierAndDate(ctx context.Context, identifier string, date time.Time) (*Menu, error)
	DeleteByID(ctx context.Context, id uuid.UUID) error
	Save(ctx context.Context, menu *Menu) error
}

type Meta

type Meta struct {
	Type    MetaType `cfg:"type" json:"type,omitempty" yaml:"type,omitempty" bson:"type,omitempty"`
	Key     string   `cfg:"key" json:"key,omitempty" yaml:"key,omitempty" bson:"key,omitempty"`
	Content string   `cfg:"content" json:"content,omitempty" yaml:"content,omitempty" bson:"content,omitempty"`
}

func (Meta) Equals

func (m Meta) Equals(another Meta) bool

type MetaType

type MetaType string
const (
	MetaName     MetaType = "name"
	MetaEquiv    MetaType = "http-equiv"
	MetaProperty MetaType = "property"
)

func (MetaType) String

func (t MetaType) String() string

type NodeTarget

type NodeTarget string

type NodeType

type NodeType string

type Page

type Page struct {
	ID        uuid.UUID              `cfg:"id,omitempty" json:"id,omitempty" yaml:"id,omitempty" bson:"id,omitempty"`
	Path      string                 `cfg:"path,omitempty" json:"path,omitempty" yaml:"path,omitempty" bson:"path,omitempty"`
	Title     string                 `cfg:"title,omitempty" json:"title,omitempty" yaml:"title,omitempty" bson:"title,omitempty"`
	Template  string                 `cfg:"template,omitempty" json:"template,omitempty" yaml:"template,omitempty" bson:"template,omitempty"`
	NoSitemap bool                   `cfg:"no_sitemap,omitempty" json:"no_sitemap,omitempty" yaml:"no_sitemap,omitempty" bson:"no_sitemap,omitempty"`
	Created   time.Time              `cfg:"created,omitempty" json:"created,omitempty" yaml:"created,omitempty" bson:"created,omitempty"`
	Updated   time.Time              `cfg:"updated,omitempty" json:"updated,omitempty" yaml:"updated,omitempty" bson:"updated,omitempty"`
	Published *time.Time             `cfg:"published,omitempty" json:"published,omitempty" yaml:"published,omitempty" bson:"published,omitempty"`
	Expired   *time.Time             `cfg:"expired,omitempty" json:"expired,omitempty" yaml:"expired,omitempty" bson:"expired,omitempty"`
	Metas     []Meta                 `cfg:"metas,omitempty" json:"metas,omitempty" yaml:"metas,omitempty" bson:"metas,omitempty"`
	Metadata  map[string]interface{} `cfg:"metadata,omitempty" json:"metadata,omitempty" yaml:"metadata,omitempty" bson:"metadata,omitempty"`
	ParentID  *uuid.UUID             `cfg:"parent_id,omitempty" json:"parent_id,omitempty" yaml:"parent_id,omitempty" bson:"parent_id,omitempty"`
	Parent    *Page                  `cfg:"parent,omitempty" json:"parent,omitempty" yaml:"parent,omitempty" bson:"-"`
	Children  []*Page                `cfg:"children,omitempty" json:"children,omitempty" yaml:"children,omitempty" bson:"-"`
}

func (*Page) Enabled

func (p *Page) Enabled(now time.Time) bool

func (*Page) SetPath

func (p *Page) SetPath()

func (*Page) String

func (p *Page) String() string

type PageRepository

type PageRepository interface {
	Find(ctx context.Context, criteria *cr.Criteria) ([]*Page, int, error)
	FindByID(ctx context.Context, id uuid.UUID) (*Page, error)
	FindByPathAndDate(ctx context.Context, path string, date time.Time) (*Page, error)
	FindByParentIDAndDate(ctx context.Context, parentID uuid.UUID, date time.Time) ([]*Page, error)
	DeleteByID(ctx context.Context, id uuid.UUID) error
	Save(ctx context.Context, page *Page) error
}

type Service

type Service interface {
	GetPage(ctx context.Context, path string, date time.Time) (*Page, error)
	GetPages(ctx context.Context, parentID uuid.UUID, date time.Time) ([]*Page, error)
	GetMenu(ctx context.Context, identifier string, date time.Time) (*Menu, error)
}

func NewService

func NewService(page PageRepository, menu MenuRepository, menuNode MenuNodeRepository) Service

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL