Help us shape the future of Go! Take the 2026 Go Developer Survey

pub

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: BSD-3-Clause Imports: 14 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContentLink = manifest.Link{
	Href:      manifest.MustNewHREFFromString("~readium/content.json", false),
	MediaType: &mediatype.ReadiumContentDocument,
}
View Source
var GuidedNavigationLink = manifest.Link{
	Href:      manifest.MustNewHREFFromString("~readium/guided-navigation.json{?ref}", true),
	MediaType: &mediatype.ReadiumGuidedNavigationDocument,
}

GuidedNavigationLink is the templated link of the guided navigation service, which generates guided navigation documents from the publication's (X)HTML documents. It is advertised in the manifest's links when the service is public.

View Source
var MediaOverlayLink = manifest.Link{
	Href:      manifest.MustNewHREFFromString("~readium/media-overlay.json{?ref}", true),
	MediaType: &mediatype.ReadiumGuidedNavigationDocument,
}

MediaOverlayLink is the templated link of the media overlay service, which converts a resource's SMIL media overlay into a guided navigation document. It is never advertised in the manifest's links: the service replaces each SMIL alternate with an expansion of this link instead.

View Source
var PositionsLink = manifest.Link{
	Href:      manifest.MustNewHREFFromString("~readium/positions.json", false),
	MediaType: &mediatype.ReadiumPositionList,
}

Functions

func GetForContentService

func GetForContentService(ctx context.Context, service ContentService, link manifest.Link) (fetcher.Resource, bool)

func GetForGuidedNavigationService added in v0.5.0

func GetForGuidedNavigationService(ctx context.Context, service GuidedNavigationService, link manifest.Link) (fetcher.Resource, bool)

GetForGuidedNavigationService serves a GuidedNavigationLink expansion from the given service.

func GetForMediaOverlayService added in v0.16.0

func GetForMediaOverlayService(ctx context.Context, service GuidedNavigationService, link manifest.Link) (fetcher.Resource, bool)

GetForMediaOverlayService serves a MediaOverlayLink expansion from the given service.

func GetForPositionsService

func GetForPositionsService(ctx context.Context, service PositionsService, link manifest.Link) (fetcher.Resource, bool)

Types

type Builder

type Builder struct {
	Manifest        manifest.Manifest
	Fetcher         fetcher.Fetcher
	ServicesBuilder ServicesBuilder
}

func (Builder) Build

func (b Builder) Build() *Publication

type ContentService

type ContentService interface {
	Service
	Content(start *manifest.Locator) content.Content // Creates a [Content] starting from the given [start] location.
}

PositionsService implements Service Provides a way to extract the raw [Content] of a Publication.

type Context

type Context struct {
	Manifest manifest.Manifest
	Fetcher  fetcher.Fetcher
}

Container for the context from which a service is created.

func NewContext

func NewContext(manifest manifest.Manifest, fetcher fetcher.Fetcher) Context

type DefaultContentService

type DefaultContentService struct {
	// contains filtered or unexported fields
}

Implements ContentService

func (DefaultContentService) Close

func (s DefaultContentService) Close()

func (DefaultContentService) Content

func (DefaultContentService) Get

type GuidedNavigationService added in v0.5.0

type GuidedNavigationService interface {
	Service
	GuideForResource(ctx context.Context, href string) (*guidednavigation.GuidedNavigationDocument, error)
	HasGuideForResource(href string) bool
}

GuidedNavigationService implements Service Provides a way to access guided navigation documents for resources of a Publication.

type HTMLGuidedNavigationService added in v0.16.0

type HTMLGuidedNavigationService struct {
	// contains filtered or unexported fields
}

HTMLGuidedNavigationService provides guided navigation documents generated from the (X)HTML documents of a publication's reading order and resources.

func (*HTMLGuidedNavigationService) Close added in v0.16.0

func (s *HTMLGuidedNavigationService) Close()

func (*HTMLGuidedNavigationService) Get added in v0.16.0

func (*HTMLGuidedNavigationService) GuideForResource added in v0.16.0

func (*HTMLGuidedNavigationService) HasGuideForResource added in v0.16.0

func (s *HTMLGuidedNavigationService) HasGuideForResource(href string) bool

type PerResourcePositionsService

type PerResourcePositionsService struct {
	// contains filtered or unexported fields
}

PerResourcePositionsService implements PositionsService Simple PositionsService which generates one position per [readingOrder] resource.

func (PerResourcePositionsService) Close

func (s PerResourcePositionsService) Close()

func (PerResourcePositionsService) Get

func (PerResourcePositionsService) Positions

func (PerResourcePositionsService) PositionsByReadingOrder

func (s PerResourcePositionsService) PositionsByReadingOrder(ctx context.Context) [][]manifest.Locator

type PositionsService

type PositionsService interface {
	Service
	PositionsByReadingOrder(ctx context.Context) [][]manifest.Locator // Returns the list of all the positions in the publication, grouped by the resource reading order index.
	Positions(ctx context.Context) []manifest.Locator                 // Returns the list of all the positions in the publication. (flattening of PositionsByReadingOrder)
}

PositionsService implements Service Provides a list of discrete locations in the publication, no matter what the original format is.

type Publication

type Publication struct {
	Manifest manifest.Manifest // The manifest holding the publication metadata extracted from the publication file.
	Fetcher  fetcher.Fetcher   // The underlying fetcher used to read publication resources.
	// contains filtered or unexported fields
}

The Publication shared model is the entrypoint for all the metadata and services related to a Readium publication.

