meta

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: EUPL-1.2 Imports: 15 Imported by: 0

Documentation

Overview

Package meta provides the zettel specific type 'meta'.

Index

Constants

View Source
const (
	SuffixKeyRole = "-role"
	SuffixKeyURL  = "-url"
)

Some constants for key suffixes that determine a type.

View Source
const (
	SyntaxCSS      = api.ValueSyntaxCSS
	SyntaxDraw     = api.ValueSyntaxDraw
	SyntaxGif      = api.ValueSyntaxGif
	SyntaxHTML     = api.ValueSyntaxHTML
	SyntaxJPEG     = "jpeg"
	SyntaxJPG      = "jpg"
	SyntaxMarkdown = api.ValueSyntaxMarkdown
	SyntaxMD       = api.ValueSyntaxMD
	SyntaxNone     = api.ValueSyntaxNone
	SyntaxPlain    = "plain"
	SyntaxPNG      = "png"
	SyntaxSVG      = api.ValueSyntaxSVG
	SyntaxSxn      = api.ValueSyntaxSxn
	SyntaxText     = api.ValueSyntaxText
	SyntaxTxt      = "txt"
	SyntaxWebp     = "webp"
	SyntaxZmk      = api.ValueSyntaxZmk

	DefaultSyntax = SyntaxPlain
)

Supported syntax values.

View Source
const NewPrefix = "new-"

NewPrefix is the prefix for metadata key in template zettel for creating new zettel.

Variables

View Source
var (
	TypeCredential   = registerType(api.MetaCredential, false)
	TypeEmpty        = registerType(api.MetaEmpty, false)
	TypeID           = registerType(api.MetaID, false)
	TypeIDSet        = registerType(api.MetaIDSet, true)
	TypeNumber       = registerType(api.MetaNumber, false)
	TypeString       = registerType(api.MetaString, false)
	TypeTagSet       = registerType(api.MetaTagSet, true)
	TypeTimestamp    = registerType(api.MetaTimestamp, false)
	TypeURL          = registerType(api.MetaURL, false)
	TypeWord         = registerType(api.MetaWord, false)
	TypeZettelmarkup = registerType(api.MetaZettelmarkup, false)
)

Supported key types.

Functions

func BoolValue

func BoolValue(value string) bool

BoolValue returns the value interpreted as a bool.

func CleanTag

func CleanTag(tag string) string

CleanTag removes the number character ('#') from a tag value and lowercases it.

func ExpandTimestamp added in v0.16.0

func ExpandTimestamp(value string) string

ExpandTimestamp makes a short-form timestamp larger.

func Inverse

func Inverse(name string) string

Inverse returns the name of the inverse key.

func IsComputed

func IsComputed(name string) bool

IsComputed returns true, if key denotes a computed metadata key.

func IsProperty

func IsProperty(name string) bool

IsProperty returns true, if key denotes a property metadata value.

func KeyIsValid

func KeyIsValid(s string) bool

KeyIsValid returns true, if the string is a valid metadata key.

func ListFromValue

func ListFromValue(value string) []string

ListFromValue transforms a string value into a list value.

func NormalizeTag added in v0.15.0

func NormalizeTag(tag string) string

NormalizeTag adds a missing prefix "#" to the tag

func RemoveNonGraphic

func RemoveNonGraphic(s string) string

RemoveNonGraphic changes the given string not to include non-graphical characters. It is needed to sanitize meta data.

func TagsFromValue added in v0.16.0

func TagsFromValue(value string) []string

TagsFromValue returns the value as a sequence of normalized tags.

func TimeValue

func TimeValue(value string) (time.Time, bool)

TimeValue returns the time value of the given value.

Types

type Arrangement

type Arrangement map[string][]*Meta

Arrangement stores metadata within its categories. Typecally a category might be a tag name, a role name, a syntax value.

func CreateArrangement

func CreateArrangement(metaList []*Meta, key string) Arrangement

CreateArrangement by inspecting a given key and use the found value as a category.

func (Arrangement) Counted

func (a Arrangement) Counted() CountedCategories

Counted returns the list of categories, together with the number of metadata for each category.

type CountedCategories

type CountedCategories []CountedCategory

CountedCategories is the list of CountedCategories. Every name must occur only once.

func (CountedCategories) Categories

func (ccs CountedCategories) Categories() []string

Categories returns just the category names.

func (CountedCategories) SortByCount

func (ccs CountedCategories) SortByCount()

SortByCount sorts the list by the count attribute, descending. If two counts are equal, elements are sorted by name.

func (CountedCategories) SortByName

func (ccs CountedCategories) SortByName()

SortByName sorts the list by the name attribute. Since each name must occur only once, two CountedCategories cannot have the same name.

type CountedCategory

type CountedCategory struct {
	Name  string
	Count int
}

CountedCategory contains of a name and the number how much this name occured somewhere.

type DescriptionKey

type DescriptionKey struct {
	Name string
	Type *DescriptionType

	Inverse string
	// contains filtered or unexported fields
}

DescriptionKey formally describes each supported metadata key.

func GetDescription

func GetDescription(name string) DescriptionKey

GetDescription returns the key description object of the given key name.

func GetSortedKeyDescriptions

func GetSortedKeyDescriptions() []*DescriptionKey

GetSortedKeyDescriptions delivers all metadata key descriptions as a slice, sorted by name.

func (*DescriptionKey) IsComputed

func (kd *DescriptionKey) IsComputed() bool

IsComputed returns true, if metadata is computed and not set by the user.

func (*DescriptionKey) IsProperty

func (kd *DescriptionKey) IsProperty() bool

IsProperty returns true, if metadata is a computed property.

type DescriptionType

