valueobject

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KindPage = "page"

	KindHome    = "home"
	KindSection = "section"

	// Note that before Hugo 0.73 these were confusingly named
	// taxonomy (now: term)
	// taxonomyTerm (now: taxonomy)
	KindTaxonomy = "taxonomy"
	KindTerm     = "term"

	// The following are (currently) temporary nodes,
	// i.e. nodes we create just to render in isolation.
	KindRSS          = "rss"
	KindSitemap      = "sitemap"
	KindSitemapIndex = "sitemapindex"
	KindRobotsTXT    = "robotstxt"
	KindStatus404    = "404"
)
View Source
const ShortcodePlaceholderPrefix = "HAHAHUGOSHORTCODE"

Variables

View Source
var (
	// This is all the kinds we can expect to find in .Site.Pages.
	AllKindsInPages []string
	// This is all the kinds, including the temporary ones.
	AllKinds []string
)
View Source
var DefaultTocConfig = TocConfig{
	StartLevel: 2,
	EndLevel:   3,
	Ordered:    false,
}

DefaultTocConfig is the default ToC configuration.

View Source
var MDProvider contenthub.ProviderProvider = provide{}

MDProvider is the package entry point.

View Source
var (
	NilPage *nopPage
)
View Source
var TocShortcodePlaceholder = CreateShortcodePlaceholder("TOC", 0, 0)
View Source
var ZeroShortcode = prerenderedShortcode{}

Functions

func AddFileInfoToError

func AddFileInfoToError(err error, fi fs.FileMetaInfo, fs afero.Fs) error

AddFileInfoToError adds file info to the given error.

func CheckCascadePattern

func CheckCascadePattern(m PageMatcher)

func CreateShortcodePlaceholder

func CreateShortcodePlaceholder(sid string, id uint64, ordinal int) string

func DecodeCascadeConfig

func DecodeCascadeConfig(in any) (map[PageMatcher]maps.Params, error)

func GetKindAny

func GetKindAny(s string) string

GetKindAny gets the page kind given a string, empty if not found.

func GetKindMain

func GetKindMain(s string) string

GetKindMain gets the page kind given a string, empty if not found. Note that this will not return any temporary kinds (e.g. robotstxt).

func GetParam

func GetParam(p maps.Params, key string, stringToLower bool) any

func GetParamToLower

func GetParamToLower(m maps.Params, key string) any

func IsBranch

func IsBranch(kind string) bool

IsBranch returns whether the given kind is a branch node.

func IsDeprecatedAndReplacedWith

func IsDeprecatedAndReplacedWith(s string) string

IsDeprecatedAndReplacedWith returns the new kind if the given kind is deprecated.

func MustUnwrapPage

func MustUnwrapPage(in any) contenthub.Page

func NewPageInfo

func NewPageInfo(name, kind, dir string, sections []string, buf *bytes.Buffer) contenthub.PageInfo

func NewZeroFile

func NewZeroFile() contenthub.File

func PosFromInput

func PosFromInput(filename string, input []byte, offset int) text.Position

func PutPagePathBuilder

func PutPagePathBuilder(b *PagePathBuilder)

func SortByDefault

func SortByDefault(pages contenthub.Pages)

SortByDefault sorts pages by the default sort.

func SortByLanguage

func SortByLanguage(pages contenthub.Pages)

func SortByWeight added in v0.0.5

func SortByWeight(pages contenthub.Pages)

SortByWeight sorts pages by weight.

func UniqueStringsReuse

func UniqueStringsReuse(s []string) []string

UniqueStringsReuse returns a slice with any duplicates removed. It will modify the input slice.

Types

type BundleType

type BundleType int
const (
	// BundleTypeFile A generic resource, e.g. a JSON file.
	BundleTypeFile BundleType = iota

	// BundleTypeContentResource All below are content files.
	// A resource of a content type with front matter.
	// A single file but not leaf
	BundleTypeContentResource

	// BundleTypeContentSingle E.g. /blog/my-post.md
	BundleTypeContentSingle

	// BundleTypeLeaf Leaf bundles, e.g. /blog/my-post/index.md
	BundleTypeLeaf

	// BundleTypeBranch Branch bundles, e.g. /blog/_index.md
	BundleTypeBranch
)

func (BundleType) IsBranchBundle

func (b BundleType) IsBranchBundle() bool

func (BundleType) IsBundle

func (b BundleType) IsBundle() bool

func (BundleType) IsContent

func (b BundleType) IsContent() bool

