entity

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LayoutSection = "section.html"
	LayoutList    = "list.html"
	LayoutIndex   = "index.html"

	InternalFolder = "_internal"

	DefaultFolder   = "_default"
	DefaultIndex    = "_default/index.html"
	DefaultList     = DefaultFolder + "/" + LayoutList
	DefaultPage     = "_default/single.html"
	DefaultSection  = DefaultFolder + "/" + LayoutSection
	DefaultTaxonomy = "_default/taxonomy.html"
	DefaultTerm     = "_default/term.html"
	DefaultBaseof   = "_default/baseof.html"

	TaxonomyTaxonomy = "taxonomy/taxonomy.html"
	TaxonomyList     = "taxonomy" + "/" + LayoutList

	TermTerm = "term/term.html"
	TermTag  = "taxonomy/tag.html"
	TermList = "taxonomy" + "/" + LayoutList

	Sitemap                = "sitemap.xml"
	DefaultSitemap         = DefaultFolder + "/" + "sitemap.xml"
	InternalDefaultSitemap = InternalFolder + "/" + DefaultFolder + "/" + "sitemap.xml"
)
View Source
const (
	Never       = "never"
	Always      = "always"
	ListLocally = "local"
	Link        = "link"
)
View Source
const (
	StandalonePage404Base     = "404"
	StandalonePageSitemapBase = "_sitemap"
)
View Source
const ArtificialLangTagPrefix = "art-x-"
View Source
const PageHomeBase = "/"

Variables

View Source
var (
	InternalSummaryDividerPre = []byte("\n\n" + internalSummaryDividerBase + "\n\n")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	CachePages1 *dynacache.Partition[string, contenthub.Pages]
	CachePages2 *dynacache.Partition[string, contenthub.Pages]

	// Cache for content sources.
	CacheContentSource *dynacache.Partition[string, *stale.Value[[]byte]]

	CachePageSource  *dynacache.Partition[string, contenthub.PageSource]
	CachePageSources *dynacache.Partition[string, []contenthub.PageSource]

	CacheContentRendered   *dynacache.Partition[string, *stale.Value[valueobject.ContentSummary]]
	CacheContentToRender   *dynacache.Partition[string, *stale.Value[[]byte]]
	CacheContentShortcodes *dynacache.Partition[string, *stale.Value[map[string]valueobject.ShortcodeRenderer]]
}

func (*Cache) GetOrCreateResource

func (c *Cache) GetOrCreateResource(key string, f func() (contenthub.PageSource, error)) (contenthub.PageSource, error)

func (*Cache) GetOrCreateResources

func (c *Cache) GetOrCreateResources(key string, f func() ([]contenthub.PageSource, error)) ([]contenthub.PageSource, error)

type Content

type Content struct {
	// contains filtered or unexported fields
}

func NewContent

func NewContent(source []byte) *Content

func (*Content) AddItems

func (c *Content) AddItems(item pageparser.Item)

func (*Content) AddReplacement

func (c *Content) AddReplacement(val []byte, source pageparser.Item)

func (*Content) AddShortcode

func (c *Content) AddShortcode(s *valueobject.Shortcode)

func (*Content) IsEmpty added in v0.1.1

func (c *Content) IsEmpty() bool

func (*Content) PureContent

func (c *Content) PureContent() string

func (*Content) RawContent

func (c *Content) RawContent() string

func (*Content) SetSummaryDivider

func (c *Content) SetSummaryDivider()

func (*Content) SetSummaryTruncated

func (c *Content) SetSummaryTruncated()

func (*Content) Truncated added in v0.1.1

func (c *Content) Truncated() bool

type ContentHub

type ContentHub struct {
	Fs contenthub.FsService

	// ExecTemplate handling.
	TemplateExecutor contenthub.Template

	*Cache
	*Translator

	*PageMap
	*PageFinder

	*Title

	Log loggers.Logger `json:"-"`
	// contains filtered or unexported fields
}

func (*ContentHub) CollectPages

func (ch *ContentHub) CollectPages(exec contenthub.Template) error

func (*ContentHub) GetPageSources

func (ch *ContentHub) GetPageSources(page contenthub.Page) ([]contenthub.PageSource, error)

func (*ContentHub) GlobalPages

func (ch *ContentHub) GlobalPages() contenthub.Pages

func (*ContentHub) GlobalRegularPages added in v0.0.5

func (ch *ContentHub) GlobalRegularPages() contenthub.Pages

func (*ContentHub) ProcessPages

func (ch *ContentHub) ProcessPages(exec contenthub.Template) error

func (*ContentHub) RenderString