func (Publication) BaseURL

func (p Publication) BaseURL() url.URL

The URL where this publication is served, computed from the [Link] with `self` relation.

func (Publication) Close

func (p Publication) Close()

Free up resources associated with the publication

func (Publication) ConformsTo

func (p Publication) ConformsTo(profile manifest.Profile) bool

Returns whether this publication conforms to the given Readium Web Publication Profile.

func (Publication) FindService

func (p Publication) FindService(serviceName ServiceName) Service

Find a service in the publication by its name.

func (Publication) Get

Returns the resource targeted by the given non-templated [link].

func (Publication) JSONManifest

func (p Publication) JSONManifest() (string, error)

Returns the RWPM JSON representation for this Publication's manifest, as a string.

func (Publication) LinkWithHref

func (p Publication) LinkWithHref(href url.URL) *manifest.Link

Finds the first [Link] with the given href in the publication's links. Searches through (in order) the reading order, resources and links recursively following alternate and children links. If there's no match, tries again after removing any query parameter and anchor from the given href.

func (Publication) LinkWithRel

func (p Publication) LinkWithRel(rel string) *manifest.Link

Finds the first [Link] having the given [rel] in the publications's links.

func (Publication) LinksWithRel

func (p Publication) LinksWithRel(rel string) []manifest.Link

Finds all [Link]s having the given [rel] in the publications's links.

func (p Publication) LocatorFromLink(link manifest.Link) *manifest.Locator

Creates a new [Locator] object from a [Link] to a resource of this publication. Returns nil if the resource is not found in this publication.

func (*Publication) Positions

func (p *Publication) Positions(ctx context.Context) []manifest.Locator

func (Publication) PositionsByReadingOrder

func (p Publication) PositionsByReadingOrder(ctx context.Context) [][]manifest.Locator

func (Publication) PositionsFromManifest

func (p Publication) PositionsFromManifest(ctx context.Context) []manifest.Locator

type Service

type Service interface {
	Links() manifest.LinkList                                             // Links to be added to the publication
	Get(ctx context.Context, link manifest.Link) (fetcher.Resource, bool) // A service can return a Resource that supplements, replaces or compensates for other links
	Close()                                                               // Closes any opened file handles, removes temporary files, etc.
}

Base interface to be implemented by all publication services.

type ServiceFactory

type ServiceFactory func(context Context, public bool) Service

func DefaultContentServiceFactory

func DefaultContentServiceFactory(resourceContentIteratorFactories []iterator.ResourceContentIteratorFactory) ServiceFactory

func HTMLGuidedNavigationServiceFactory added in v0.16.0

func HTMLGuidedNavigationServiceFactory(opts ...converter.Option) ServiceFactory

HTMLGuidedNavigationServiceFactory creates a service generating guided navigation documents from the (X)HTML documents of a publication's reading order and resources. It never touches SMIL media overlays (see the EPUB parser's media overlay service for those) and adds nothing to the manifest besides its own templated link when public. The options are passed to the HTML converter, e.g. converter.WithTextRefLocators. When the publication has no (X)HTML documents, no service is created.

func PerResourcePositionsServiceFactory

func PerResourcePositionsServiceFactory(fallbackMediaType mediatype.MediaType) ServiceFactory

type ServiceName added in v0.11.0

type ServiceName string
const (
	ContentProtectionService_Name ServiceName = "ContentProtectionService"
	CoverService_Name             ServiceName = "CoverService"
	LocatorService_Name           ServiceName = "LocatorService"
	PositionsService_Name         ServiceName = "PositionsService"
	SearchService_Name            ServiceName = "SearchService"
	ContentService_Name           ServiceName = "ContentService"
	GuidedNavigationService_Name  ServiceName = "GuidedNavigationService"
	MediaOverlayService_Name      ServiceName = "MediaOverlayService"
)

type ServicesBuilder

type ServicesBuilder struct {
	// contains filtered or unexported fields
}

Builds a list of Service from a collection of service factories. Provides helpers to manipulate the list of services of a pub.Publication.

func NewServicesBuilder

func NewServicesBuilder(fcs map[ServiceName]ServiceFactory) *ServicesBuilder

func (*ServicesBuilder) Build

func (s *ServicesBuilder) Build(context Context) map[ServiceName]Service

Builds the actual list of publication services to use in a Publication.

func (*ServicesBuilder) Decorate

func (s *ServicesBuilder) Decorate(name ServiceName, transform func(*ServiceFactory) ServiceFactory)

Replaces the service factory associated with the given service type with the result of [transform]

func (s *ServicesBuilder) ExposeLinks(name ServiceName)

func (*ServicesBuilder) Get

Gets the publication service factory for the given service type.

func (s *ServicesBuilder) HideLinks(name ServiceName)

func (*ServicesBuilder) Remove

func (s *ServicesBuilder) Remove(name ServiceName)

Removes the service factory producing the given kind of service, if any.

func (*ServicesBuilder) RemoveExcept added in v0.11.0

func (s *ServicesBuilder) RemoveExcept(name ...ServiceName)

Removes all service factories except the ones producing the given kinds of services, if any. If no services are given, all service factories are removed.

func (*ServicesBuilder) Services added in v0.12.0

func (s *ServicesBuilder) Services() []ServiceName

Gets the names of all services currently in the builder

func (*ServicesBuilder) Set

func (s *ServicesBuilder) Set(name ServiceName, factory *ServiceFactory)

Sets the publication service factory for the given service type.

Jump to

Keyboard shortcuts

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