IsContent returns true if the path is a content file (e.g. mypost.md). Note that this will also return true for content files in a bundle.

func (BundleType) IsContentResource

func (b BundleType) IsContentResource() bool

func (BundleType) IsLeafBundle

func (b BundleType) IsLeafBundle() bool

type Cascade

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

func NewCascade

func NewCascade(cas any) (*Cascade, error)

type ContentSummary

type ContentSummary struct {
	Content             template.HTML
	Summary             template.HTML
	SummaryTruncated    bool
	TableOfContentsHTML template.HTML
}

func NewEmptyContentSummary

func NewEmptyContentSummary() ContentSummary

type ConverterProvider

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

func (ConverterProvider) Name

func (n ConverterProvider) Name() string

func (ConverterProvider) New

type ConverterRegistry

type ConverterRegistry struct {
	// Maps name (md, markdown, goldmark etc.) to a converter provider.
	// Note that this is also used for aliasing, so the same converter
	// may be registered multiple times.
	// All names are lower case.
	Converters map[string]contenthub.ConverterProvider
}

func (*ConverterRegistry) Get

type File

type File struct {
	fs.FileMetaInfo

	BundleType
	// contains filtered or unexported fields
}

File describes a source file.

func NewFileInfo

func NewFileInfo(fi fs.FileMetaInfo) *File

func (*File) BaseFileName

func (fi *File) BaseFileName() string

BaseFileName returns a file's name without extension (e.g. "page.sv").

func (*File) ContentBaseName

func (fi *File) ContentBaseName() string

ContentBaseName is a either TranslationBaseName or name of containing folder if file is a bundle.

func (*File) Dir

func (fi *File) Dir() string

Dir gets the name of the directory that contains this file. The directory is relative to the content root.

func (*File) Ext

func (fi *File) Ext() string

Ext returns a file's extension without the leading period (e.g. "md").

func (*File) FileInfo

func (fi *File) FileInfo() fs.FileMetaInfo

FileInfo returns a file's underlying os.FileInfo.

func (*File) Filename

func (fi *File) Filename() string

Filename returns a file's absolute path and filename on disk.

func (*File) IsZero

func (fi *File) IsZero() bool

func (*File) LogicalName

func (fi *File) LogicalName() string

LogicalName returns a file's name and extension (e.g. "page.sv.md").

func (*File) Open

func (fi *File) Open() (io.ReadSeekCloser, error)

Open implements ReadableFile.

func (*File) Opener

func (fi *File) Opener() io.OpenReadSeekCloser

func (*File) PageFile

func (fi *File) PageFile() contenthub.File

func (*File) Path

func (fi *File) Path() string

func (*File) Paths

func (fi *File) Paths() *paths.Path

func (*File) RelPath

func (fi *File) RelPath() string

RelPath Paths gets the relative path including file name and extension. The directory is relative to the content root.

func (*File) Section

func (fi *File) Section() string

Section returns a file's section.

func (*File) ShiftToResource

func (fi *File) ShiftToResource()

func (*File) String

func (fi *File) String() string

func (*File) TranslationBaseName

func (fi *File) TranslationBaseName() string

TranslationBaseName returns a file's translation base name without the language segment (e.g. "page").

func (*File) UniqueID

func (fi *File) UniqueID() string

UniqueID returns a file's unique, MD5 hash identifier.

type FileManager

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

func NewFsManager

func NewFsManager(fis []fs.FileMetaInfo) *FileManager

func (*FileManager) GetLeaf

func (f *FileManager) GetLeaf() *File

type FrontMatter

type FrontMatter struct {
	*Cascade

	Path   string
	Lang   string
	Kind   string
	Title  string
	Weight int

	Terms map[string][]string

	Params maps.Params
}

type FrontMatterParser

type FrontMatterParser struct {
	Params      maps.Params
	LangSvc     contenthub.LangService
	TaxonomySvc contenthub.TaxonomyService
}

func (*FrontMatterParser) Parse

func (b *FrontMatterParser) Parse() (*FrontMatter, error)

type Identity

type Identity struct {
	Id uint64

	Lang    string
	LangIdx int
}

func (Identity) ID

func (i Identity) ID() int

func (Identity) IdentifierBase

func (i Identity) IdentifierBase() string

func (Identity) PageIdentity

func (i Identity) PageIdentity() contenthub.PageIdentity

func (Identity) PageLanguage

func (i Identity) PageLanguage() string

func (Identity) PageLanguageIndex

func (i Identity) PageLanguageIndex() int

