mobi

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT, MIT Imports: 10 Imported by: 0

README

Go MOBI

Github Actions CI Go Report Card Go Reference

This package implements facilities to create KF8-formatted MOBI and AZW3 books. We also export the raw PalmDB writer and various PalmDoc, MOBI and KF8 components as subpackages, which can be used to implement other formats that build on these standards.

Known issues

  • Chapters are supported but subchapters are not
  • Books without any text content are always malformed
  • Errors during template expansion result in a panic

References

Huge thanks to the authors of these resources.

License

MIT © Leo Gaskin 2020-2021

Modifications

Small modifications have been made to enable vertical displaying of text.

Masahiro Yamada

Documentation

Overview

Package mobi implements writing KF8-style formatted MOBI and AZW3 books.

Index

Constants

This section is empty.

Variables

View Source
var SupportedLocales []language.Tag

SupportedLocales is a list of locales supported by MOBI, intended for use with Go language matching facilities.

BUG(leotaku): While the MOBI language format supports regions, this implementation does not and explicitly removes region information from the locale stored in the generated MOBI file.

Functions

func Split

func Split(s string) (list []string)

Types

type Book

type Book struct {
	Title         string
	Authors       []string
	Contributors  []string
	Publisher     string
	Subject       string
	CreatedDate   time.Time
	PublishedDate time.Time
	DocType       string
	Language      language.Tag
	FixedLayout   bool
	RightToLeft   bool
	Vertical      bool
	Chapters      []Chapter
	CSSFlows      []string
	Images        []r.ImageRecord
	CoverImage    image.Image
	ThumbImage    image.Image
	UniqueID      uint32
	Html          string
	// contains filtered or unexported fields
}

Book represents all the information necessary to generate a KF8-style formatted MOBI or AZW3 book.

You are expected to initialize the Book struct using the required variables and/or builder pattern, then convert the resulting structure into a PalmDB database. This database can then be written out to any io.Writer.

func (Book) GetThumbFilename

func (m Book) GetThumbFilename() string

GetThumbFilename returns the filename a JPEG image in the Kindle thumbnails folder would need to have in order to be correctly associated with the generated book.

Newer Kindle readers no longer respect the thumbnail embedded in the Palm database but instead try to download the cover art from Amazon's servers using the embedded ASIN identification string. However, we can still get covers for sideloaded books by embedding a fake ASIN identification string and manually copying an image to the corresponding location inside the Kindle thumbnails folder.

func (*Book) OverrideTemplate

func (m *Book) OverrideTemplate(tpl template.Template) Book

OverrideTemplate overrides the template used in order to generate the skeleton section of a KF8 HTML chunk.

During conversion to a PalmDB database, this template is passed the internal inventory type. If the template cannot successfully be applied, the conversion will panic.

The skeleton section generally consists of a complete HTML document including head and body, with the body tag expected to contain an 'aid' attribute that indicates the identifier of the corresponding chunk. As it is relatively easy to end up with an invalid KF8 document by generating invalid skeleton sections, this option is private and hidden behind a setter function.

func (Book) Realize

func (m Book) Realize() pdb.Database

Realize converts a MobiBook to a PalmDB Database.

type Chapter

type Chapter struct {
	Title  string
	Chunks []Chunk
}

Chapter represents a chapter in a MobiBook book.

type Chunk

type Chunk struct {
	Body string
}

Chunk represents a chunk of text in a MobiBook Chapter.

Chunks are mostly an implementation detail that is exposed for maximum control over the final book output. Generally, you should use one of the various "Chunks" functions in order to generate the correct amount of chunks for a chapter.

func Chunks

func Chunks(list ...string) []Chunk

Chunks produces a list of chunks from one or more strings.

In the resulting list of chunks, each chunk exactly corresponds the given string with the same index. In almost all cases, this is the preferred method of converting KF8 HTML into a list of chunks.

Notes

Bugs

  • While the MOBI language format supports regions, this implementation does not and explicitly removes region information from the locale stored in the generated MOBI file.

Directories

Path Synopsis
Package jfif implements writing JPEG images with fixed JFIF header.
Package jfif implements writing JPEG images with fixed JFIF header.
Package pdb implements reading and writing PalmDB databases.
Package pdb implements reading and writing PalmDB databases.
Package records contains facilities to create MOBI formatted books.
Package records contains facilities to create MOBI formatted books.
Package types contains types and constants to create MOBI formatted books.
Package types contains types and constants to create MOBI formatted books.

Jump to

Keyboard shortcuts

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