collection

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const FileName = ".mdsh.yaml"

FileName is the name of a folder's collection file.

Variables

This section is empty.

Functions

func Images

func Images(dir string, max int) []string

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 Merge

func Merge(a, b []string) []string

Merge returns the tags of a, then those of b not in a.

func Tags

func Tags(v any) []string

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

func ValidColor(s string) bool

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

func Writable(dir string) bool

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

func Write(dir string, s Settings) error

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.

func Parse

func Parse(dir string, src []byte) (*Collection, error)

Parse checks src, the contents of dir's .mdsh.yaml. Relative paths in it are resolved against dir, which must be absolute.

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.

func Read

func Read(dir string) (Settings, error)

Read returns dir's .mdsh.yaml as written. A folder without one reads as empty Settings. It fails when the file can't be read or isn't a YAML mapping, since Write would then lose what is in it.

Jump to

Keyboard shortcuts

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