func (ch *ContentHub) RenderString(ctx context.Context, args ...any) (goTmpl.HTML, error)

func (*ContentHub) WalkPages

func (ch *ContentHub) WalkPages(langIndex int, walker contenthub.WalkFunc) error

func (*ContentHub) WalkTaxonomies

func (ch *ContentHub) WalkTaxonomies(langIndex int, walker contenthub.WalkTaxonomyFunc) error

type ContentProvider

type ContentProvider struct {
	// contains filtered or unexported fields
}

func (*ContentProvider) Content

func (c *ContentProvider) Content() (any, error)

func (*ContentProvider) ContentSummary

func (c *ContentProvider) ContentSummary() (valueobject.ContentSummary, error)

func (*ContentProvider) Summary

func (c *ContentProvider) Summary() goTemplate.HTML

func (*ContentProvider) TableOfContents

func (c *ContentProvider) TableOfContents() goTemplate.HTML

type ContentSpec

type ContentSpec struct {
	Converters contenthub.ConverterRegistry
}

func (*ContentSpec) GetContentConvertProvider

func (c *ContentSpec) GetContentConvertProvider(name string) contenthub.ConverterProvider

func (*ContentSpec) ResolveMarkup

func (c *ContentSpec) ResolveMarkup(in string) string

type Layout

type Layout struct{}

type Meta

type Meta struct {
	List       string
	Parameters maps.Params
	Weight     int

	Date time.Time
}

func (*Meta) Description

func (m *Meta) Description() string
func (m *Meta) NoLink() bool

func (*Meta) PageDate added in v0.1.1

func (m *Meta) PageDate() time.Time

func (*Meta) PageWeight added in v0.0.5

func (m *Meta) PageWeight() int

func (*Meta) Params

func (m *Meta) Params() maps.Params

func (*Meta) ShouldList added in v0.0.13

func (m *Meta) ShouldList(global bool) bool

func (*Meta) ShouldListAny added in v0.0.13

func (m *Meta) ShouldListAny() bool

type Output

type Output struct {
	// contains filtered or unexported fields
}

func (*Output) Build

func (o *Output) Build(convertProvider *ContentSpec,
	templateSvc contenthub.Template, mediaSvc contenthub.MediaService) error

func (*Output) Outputs

func (o *Output) Outputs(p *Page) ([]contenthub.PageOutput, error)

type Page

type Page struct {
	*Source
	*Content
	*Meta

	*Layout
	*Output
	contenthub.PagerManager
	// contains filtered or unexported fields
}

func (*Page) AllTranslations

func (p *Page) AllTranslations() contenthub.Pages

AllTranslations returns all translations, including the current Page.

func (*Page) Eq

func (p *Page) Eq(other contenthub.Page) bool

func (*Page) IsAncestor

func (p *Page) IsAncestor(other contenthub.Page) bool

func (*Page) IsBundled

func (p *Page) IsBundled() bool

func (*Page) IsHome

func (p *Page) IsHome() bool

func (*Page) IsPage

func (p *Page) IsPage() bool

func (*Page) IsSection

func (p *Page) IsSection() bool

func (*Page) Kind

func (p *Page) Kind() string

func (*Page) Layouts

func (p *Page) Layouts() []string

func (*Page) PageOutputs

func (p *Page) PageOutputs() ([]contenthub.PageOutput, error)

func (*Page) Pages

func (p *Page) Pages(langIndex int) contenthub.Pages

func (*Page) Parent added in v0.1.1

func (p *Page) Parent() contenthub.Page

func (*Page) RegularPages added in v0.1.1

func (p *Page) RegularPages() contenthub.Pages

func (*Page) Terms added in v0.0.13

func (p *Page) Terms(langIndex int, taxonomy string) contenthub.Pages

func (*Page) Title

func (p *Page) Title() string

func (*Page) Translations

func (p *Page) Translations() contenthub.Pages

type PageBuilder

type PageBuilder struct {
	LangSvc     contenthub.LangService
	TaxonomySvc contenthub.TaxonomyService
	TemplateSvc contenthub.Template
	MediaSvc    contenthub.MediaService
	PageMapper  *PageMap

	Taxonomy   *Taxonomy
	Term       *Term
	Section    *Section
	Standalone *Standalone

	ConvertProvider *ContentSpec
	ContentHub      *ContentHub

	Log loggers.Logger
	// contains filtered or unexported fields
}

func (*PageBuilder) Build

func (b *PageBuilder) Build() (contenthub.Page, error)

func (*PageBuilder) BytesHandler

func (b *PageBuilder) BytesHandler() valueobject.ItemHandler

func (*PageBuilder) FrontMatterHandler

