Documentation
¶
Overview ¶
Package collection reads the .mdsh.yaml file that turns a folder of runbooks into a collection: a title, description, icon, color, background image and tags that front ends show for the folder.
Index ¶
Constants ¶
const ( MaxSize = 64 << 10 // bytes of .mdsh.yaml read MaxText = 300 // runes of title or description kept MaxIcon = 8 // runes of a text icon, enough for one emoji sequence MaxTags = 32 // tags kept MaxTagSz = 40 // runes in one tag )
Limits on what a collection file holds.
const FileName = ".mdsh.yaml"
FileName is the name of a folder's collection file.
Variables ¶
This section is empty.
Functions ¶
func Images ¶
Images lists up to max image files in dir and the folders below it, as forward-slash paths relative to dir, for a form to offer as an icon or background. Hidden folders, and those more than two below dir, are left out.
func Tags ¶
Tags normalizes a tags value from YAML: a list of strings, or one string of tags split by commas or spaces, the way Jekyll and Hugo front matter allow. Tags are trimmed, lose a leading #, are made lower case and are de-duplicated in order; empty or overlong ones are dropped.
func ValidColor ¶
ValidColor reports whether s is a color Collection accepts. The check is by shape, so it is safe to put s in a style attribute; the browser decides whether a name or function is a real color.
func Writable ¶
Writable reports whether Write can save dir's .mdsh.yaml: the folder can be written to and the file, if there is one, is a regular file that can be written too.
func Write ¶
Write saves s as dir's .mdsh.yaml. Keys s leaves empty are taken out; other keys and comments in the file are kept. It saves nothing when Parse would ignore part of s, such as an icon that isn't in the folder, and says why. When the file would be left with no keys and no comments, it is removed, so the folder shows as a plain folder again.
Types ¶
type Collection ¶
type Collection struct {
// Dir is the folder's absolute path.
Dir string
// Title is shown instead of the folder's name.
Title string
// Description says what the collection is for.
Description string
// Icon is a text icon, such as an emoji. Empty when IconPath is set.
Icon string
// IconPath is the absolute path of an icon image.
IconPath string
// Color is a CSS color: #hex, rgb(), rgba(), hsl(), hsla() or a name.
Color string
// Background is the absolute path of an image shown behind the
// collection's header.
Background string
// Tags are lower case, without a leading #, and unique.
Tags []string
// Problems lists what was ignored and why, such as a path that
// leaves the folder.
Problems []string
}
Collection is a folder's .mdsh.yaml, checked: paths are absolute and inside the folder, the color is safe to put in CSS, and tags are normalized. Fields that fail a check are left empty.
func Load ¶
func Load(dir string) (*Collection, error)
Load reads dir's .mdsh.yaml. It returns nil and no error when the folder has none, and an error when the file can't be read or isn't a YAML mapping; front ends then show the folder as a plain folder.
type Settings ¶
type Settings struct {
Title string `json:"title"`
Description string `json:"description"`
Icon string `json:"icon"`
Color string `json:"color"`
Background string `json:"background"`
Tags []string `json:"tags"`
}
Settings are the keys of a .mdsh.yaml as written, for a form to edit: paths stay relative and nothing is checked. See Collection for what each key means.