type ItemHandler

type ItemHandler func(item pageparser.Item) error

type IterHandler

type IterHandler func(item pageparser.Item, iter *pageparser.Iterator) error

type LayoutDescriptor

type LayoutDescriptor struct {
	Type    string
	Section string

	// E.g. "page", but also used for the _markup render kinds, e.g. "render-images".
	Kind string

	// Comma-separated list of kind variants, e.g. "go,json" as variants which would find "render-codeblock-go.html"
	KindVariants string

	Lang   string
	Layout string
	// LayoutOverride indicates what we should only look for the above layout.
	LayoutOverride bool

	RenderingHook bool
	Baseof        bool

	FormatName string
	Extension  string
}

LayoutDescriptor describes how a layout should be chosen. This is typically built from a Page.

type LayoutHandler

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

LayoutHandler calculates the layout template to use to render a given output type.

func NewLayoutHandler

func NewLayoutHandler() *LayoutHandler

NewLayoutHandler creates a new LayoutHandler.

func (*LayoutHandler) For

func (l *LayoutHandler) For(d LayoutDescriptor) ([]string, error)

For returns a layout for the given LayoutDescriptor and options. Layouts are rendered and cached internally.

type LayoutLooker

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

func NewLayoutLooker

func NewLayoutLooker(names []string, bnames []string) *LayoutLooker

func (*LayoutLooker) BaseNames

func (l *LayoutLooker) BaseNames() []string

func (*LayoutLooker) Names

func (l *LayoutLooker) Names() []string

type PageContentReplacement

type PageContentReplacement struct {
	Val []byte

	Source pageparser.Item
}

type PageMatcher

type PageMatcher struct {
	// A Glob pattern matching the content path below /content.
	// Expects Unix-styled slashes.
	// Note that this is the virtual path, so it starts at the mount root
	// with a leading "/".
	Path string

	// A Glob pattern matching the Page's Kind(s), e.g. "{home,section}"
	Kind string

	// A Glob pattern matching the Page's language, e.g. "{en,sv}".
	Lang string

	// A Glob pattern matching the Page's Environment, e.g. "{production,development}".
	Environment string
}

A PageMatcher can be used to match a Page with Glob patterns. Note that the pattern matching is case insensitive.

func (PageMatcher) Matches

func (m PageMatcher) Matches(p contenthub.Page) bool

Matches returns whether p matches this matcher.

type PageMatcherParamsConfig

type PageMatcherParamsConfig struct {
	// Apply Params to all Pages matching Target.
	Params maps.Params
	Target PageMatcher
}

type PagePathBuilder

type PagePathBuilder struct {

	// Builder state.
	IsUgly             bool
	BaseNameSameAsType bool // Remove it, only sitemap has same basename from both output format and descriptor
	NoSubResources     bool
	FullSuffix         string // File suffix including any ".".

	PrefixPath      string
	LinkUpperOffset int
	// contains filtered or unexported fields
}

PagePathBuilder When adding state here, remember to update putPagePathBuilder.

func GetPagePathBuilder

func GetPagePathBuilder(format output.Format) *PagePathBuilder

func (*PagePathBuilder) Add

func (p *PagePathBuilder) Add(el ...string)

func (*PagePathBuilder) ConcatLast

func (p *PagePathBuilder) ConcatLast(s string)

func (*PagePathBuilder) IsHtmlIndex

func (p *PagePathBuilder) IsHtmlIndex() bool

func (*PagePathBuilder) Last

func (p *PagePathBuilder) Last() string
func (p *PagePathBuilder) Link() string

func (*PagePathBuilder) LinkDir

func (p *PagePathBuilder) LinkDir() string

func (*PagePathBuilder) Path

func (p *PagePathBuilder) Path(upperOffset int) string

func (*PagePathBuilder) PathDir

func (p *PagePathBuilder) PathDir() string

func (*PagePathBuilder) PathDirBase

func (p *PagePathBuilder) PathDirBase() string

func (*PagePathBuilder) PathFile

func (p *PagePathBuilder) PathFile() string

func (*PagePathBuilder) Prepend

func (p *PagePathBuilder) Prepend(el ...string)

func (*PagePathBuilder) Sanitize

func (p *PagePathBuilder) Sanitize()

type PageWrapper

type PageWrapper interface {
	// contains filtered or unexported methods
}

type Shortcode