func (b *PageBuilder) FrontMatterHandler() valueobject.ItemHandler

func (*PageBuilder) KindBuild

func (b *PageBuilder) KindBuild() (contenthub.Page, error)

func (*PageBuilder) ShortcodeHandler

func (b *PageBuilder) ShortcodeHandler() valueobject.IterHandler

func (*PageBuilder) SummaryHandler

func (b *PageBuilder) SummaryHandler() valueobject.IterHandler

func (*PageBuilder) WithSource

func (b *PageBuilder) WithSource(source *Source) *PageBuilder

type PageFinder added in v0.1.1

type PageFinder struct {
	Fs contenthub.FsService

	PageMapper *PageMap
	// contains filtered or unexported fields
}

func (*PageFinder) GetPageFromPath added in v0.1.1

func (pf *PageFinder) GetPageFromPath(path string) (contenthub.Page, error)

func (*PageFinder) GetPageRef added in v0.1.1

func (pf *PageFinder) GetPageRef(context contenthub.Page, ref string, home contenthub.Page) (contenthub.Page, error)

type PageMap

type PageMap struct {
	// Main storage for all pages.
	*PageTrees

	Cache *Cache

	PageBuilder *PageBuilder

	Log loggers.Logger
	// contains filtered or unexported fields
}

func (*PageMap) AddFi

func (m *PageMap) AddFi(f *valueobject.File) error

func (*PageMap) Assemble

func (m *PageMap) Assemble() error

func (*PageMap) InsertResourceNode

func (m *PageMap) InsertResourceNode(key string, node *PageTreesNode)

func (*PageMap) SetupReverseIndex added in v0.1.1

func (m *PageMap) SetupReverseIndex()

type PageShifter added in v0.1.1

type PageShifter struct {
	*Shifter
}

func (*PageShifter) Shift added in v0.1.1

type PageTrees

type PageTrees struct {
	// This tree contains all Pages.
	// This include regular pages, sections, taxonomies and so on.
	// Note that all of these trees share the same key structure,
	// so you can take a leaf Page key and do a prefix search
	// with key + "/" to get all of its resources.
	TreePages *doctree.NodeShiftTree[*PageTreesNode]

	// This tree contains Resources bundled in pages.
	TreeResources *doctree.NodeShiftTree[*PageTreesNode]

	// All pages and resources.
	TreePagesResources doctree.WalkableTrees[*PageTreesNode]

	// This tree contains all taxonomy entries, e.g "/tags/blue/page1"
	TreeTaxonomyEntries *doctree.TreeShiftTree[*WeightedTermTreeNode]

	// A slice of the resource trees.
	ResourceTrees doctree.MutableTrees
}

PageTrees holds pages and resources in a tree structure for all sites/languages. Each site gets its own tree set via the Shape method.

func (*PageTrees) CreateMutableTrees

func (t *PageTrees) CreateMutableTrees()

type PageTreesNode

type PageTreesNode struct {
	// contains filtered or unexported fields
}

type Paginator added in v0.1.1

type Paginator struct {
	// contains filtered or unexported fields
}

func NewPaginator added in v0.1.1

func NewPaginator(svc PaginatorSvc, page contenthub.Page) *Paginator

func (*Paginator) Current added in v0.1.1

func (p *Paginator) Current() contenthub.Pager

func (*Paginator) Paginate added in v0.1.1

func (p *Paginator) Paginate(groups contenthub.PageGroups) (contenthub.Pager, error)

func (*Paginator) Paginator added in v0.1.1

func (p *Paginator) Paginator() (contenthub.Pager, error)

func (*Paginator) SetCurrent added in v0.1.1

func (p *Paginator) SetCurrent(current contenthub.Pager)

type PaginatorSvc added in v0.1.1

type PaginatorSvc interface {
	PageSize() int
	GlobalRegularPages() contenthub.Pages
}

type Section

type Section struct {
	FsSvc contenthub.FsService
	Cache *Cache
	// contains filtered or unexported fields
}

func (*Section) Assemble

func (s *Section) Assemble(pages *doctree.NodeShiftTree[*PageTreesNode], pb *PageBuilder) error

func (*Section) CreateHome

func (s *Section) CreateHome(pb *PageBuilder) error

type Shifter added in v0.1.1

type Shifter struct{}

func (*Shifter) Delete added in v0.1.1

func (s *Shifter) Delete(n *PageTreesNode, dimension doctree.Dimension) (bool, bool)

func (*Shifter) ForEachInDimension added in v0.1.1

func (s *Shifter) ForEachInDimension(n *PageTreesNode, d int, f func(*PageTreesNode) bool)

