collections

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package collections is a medusa transformer that group files together in collections.

It stores the collections in a Collections type at the "Collections" key in the global store.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoName    = errors.New("no collection name specified")
	ErrNoPattern = errors.New("no collection pattern specified")
)

Functions

func New

func New(collectionCfgs ...CollectionConfig) medusa.Transformer

Adds a "Collections" key to global store. The value is of type Collections.

Types

type Collection

type Collection struct {
	// Yet another store, this time
	// specific to the collection!
	Store medusa.Store

	Files []File
}

type CollectionConfig

type CollectionConfig struct {
	// The name of the collection.
	Name string
	// Glob pattern for files to add in
	// collection.
	Patterns []string

	// Store defines the data to add
	// the files in the collections's stores
	Store medusa.Store

	// 0 if a == b,
	// -1 if a < b,
	// +1 if a > b.
	SortBy func(a medusa.File, b medusa.File) int

	FilterFunc func(file medusa.File) bool

	// Don't reverse.
	// By default it is false.
	DontReverse bool

	// zero is unlimited
	Limit int

	// Whether to include content in the
	// store of collections
	IncludeContent bool
}

Pattern and Name is the only non-optional field

type Collections

type Collections map[string]Collection

Maps collection name to collection.

type File

type File struct {
	Frontmatter map[string]any

	// often nil
	Content []byte
	// contains filtered or unexported fields
}

A file as represented in a Collection

Jump to

Keyboard shortcuts

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