ebook

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Copyright 2022 Hal Canary Use of this program is governed by the file LICENSE.

Index

Constants

This section is empty.

Variables

View Source
var UnsupportedUrlError = errors.New("unsupported url")

Returned by a EbookGeneratorFunction when the URL can not be handled.

Functions

func ConvertToEbook

func ConvertToEbook(src, dst string, arguments ...string) error

Convert a html file to an epub, using `ebook-convert`.

func PopulateInfo added in v0.1.1

func PopulateInfo(info *EbookInfo, doc *dom.Node)

Populate `info` based on common patterns.

func RegisterEbookGenerator added in v1.0.0

func RegisterEbookGenerator(downloadFunction EbookGeneratorFunction)

Register the given function.

Types

type Chapter

type Chapter struct {
	Title    string
	Url      string
	Content  *Node
	Modified time.Time
}

One Chapter of an Ebook.

type EbookGeneratorFunction added in v1.0.0

type EbookGeneratorFunction func(url string, doPopulate bool) (EbookInfo, error)

A function that generates an ebook from a url. @param url - the URL of the title page of the book. @param doPopulate - if true, download and populate the entire EbookInfo data structure, not just its metadata.

type EbookInfo

type EbookInfo struct {
	Authors  string
	Comments string
	Title    string
	Source   string
	Language string
	Chapters []Chapter
	Modified time.Time
	Cover    []byte
}

Ebook content and metadata.

func DownloadEbook added in v1.0.0

func DownloadEbook(url string, doPopulate bool) (EbookInfo, error)

Return the result of the first registered download function that does not return UnsupportedUrlError. @param url - the URL of the title page of the book. @param doPopulate - if true, download and populate the entire EbookInfo data structure, not just its metadata.

func (EbookInfo) CalculateLastModified

func (info EbookInfo) CalculateLastModified() time.Time

Return the time of most recently modified chapter.

func (*EbookInfo) Cleanup added in v1.0.6

func (info *EbookInfo) Cleanup()

func (EbookInfo) Print added in v0.1.2

func (info EbookInfo) Print(dst io.Writer)

Print information about the book.

func (EbookInfo) Write

func (info EbookInfo) Write(dst io.Writer) error

Write the ebook as an Epub.

func (EbookInfo) WriteHtml

func (info EbookInfo) WriteHtml(dst io.Writer) error

Write the ebook as a single HTML file.

type Node

type Node = dom.Node

func Cleanup

func Cleanup(node *Node) *Node

Clean up a HTML fragment.

func ResolveLinks(node *Node, ref *url.URL) *Node

Resolve all links in the tree, relative to `ref`.

Jump to

Keyboard shortcuts

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