func (*Shifter) Insert added in v0.1.1

func (s *Shifter) Insert(old, new *PageTreesNode) *PageTreesNode

func (*Shifter) InsertInto added in v0.1.1

func (s *Shifter) InsertInto(old, new *PageTreesNode, dimension doctree.Dimension) *PageTreesNode

func (*Shifter) Shift added in v0.1.1

func (s *Shifter) Shift(n *PageTreesNode, dimension doctree.Dimension, exact bool) (*PageTreesNode, bool, doctree.DimensionFlag)

type ShortcodeWithPage

type ShortcodeWithPage struct {
	Params        any
	Inner         template.HTML
	Page          contenthub.Page
	Parent        *ShortcodeWithPage
	Name          string
	IsNamedParams bool

	// Zero-based ordinal in relation to its parent. If the parent is the page itself,
	// this ordinal will represent the position of this shortcode in the page content.
	Ordinal int
	// contains filtered or unexported fields
}

ShortcodeWithPage is the "." context in a shortcode template.

func (*ShortcodeWithPage) Get

func (scp *ShortcodeWithPage) Get(key any) any

Get is a convenience method to look up shortcode parameters by its key.

func (*ShortcodeWithPage) InnerDeindent

func (scp *ShortcodeWithPage) InnerDeindent() template.HTML

InnerDeindent returns the (potentially de-indented) inner content of the shortcode.

func (*ShortcodeWithPage) Position

func (scp *ShortcodeWithPage) Position() text.Position

Position returns this shortcode's detailed position. Note that this information may be expensive to calculate, so only use this in error situations.

func (*ShortcodeWithPage) Scratch

func (scp *ShortcodeWithPage) Scratch() *maps.Scratch

Scratch returns a scratch-pad scoped for this shortcode. This can be used as a temporary storage for variables, counters etc.

func (*ShortcodeWithPage) UnwrapPage added in v0.1.1

func (scp *ShortcodeWithPage) UnwrapPage() contenthub.Page

type Source

type Source struct {
	*valueobject.Identity
	*valueobject.File

	stale.Staler
	// contains filtered or unexported fields
}

func (*Source) PosOffset added in v0.1.1

func (p *Source) PosOffset(offset int) text.Position

type SourceShifter

type SourceShifter struct {
	*Shifter
}

func (*SourceShifter) Shift

type Standalone

type Standalone struct {
	FsSvc contenthub.FsService
	Cache *Cache
}

func (*Standalone) Assemble

func (s *Standalone) Assemble(pages *doctree.NodeShiftTree[*PageTreesNode], pb *PageBuilder) error

type Taxonomy

type Taxonomy struct {
	Views []contenthub.Taxonomy

	FsSvc contenthub.FsService
	Cache *Cache
}

func (*Taxonomy) Assemble

func (t *Taxonomy) Assemble(pages *doctree.NodeShiftTree[*PageTreesNode], pb *PageBuilder) error

func (*Taxonomy) IsTaxonomyPath added in v0.0.13

func (t *Taxonomy) IsTaxonomyPath(p string) bool

func (*Taxonomy) IsZero

func (t *Taxonomy) IsZero(v contenthub.Taxonomy) bool

func (*Taxonomy) PluralTreeKey

func (t *Taxonomy) PluralTreeKey(plural string) string

type TaxonomyPage

type TaxonomyPage struct {
	*Page
	// contains filtered or unexported fields
}

type Term

type Term struct {
	Terms map[string][]string

	FsSvc contenthub.FsService
	Cache *Cache
}

func (*Term) Assemble

type TermPage

type TermPage struct {
	*TaxonomyPage
	// contains filtered or unexported fields
}

type Title

type Title struct {
	Style TitleStyle
}

func (*Title) CreateTitle

func (t *Title) CreateTitle(raw string) string

type TitleStyle

type TitleStyle string
const (
	StyleNone TitleStyle = ""
	StyleAP              = "ap"
)

type TranslateFunc added in v0.1.1

type TranslateFunc func(ctx context.Context, translationID string, templateData any) string

type Translator added in v0.1.1

type Translator struct {
	ContentLanguage string
	TranslateFuncs  map[string]TranslateFunc

	Log loggers.Logger `json:"-"`
}

func (*Translator) SetupTranslateFuncs added in v0.1.1

func (t *Translator) SetupTranslateFuncs(bndl *i18n.Bundle)

func (*Translator) Translate added in v0.1.1

func (t *Translator) Translate(ctx context.Context, lang string, translationID string, templateData any) string

type WeightedTermTreeNode

type WeightedTermTreeNode struct {
	*PageTreesNode
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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