internal

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanonicalConfigPath

func CanonicalConfigPath(home string) string

func CreateExampleConfig

func CreateExampleConfig(path string) error

func DefaultLibraryPath

func DefaultLibraryPath(home string) string

func DownloadAliasNames

func DownloadAliasNames() []string

DownloadAliasNames returns supported shortcuts in display order.

func EnsureLibraryExists

func EnsureLibraryExists() error

EnsureLibraryExists creates the library directory if it doesn't exist

func ExtractFileName

func ExtractFileName(path string) string

ExtractFileName extracts a readable name from a file path

func ExtractTopicFromWikipediaFilename

func ExtractTopicFromWikipediaFilename(filename string) string

ExtractTopicFromWikipediaFilename extracts the topic from Wikipedia filenames e.g., "wikipedia_en_comics_nopic_2025-08.zim" -> "comics"

func FindArticleInAnyFile

func FindArticleInAnyFile(articleTitle string) string

FindArticleInAnyFile searches all ZIM files for a specific article

func FormatSize

func FormatSize(bytes int64) string

FormatSize formats byte size to human readable format

func GetLibraryFile

func GetLibraryFile(name string) (string, error)

GetLibraryFile returns the full path to a ZIM file in the library

func GetLibraryPath

func GetLibraryPath() string

GetLibraryPath returns the path to the ZIM library directory

func HasArticle

func HasArticle(zimPath, articleTitle string) bool

HasArticle checks if a ZIM file contains a specific article

func IsInteractive

func IsInteractive() bool

IsInteractive checks if we're running in an interactive terminal

func NormalizeZIMURL

func NormalizeZIMURL(raw string) string

NormalizeZIMURL converts Kiwix Metalink acquisition URLs to the archive URL.

func OpenZIM

func OpenZIM(path string) (*zim.File, error)

OpenZIM opens a ZIM file and returns the reader

func PipeThrough

func PipeThrough(content string) error

PipeThrough sends content through a pager (bat or less) when stdout is a TTY. Falls back to direct printing when piped or no pager is available.

func RemoveFromLibrary

func RemoveFromLibrary(name string) error

RemoveFromLibrary removes a ZIM file from the library

func RenderHTML

func RenderHTML(data []byte, width int) (string, error)

RenderHTML converts HTML content to styled terminal output using glamour. It first converts HTML to markdown, then renders with glamour for rich display.

func ResolveEntry

func ResolveEntry(z *zim.File, url string) (zim.DirectoryEntry, bool)

ResolveEntry tries to find a ZIM directory entry by URL, attempting namespace C then A, and retrying with underscore/space variants of the URL.

Fallback order:

  1. Namespace C, original URL
  2. Namespace A, original URL
  3. Namespace C, underscores → spaces
  4. Namespace A, underscores → spaces
  5. Namespace C, spaces → underscores
  6. Namespace A, spaces → underscores

func ResolveZIMPath

func ResolveZIMPath(pathOrName string) (string, error)

ResolveZIMPath resolves a ZIM file path - checks library first, then treats as regular path

func ResolveZIMPathWithArticleContext

func ResolveZIMPathWithArticleContext(pathOrName, articleTitle string) (string, error)

ResolveZIMPathWithArticleContext resolves a ZIM path using article context for smarter selection

func ResolveZIMPathWithInteraction

func ResolveZIMPathWithInteraction(pathOrName string) (string, error)

ResolveZIMPathWithInteraction resolves a ZIM path and handles ambiguous matches interactively

func SelectFromMultipleMatches

func SelectFromMultipleMatches(pattern string, matches []LibraryEntry) (string, error)

SelectFromMultipleMatches presents a list of options and returns the selected one

func StripHTML

func StripHTML(content []byte) string

StripHTML removes HTML tags from content for terminal display

func TruncateString

func TruncateString(s string, maxLen int) string

TruncateString truncates a string to specified length with ellipsis

Types

type AmbiguousMatchError

type AmbiguousMatchError struct {
	Pattern string
	Matches []LibraryEntry
}

AmbiguousMatchError represents an error where multiple files match a pattern

func (*AmbiguousMatchError) Error

func (e *AmbiguousMatchError) Error() string

type CatalogEntry

type CatalogEntry struct {
	Name        string `json:"name"`
	Flavor      string `json:"flavor"`
	Title       string `json:"title"`
	Description string `json:"description"`
	Language    string `json:"language"`
	Size        int64  `json:"size"`
	Date        string `json:"date"`
	URL         string `json:"url"`
	Tags        string `json:"tags"`
}

CatalogEntry represents a single ZIM file available from Kiwix.

func FetchCatalog

func FetchCatalog(lang string) ([]CatalogEntry, error)

FetchCatalog returns catalog entries, using cache when fresh. Falls back to stale cache on network errors.

func FetchCatalogByName

