config

package
v0.0.0-...-ead6f67 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrontMatterStart = "---"
	FrontMatterEnd   = "---"

	FrontMatterKeyTitle     = "title"
	FrontMatterKeyPath      = "path"
	FrontMatterKeyLink      = "link"
	FrontMatterDescription  = "description"
	FrontMatterKeyGroup     = "group"
	FrontMatterKeyCreatedAt = "created_at"
	FrontMatterKeyUpdatedAt = "updated_at"
)
View Source
const (
	ConfigPageTypeUnknown = iota
	ConfigPageTypeMarkdown
	ConfigPageTypeMatch
	ConfigPageTypeDirectory
)
View Source
const (
	ConfigPageKeyMarkdown    = "markdown"
	ConfigPageKeyTitle       = "title"
	ConfigPageKeyPath        = "path"
	ConfigPageKeyDescription = "description"
	ConfigPageKeyUpdatedAt   = "updated_at"
	ConfigPageKeyCreatedAt   = "created_at"
)
View Source
const (
	ConfigPageMatchKeyMatch     = "match"
	ConfigPageMatchKeySortKey   = "sort_key"
	ConfigPageMatchKeySortOrder = "sort_order"
)
View Source
const (
	ConfigPageDirectoryKeyDirectory = "directory"
	ConfigPageDirectoryKeyChildren  = "children"
)
View Source
const (
	ConfigPageTypeMarkdownV2               = "markdown"
	ConfigPageTypeMarkdownMultiLanguageV2  = "markdown_multilanguage"
	ConfigPageTypeMatchV2                  = "match"
	ConfigPageTypeDirectoryV2              = "directory"
	ConfigPageTypeDirectoryMultiLanguageV2 = "directory_multilanguage"
	ConfigPageTypeSectionV2                = "section"
	ConfigPageTypeSectionV2MultiLanguage   = "section_multilanguage"
)
View Source
const (
	ConfigPageV2KeyType     = "type"
	ConfigPageV2KeyLink     = "link"
	ConfigPageV2KeyTitle    = "title"
	ConfigPageV2KeyDesc     = "description"
	ConfigPageV2KeyFilepath = "filepath"
	ConfigPageV2KeyLang     = "lang"
	ConfigPageV2KeyPattern  = "pattern"
	ConfigPageV2KeySortKey  = "sort_key"
	ConfigPageV2KeySortOrd  = "sort_order"
	ConfigPageV2KeyChildren = "children"
)
View Source
const (
	SystemDefaultLanguageV2 = "en"
)

Variables

This section is empty.

Functions

func DetectConfigVersion

func DetectConfigVersion(reader io.Reader) (int, error)

DetectConfigVersion parses the YAML and returns the top-level version number. The reader is fully consumed by this function.

func IsUnderRootPath

func IsUnderRootPath(root string, path string) error

Types

type ConfigAssetV1

type ConfigAssetV1 string

func (ConfigAssetV1) List

func (m ConfigAssetV1) List(rootDir string) ([]string, error)

type ConfigAssetV2

type ConfigAssetV2 string

func (ConfigAssetV2) List

func (m ConfigAssetV2) List(rootDir string) ([]string, error)

type ConfigPageLangDirectory

type ConfigPageLangDirectory struct {
	Title       string
	Description string
}

type ConfigPageLangPage

type ConfigPageLangPage struct {
	Link        string
	Title       string
	Description string
	Filepath    string
}

type ConfigPageLangSection

type ConfigPageLangSection struct {
	Title       string
	Description string
}

type ConfigPageV1

type ConfigPageV1 struct {
	// markdown syntax
	Markdown    string
	Title       string
	Path        string
	Description string
	UpdatedAt   SerializableTime
	CreatedAt   SerializableTime

	// directory syntax
	Directory string
	Children  []ConfigPageV1
}

func (*ConfigPageV1) MatchDirectory

func (c *ConfigPageV1) MatchDirectory() bool

func (*ConfigPageV1) MatchMarkdown

func (c *ConfigPageV1) MatchMarkdown() bool

Check if the page is a valid single page.

