libro

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// FilepathFuncMap provides standard functions to build/manipulate path in
	// template.Funcmap's format:
	//  - ext         : get file extension
	//  - sanitizePath: replace special chars that don't usually work well when
	//                  use in path name
	//  - nospace     : get rid of spaces
	FilepathFuncMap = template.FuncMap{
		"base":             filepath.Base,
		"ext":              filepath.Ext,
		"sanitizePath":     pathSanitizer,
		"sanitizeFilename": filenameSanitizer,
		"nospace":          nospaceSanitizer,
	}
)

Functions

func TmplFuncMap

func TmplFuncMap(t *template.Template) template.FuncMap

TmplFuncMap provides standard functions to execute go text templates path in template.Funcmap's format:

  • tmpl : execute a sub-template by name. Sub-templates are chosen from t namespace

Types

type Libro

type Libro struct {
	// Root is the location of Libro's library.
	Root string

	// Verbose is the logger for providing low interest messages to the user.
	Verbose *log.Logger

	// Debug is the logger for providing messages supposed to help the
	// developer understand his/her mistakes.
	Debug *log.Logger

	// UseGuesser, if set,  tries to complete book's metadata by guessing
	// missing information using media's filename and title.
	// Default to false (do not try metadata guessing)
	UseGuesser bool

	// LocationTmpl is a text.Template that determines the standardized media
	// files location in the collection based on their metadata.
	// Default to nil (keep item location as-is)
	LocationTmpl *template.Template
}

Libro represents a collection of media and its associated management facilities.

func New

func New() *Libro

New creates a new Libro.

func (*Libro) Create

func (lib *Libro) Create(b *book.Book) error

Create inserts a new book in Libro's collection.

It determines the location in the collection by executing Libro.LocationTmpl against book's metadata. Location can be relative or absolute, relative location are relative to the Libro's root folder. Location can contain reference to environment variables that are expanded to determine the target location to store the book's file.

Create operation will fail if the target location already exists.

func (*Libro) Read

func (lib *Libro) Read(path string) (*book.Book, error)

Read extracts all possible information about a book.

Jump to

Keyboard shortcuts

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