type DescriptionType struct {
	Name  string
	IsSet bool
}

DescriptionType is a description of a specific key type.

func Type

func Type(key string) *DescriptionType

Type returns a type hint for the given key. If no type hint is specified, TypeEmpty is returned.

func (DescriptionType) String

func (t DescriptionType) String() string

String returns the string representation of the given type

type Meta

type Meta struct {
	Zid id.Zid

	YamlSep bool
	// contains filtered or unexported fields
}

Meta contains all meta-data of a zettel.

func New

func New(zid id.Zid) *Meta

New creates a new chunk for storing metadata.

func NewFromInput

func NewFromInput(zid id.Zid, inp *input.Input) *Meta

NewFromInput parses the meta data of a zettel.

func NewWithData

func NewWithData(zid id.Zid, data map[string]string) *Meta

NewWithData creates metadata object with given data.

func (*Meta) Clone

func (m *Meta) Clone() *Meta

Clone returns a new copy of the metadata.

func (*Meta) ComputedPairs

func (m *Meta) ComputedPairs() []Pair

ComputedPairs returns all key/values pairs stored, in a specific order. First come the pairs with predefined keys: MetaTitleKey, MetaTagsKey, MetaSyntaxKey, MetaContextKey. Then all other pairs are append to the list, ordered by key.

func (*Meta) ComputedPairsRest

func (m *Meta) ComputedPairsRest() []Pair

ComputedPairsRest returns all key/values pairs stored, except the values with predefined keys. The pairs are ordered by key.

func (*Meta) Delete

func (m *Meta) Delete(key string)

Delete removes a key from the data.

func (*Meta) Equal

func (m *Meta) Equal(o *Meta, allowComputed bool) bool

Equal compares to metas for equality.

func (*Meta) Get

func (m *Meta) Get(key string) (string, bool)

Get retrieves the string value of a given key. The bool value signals, whether there was a value stored or not.

func (*Meta) GetBool

func (m *Meta) GetBool(key string) bool

GetBool returns the boolean value of the given key.

func (*Meta) GetDefault

func (m *Meta) GetDefault(key, def string) string

GetDefault retrieves the string value of the given key. If no value was stored, the given default value is returned.

func (*Meta) GetList

func (m *Meta) GetList(key string) ([]string, bool)

GetList retrieves the string list value of a given key. The bool value signals, whether there was a value stored or not.

func (*Meta) GetNumber

func (m *Meta) GetNumber(key string, def int64) int64

GetNumber retrieves the numeric value of a given key.

func (*Meta) GetTitle

func (m *Meta) GetTitle() string

GetTitle returns the title of the metadata. It is the only key that has a defined default value: the string representation of the zettel identifier.

func (*Meta) Length

func (m *Meta) Length() int

Length returns the number of bytes stored for the metadata.

func (*Meta) Map

func (m *Meta) Map() map[string]string

Map returns a copy of the meta data as a string map.

func (*Meta) Pairs

func (m *Meta) Pairs() []Pair

Pairs returns not computed key/values pairs stored, in a specific order. First come the pairs with predefined keys: MetaTitleKey, MetaTagsKey, MetaSyntaxKey, MetaContextKey. Then all other pairs are append to the list, ordered by key.

func (*Meta) PairsRest

func (m *Meta) PairsRest() []Pair

PairsRest returns not computed key/values pairs stored, except the values with predefined keys. The pairs are ordered by key.

func (*Meta) Sanitize

func (m *Meta) Sanitize()

Sanitize all metadata keys and values, so that they can be written safely into a file.

func (*Meta) Set

func (m *Meta) Set(key, value string)

Set stores the given string value under the given key.

func (*Meta) SetList

func (m *Meta) SetList(key string, values []string)

SetList stores the given string list value under the given key.

func (*Meta) SetNonEmpty

func (m *Meta) SetNonEmpty(key, value string)

SetNonEmpty stores the given value under the given key, if the value is non-empty. An empty value will delete the previous association.

func (*Meta) SetNow

func (m *Meta) SetNow(key string)

SetNow stores the current timestamp under the given key.

func (*Meta) SetWord added in v0.13.0

func (m *Meta) SetWord(key, word string)

SetWord stores the given word under the given key.

func (*Meta) Type

func (*Meta) Type(key string) *DescriptionType

Type returns a type hint for the given key. If no type hint is specified, TypeUnknown is returned.

func (*Meta) Write

func (m *Meta) Write(w io.Writer) (int, error)

Write writes metadata to a writer, excluding computed and propery values.

func (*Meta) WriteComputed

func (m *Meta) WriteComputed(w io.Writer) (int, error)

WriteComputed writes metadata to a writer, including computed values, but excluding property values.

type Pair

type Pair struct {
	Key   string
	Value string
}

Pair is one key-value-pair of a Zettel meta.

type UserRole

type UserRole int

UserRole enumerates the supported values of meta key 'user-role'.

const (
	UserRoleUnknown UserRole
	UserRoleCreator
	UserRoleReader
	UserRoleWriter
	UserRoleOwner
)

Supported values for user roles.

func GetUserRole

func GetUserRole(val string) UserRole

GetUserRole role returns the user role of the given string.

type Visibility

type Visibility int

Visibility enumerates the variations of the 'visibility' meta key.

const (
	VisibilityUnknown Visibility
	VisibilityPublic
	VisibilityCreator
	VisibilityLogin
	VisibilityOwner
	VisibilityExpert
)

Supported values for visibility.

func GetVisibility

func GetVisibility(val string) Visibility

GetVisibility returns the visibility value of the given string

func (Visibility) String

func (v Visibility) String() string

Jump to

Keyboard shortcuts

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