Documentation
¶
Index ¶
- Constants
- func DetectConfigVersion(reader io.Reader) (int, error)
- func IsUnderRootPath(root string, path string) error
- type ConfigAssetV1
- type ConfigAssetV2
- type ConfigPageLangDirectory
- type ConfigPageLangPage
- type ConfigPageLangSection
- type ConfigPageV1
- type ConfigPageV2
- type ConfigProjectV1
- type ConfigProjectV2
- type ConfigV1
- type ConfigV2
- type FrontMatter
- type ParseStateV1
- type ParseStateV2
- type SerializableTime
Constants ¶
const ( FrontMatterStart = "---" FrontMatterEnd = "---" FrontMatterKeyTitle = "title" FrontMatterKeyPath = "path" FrontMatterKeyLink = "link" FrontMatterDescription = "description" FrontMatterKeyGroup = "group" FrontMatterKeyCreatedAt = "created_at" FrontMatterKeyUpdatedAt = "updated_at" )
const ( ConfigPageTypeUnknown = iota ConfigPageTypeMarkdown ConfigPageTypeMatch ConfigPageTypeDirectory )
const ( ConfigPageKeyMarkdown = "markdown" ConfigPageKeyTitle = "title" ConfigPageKeyPath = "path" ConfigPageKeyDescription = "description" ConfigPageKeyUpdatedAt = "updated_at" ConfigPageKeyCreatedAt = "created_at" )
const ( ConfigPageMatchKeyMatch = "match" ConfigPageMatchKeySortKey = "sort_key" ConfigPageMatchKeySortOrder = "sort_order" )
const ( ConfigPageDirectoryKeyDirectory = "directory" ConfigPageDirectoryKeyChildren = "children" )
const ( ConfigPageTypeMarkdownV2 = "markdown" ConfigPageTypeMarkdownMultiLanguageV2 = "markdown_multilanguage" ConfigPageTypeMatchV2 = "match" ConfigPageTypeDirectoryV2 = "directory" ConfigPageTypeDirectoryMultiLanguageV2 = "directory_multilanguage" ConfigPageTypeSectionV2 = "section" ConfigPageTypeSectionV2MultiLanguage = "section_multilanguage" )
const ( ConfigPageV2KeyType = "type" ConfigPageV2KeyLink = "link" ConfigPageV2KeyTitle = "title" ConfigPageV2KeyDesc = "description" ConfigPageV2KeyFilepath = "filepath" ConfigPageV2KeyLang = "lang" ConfigPageV2KeyPattern = "pattern" ConfigPageV2KeySortKey = "sort_key" ConfigPageV2KeySortOrd = "sort_order" ConfigPageV2KeyChildren = "children" )
const (
SystemDefaultLanguageV2 = "en"
)
Variables ¶
This section is empty.
Functions ¶
func DetectConfigVersion ¶
DetectConfigVersion parses the YAML and returns the top-level version number. The reader is fully consumed by this function.
func IsUnderRootPath ¶
Types ¶
type ConfigAssetV1 ¶
type ConfigAssetV1 string
type ConfigAssetV2 ¶
type ConfigAssetV2 string
type ConfigPageLangDirectory ¶
type ConfigPageLangPage ¶
type ConfigPageLangSection ¶
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 ConfigProjectV2 ¶
type ConfigProjectV2 struct {
ProjectID string
Name string
Description string
Version string
Logo 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 ¶
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.