type Shortcode struct {
	Name string

	Ordinal int

	Indentation string // indentation from source.

	Inner    []any // string or nested shortcode
	IsInline bool  // inline shortcode. Any inner will be a Go template.

	// If set, the rendered shortcode is sent as part of the surrounding content
	// to Goldmark and similar.
	// Before Hug0 0.55 we didn't send any shortcode output to the markup
	// renderer, and this flag told Hugo to process the {{ .Inner }} content
	// separately.
	// The old behavior can be had by starting your shortcode template with:
	//    {{ $_hugo_config := `{ "version": 1 }`}}
	DoMarkup bool

	IsClosing bool // whether a closing tag was provided

	Info   template.Info       // One of the output formats (arbitrary)
	Templs []template.Preparer // All output formats

	Params any // map or array

	Pos    int // the position in bytes in the source file
	Length int // the length in bytes in the source file

	// the placeholder in the source when passed to Goldmark etc.
	// This also identifies the rendered shortcode.
	Placeholder string
}

func (Shortcode) InsertPlaceholder

func (s Shortcode) InsertPlaceholder() bool

func (Shortcode) NeedsInner

func (s Shortcode) NeedsInner() bool

type ShortcodeParser

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

func NewShortcodeParser

func NewShortcodeParser(source []byte, pid uint64, tmplSvc contenthub.Template) *ShortcodeParser

func (*ShortcodeParser) ParseItem

func (s *ShortcodeParser) ParseItem(it pageparser.Item, pt *pageparser.Iterator) (*Shortcode, error)

type ShortcodeRenderFunc

type ShortcodeRenderFunc func(context.Context) ([]byte, bool, error)

func (ShortcodeRenderFunc) RenderShortcode

func (f ShortcodeRenderFunc) RenderShortcode(ctx context.Context) ([]byte, bool, error)

func (ShortcodeRenderFunc) RenderShortcodeString

func (f ShortcodeRenderFunc) RenderShortcodeString(ctx context.Context) (string, bool, error)

type ShortcodeRenderer

type ShortcodeRenderer interface {
	RenderShortcode(context.Context) ([]byte, bool, error)
	RenderShortcodeString(context.Context) (string, bool, error)
}

ShortcodeRenderer is typically used to delay rendering of inner shortcodes marked with placeholders in the content.

func NewPrerenderedShortcode

func NewPrerenderedShortcode(s string, hasVariants bool) ShortcodeRenderer

type SourceHandlers

type SourceHandlers interface {
	FrontMatterHandler() ItemHandler
	SummaryHandler() IterHandler
	BytesHandler() ItemHandler
	ShortcodeHandler() IterHandler
}

type SourceParseInfo

type SourceParseInfo struct {
	Source []byte

	// Items from the page parser.
	// These maps directly to the source
	ItemsStep1 pageparser.Items

	Handlers SourceHandlers
	// contains filtered or unexported fields
}

func NewSourceParseInfo

func NewSourceParseInfo(source []byte, handlers SourceHandlers) (*SourceParseInfo, error)

func (*SourceParseInfo) Handle

func (s *SourceParseInfo) Handle() error

func (*SourceParseInfo) IsEmpty

func (s *SourceParseInfo) IsEmpty() bool

func (*SourceParseInfo) Parse

func (s *SourceParseInfo) Parse() error

type Target

type Target struct {
	Prefix string

	// Where to store the file on disk relative to the publish dir. OS slashes.
	FilePath string
	// The directory to write sub-resources of the above.
	SubResourceBaseTarget string

	Format output.Format
}

func (*Target) TargetFilePath

func (t *Target) TargetFilePath() string

func (*Target) TargetFormat

func (t *Target) TargetFormat() output.Format

func (*Target) TargetPrefix

func (t *Target) TargetPrefix() string

func (*Target) TargetSubResourceDir

func (t *Target) TargetSubResourceDir() string

type TocConfig

type TocConfig struct {
	// Heading start level to include in the table of contents, starting
	// at h1 (inclusive).
	// <docsmeta>{ "identifiers": ["h1"] }</docsmeta>
	StartLevel int

	// Heading end level, inclusive, to include in the table of contents.
	// Default is 3, a value of -1 will include everything.
	EndLevel int

	// Whether to produce a ordered list or not.
	Ordered bool
}

type WhatChanged

type WhatChanged struct {
	IdentitySet identity.Identities
	// contains filtered or unexported fields
}

func (*WhatChanged) Add

func (w *WhatChanged) Add(ids ...identity.Identity)

func (*WhatChanged) Changes

func (w *WhatChanged) Changes() []identity.Identity

Jump to

Keyboard shortcuts

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