type ConfigPageV2

type ConfigPageV2 struct {
	// Type defines how this page entry should be parsed (markdown/markdown_multilanguage/match/directory/section).
	Type string

	// LangPage holds per-locale page variants (keyed by ISO 639-1 code).
	LangPage map[string]ConfigPageLangPage
	// LangDirectory holds per-locale directory titles (keyed by ISO 639-1 code).
	LangDirectory map[string]ConfigPageLangDirectory
	// LangSection holds per-locale section titles (keyed by ISO 639-1 code).
	LangSection map[string]ConfigPageLangSection

	// Children is used by directory/section entries.
	Children []ConfigPageV2
}

func (*ConfigPageV2) SortKeyTitle

func (c *ConfigPageV2) SortKeyTitle(defaultLang string) string

type ConfigProjectV1

type ConfigProjectV1 struct {
	ProjectID       string
	Name            string
	Description     string
	Version         string
	Repository      string
	DefaultLanguage string
}

type ConfigProjectV2

type ConfigProjectV2 struct {
	ProjectID       string
	Name            string
	Description     string
	Version         string
	Repository      string
	DefaultLanguage string
}

func (*ConfigProjectV2) GetDefaultLanguageOrFallback

func (c *ConfigProjectV2) GetDefaultLanguageOrFallback() string

type ConfigV1

type ConfigV1 struct {
	Version string
	Project ConfigProjectV1
	Pages   []ConfigPageV1
	Assets  []ConfigAssetV1
}

func ParseConfigV1

func ParseConfigV1(state *ParseStateV1, reader io.Reader) (*ConfigV1, error)

ParseConfigV1 takes a reader and parses it into a ConfigV1 struct. While parsing, it validates the config at the same time. This is to provide a user-friendly error message.

This function follows the implementation at: https://github.com/goccy/go-yaml/blob/abc70836f5a5623a92cf51d4bf40cbaf8fed2faa/decode.go

type ConfigV2

type ConfigV2 struct {
	Version string
	Project ConfigProjectV2
	Pages   []ConfigPageV2
	Assets  []ConfigAssetV2
}

func ParseConfigV2

func ParseConfigV2(state *ParseStateV2, reader io.Reader) (*ConfigV2, error)

type FrontMatter

type FrontMatter struct {
	Title           string
	Link            string
	LanguageGroupID string
	Description     string
	CreatedAt       SerializableTime
	UpdatedAt       SerializableTime
	UnknownTags     map[string]interface{}
}

A struct that describes the markdown header.

func NewFrontMatter

func NewFrontMatter(title string, path string, now ...time.Time) *FrontMatter

func NewFrontMatterFromMarkdown

func NewFrontMatterFromMarkdown(filepath string) (*FrontMatter, error)

func (*FrontMatter) Lang

func (f *FrontMatter) Lang() string

Lang returns the language code from front matter if present.

func (*FrontMatter) String

func (f *FrontMatter) String() string

func (*FrontMatter) UpdateMarkdown

func (f *FrontMatter) UpdateMarkdown(filepath string) error

UpdateMarkdown updates the front matter of the specified markdown file. It keeps the remaining contents of the file intact.

type ParseStateV1

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

A struct to keep the state of the parsing process.

func NewParseStateV1

func NewParseStateV1(filepath, workingDir string) *ParseStateV1

type ParseStateV2

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

func NewParseStateV2

func NewParseStateV2(filepath, workingDir string) *ParseStateV2

type SerializableTime

type SerializableTime struct {
	time.Time
}

SerializableTime is a custom type to process time in json and yaml format.

func NewSerializableTime

func NewSerializableTime(s string) (SerializableTime, error)

func NewSerializableTimeFromTime

func NewSerializableTimeFromTime(t time.Time) SerializableTime

func (*SerializableTime) HasValue

func (t *SerializableTime) HasValue() bool

func (SerializableTime) MarshalJSON

func (t SerializableTime) MarshalJSON() ([]byte, error)

func (SerializableTime) String

func (t SerializableTime) String() string

String converts the time into a string.

Jump to

Keyboard shortcuts

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