Documentation
¶
Index ¶
Constants ¶
const LinkCSS = `<link href="style.css" rel="stylesheet" type="text/css"/>`
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Content ¶
type Content struct {
// Body contains the actual HTML/text data for this section.
Body body.Body
// ReferenceType defines the semantic nature (e.g., Preface, Text, Index).
ReferenceType reftype.ReferenceType
// SubContents allows for hierarchical nesting of chapters (e.g., Part > Chapter).
SubContents []Content
// ContentReferences defines internal navigational points within this content.
ContentReferences []ContentReference
// Filename is an optional custom name for the generated XHTML file.
Filename nilo.Option[string]
}
Content represents a chapter, section, or specific semantic block within the EPUB. It supports recursive nesting via SubContents and internal cross-linking via ContentReferences.
func (Content) CreateFileContent ¶
func (c Content) CreateFileContent(number *int, stylesheet string) ([]files.FileContent[string], error)
CreateFileContent recursively generates a slice of FileContent objects. It wraps the raw body in a valid XHTML 1.1 template, applies the stylesheet, and places the resulting files into the "OEBPS/" directory.
func (Content) GetFilename ¶
GetFilename returns the user-defined filename or generates a default sequential one (e.g., "c01.xhtml") based on the provided index.
func (Content) Level ¶
Level calculates the maximum depth of the nested SubContents tree. A content block with no children returns 0.
func (Content) LevelReferenceContent ¶
LevelReferenceContent calculates the maximum nesting depth of the tree, accounting for both SubContents and ContentReferences.
type ContentReference ¶
type ContentReference struct {
// Title is the text displayed in the navigation menu.
Title string
// SubContentReferences allows for nested navigation levels (e.g., Chapter 1 > Section A).
SubContentReferences []ContentReference
// ID is an optional HTML anchor ID within the target file.
ID nilo.Option[string]
}
ContentReference represents a navigational entry point within a content file. It is used to generate Table of Contents (ToC) entries that can point to specific anchors or headers within a section.
func (ContentReference) ReferenceName ¶
func (cr ContentReference) ReferenceName(xhtml string, number int) string
ReferenceName constructs a full URI for the reference, combining the XHTML filename with an anchor fragment. If no ID is provided, it generates a default fragment (e.g., "filename.xhtml#id01").
type Epub ¶
type Epub struct {
// Metadata contains the bibliographic information for the publication.
Metadata Metadata
// Stylesheet is an optional global CSS body applied to all content sections.
Stylesheet nilo.Option[body.Body]
// CoverImage is the optional image designated as the book's front cover.
CoverImage nilo.Option[resource.Image]
// Resources is a collection of secondary assets like fonts, audio, or video.
Resources []resource.Resource
// Contents holds the primary reading order and structural sections of the book.
Contents []Content
}
Epub represents the complete structure of an EPUB document. It serves as the root container that holds metadata, styling, embedded resources, and the hierarchical content tree.
type Metadata ¶
type Metadata struct {
// Title is the primary name of the publication.
Title string
// Language defines the primary language of the content (ISO 639-1).
Language lang.Language
// Identifier is the unique ID for the book (e.g., UUID or ISBN).
Identifier ident.Identifier
// Creator is the primary author or organization responsible for the work.
Creator nilo.Option[string]
// Contributor is an entity that made secondary contributions.
Contributor nilo.Option[string]
// Publisher is the entity responsible for publication.
Publisher nilo.Option[string]
// Date is the publication or creation timestamp.
Date nilo.Option[time.Time]
// Subject defines the keywords or categories for the book.
Subject nilo.Option[string]
// Description is a summary or abstract of the content.
Description nilo.Option[string]
}
Metadata represents the Dublin Core metadata elements for the EPUB. It includes mandatory fields like Title, Language, and Identifier, along with optional bibliographic descriptors.