metadata

package
v5.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtDuration

func FmtDuration(d time.Duration) string

FmtDuration formats a duration as "Xd Yh Zm" or "Yh Zm" if less than 24 hours

func ParseAuthorList

func ParseAuthorList(s string) []string

ParseAuthorList splits s by '&', ',', and ';', trims each part, and returns non-empty names. Used for both EPUB creator lists and PDF author strings.

func SanitizeDescription

func SanitizeDescription(raw string) string

SanitizeDescription returns sanitized HTML for use in Metadata.Description. If raw is empty or only whitespace, returns "". If raw contains no HTML (strict sanitize unchanged), wraps newline-separated paragraphs in <p>. Otherwise sanitizes with a policy that allows allowedDescriptionElements.

Types

type EpubReader

type EpubReader struct {
	GetMetadataFromFile func(path string) (*epub.Information, error)
	GetPackageFromFile  func(path string) (*epub.PackageDocument, error)
}

func NewEpubReader

func NewEpubReader() EpubReader

func (EpubReader) Cover

func (e EpubReader) Cover(documentFullPath string, coverMaxWidth int) (image.Image, error)

Cover parses the document looking for a cover image and returns it

func (EpubReader) Metadata

func (e EpubReader) Metadata(filename string) (Metadata, error)

type Metadata

type Metadata struct {
	Title         string
	Authors       []string
	Illustrators  []string
	Description   template.HTML
	Language      string
	Publication   precisiondate.PrecisionDate
	Words         float64
	Series        string
	SeriesIndex   float64
	Pages         float64
	Format        string
	Subjects      []string
	Illustrations int
}

func BuildEpubMetadataFields

func BuildEpubMetadataFields(meta *epub.Information, filename string) (Metadata, error)

BuildEpubMetadataFields maps pirmd/epub Information into Metadata (title, authors, dates, etc.). It does not open the EPUB: Illustrations and Words are left at zero unless set elsewhere. EpubReader.Metadata uses this then fills illustrations and word count from the package/zip.

func (Metadata) ReadingTime

func (m Metadata) ReadingTime(wordsPerMinute float64) string

type PdfReader

type PdfReader struct {
	Fs afero.Fs
}

func (PdfReader) Cover

func (p PdfReader) Cover(documentFullPath string, coverMaxWidth int) (image.Image, error)

Cover parses the document looking for a cover image and returns it

func (PdfReader) Illustrations

func (p PdfReader) Illustrations(documentFullPath string, minMegapixels float64) (int, error)

Illustrations returns the number of distinct embedded images with pixel count >= minMegapixels.

func (PdfReader) Metadata

func (p PdfReader) Metadata(file string) (Metadata, error)

type Reader

type Reader interface {
	Metadata(file string) (Metadata, error)
	Cover(documentFullPath string, coverMaxWidth int) (image.Image, error)
}

Jump to

Keyboard shortcuts

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