func FetchCatalogByName(ctx context.Context, name string) ([]CatalogEntry, error)

FetchCatalogByName fetches the bounded exact-name result set used by download aliases. It does not use the broad browsing cache, so a shortcut cannot be resolved from an unrelated or incomplete first page.

func ResolveCatalogEntry

func ResolveCatalogEntry(entries []CatalogEntry, name, preferredFlavor string) (CatalogEntry, error)

ResolveCatalogEntry selects the newest unambiguous entry with the exact catalog name and, when requested, the preferred archive flavor.

type Config

type Config struct {
	Library LibraryConfig `mapstructure:"library"`
	Server  ServerConfig  `mapstructure:"server"`
	Search  SearchConfig  `mapstructure:"search"`
	Index   IndexConfig   `mapstructure:"index"`
}

Config represents application configuration.

func GetConfig

func GetConfig() *Config

GetConfig loads a fresh configuration for legacy callers. Configuration is intentionally not cached; cmd.App owns the configuration used by a run.

func LoadConfig

func LoadConfig() (*Config, error)

type ConfigLoader

type ConfigLoader struct {
	HomeDir string
	EtcDir  string
	Environ []string
}

ConfigLoader owns all inputs used to load configuration. Empty fields use the process defaults; tests can provide every field to avoid global state.

func NewConfigLoader

func NewConfigLoader() ConfigLoader

func (ConfigLoader) Load

func (l ConfigLoader) Load() (*LoadedConfig, error)

type DirectoryEntry

type DirectoryEntry = zim.DirectoryEntry

DirectoryEntry represents a ZIM directory entry

type DownloadAlias

type DownloadAlias struct {
	CatalogName     string
	PreferredFlavor string
	Description     string
}

DownloadAlias defines one supported catalog-backed CLI shortcut.

func LookupDownloadAlias

func LookupDownloadAlias(name string) (DownloadAlias, bool)

LookupDownloadAlias returns catalog policy for a supported CLI shortcut.

type IndexConfig

type IndexConfig struct {
	Backend     string `mapstructure:"backend"`
	Path        string `mapstructure:"path"`
	VectorIndex string `mapstructure:"vector_index"`
	Parallel    bool   `mapstructure:"parallel"`
	BatchSize   int    `mapstructure:"batch_size"`
	WorkerCount int    `mapstructure:"worker_count"`
}

type Library

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

Library owns access to the configured ZIM library root.

func NewLibrary

func NewLibrary(root string) (*Library, error)

func (*Library) Ensure

func (l *Library) Ensure() error

func (*Library) List

func (l *Library) List() ([]LibraryEntry, error)

func (*Library) Remove

func (l *Library) Remove(name string) (string, error)

Remove deletes a resolved archive only when its canonical path is contained by the configured library root.

func (*Library) Resolve

func (l *Library) Resolve(pathOrName string) (string, error)

Resolve finds a CLI archive using the configured library before accepting an explicit path. Explicit paths remain supported for the CLI; web callers must use ResolveWebPath.

func (*Library) ResolveWebPath

func (l *Library) ResolveWebPath(requested, startup string) (string, error)

ResolveWebPath allows only an existing ZIM under the configured root or the explicit startup file. Canonical paths prevent traversal and symlink escapes.

func (*Library) Root

func (l *Library) Root() string

type LibraryConfig

type LibraryConfig struct {
	Path string `mapstructure:"path"`
}

type LibraryEntry

type LibraryEntry struct {
	Name string
	Path string
	Size int64
}

LibraryEntry represents a ZIM file in the library

func ListLibraryFiles

func ListLibraryFiles() ([]LibraryEntry, error)

ListLibraryFiles returns all ZIM files in the library

type LoadedConfig

type LoadedConfig struct {
	Config *Config
	Source string
}

LoadedConfig records both the merged configuration and the file that supplied it. Source is empty when defaults and environment variables are used alone.

type Namespace

type Namespace = zim.Namespace

Namespace represents a ZIM namespace

type SearchConfig

type SearchConfig struct {
	MaxResults     int  `mapstructure:"max_results"`
	NonInteractive bool `mapstructure:"non_interactive"`
	JSONOutput     bool `mapstructure:"json_output"`
}

type ServerConfig

type ServerConfig struct {
	Port         int    `mapstructure:"port"`
	Host         string `mapstructure:"host"`
	ReadTimeout  int    `mapstructure:"read_timeout"`
	WriteTimeout int    `mapstructure:"write_timeout"`
	IdleTimeout  int    `mapstructure:"idle_timeout"`
}

type ZIMFile

type ZIMFile = zim.File

ZIMFile represents a ZIM file

Directories

Path Synopsis
Package embeddings provides reusable semantic embedding generation using Model2Vec.
Package embeddings provides reusable semantic embedding generation using Model2Vec.

Jump to

Keyboard shortcuts

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