Compare commits
13 Commits
create-con
...
v0.0.7-cb3
| Author | SHA1 | Date | |
|---|---|---|---|
| 60a1d545ed | |||
| 3a72204915 | |||
| 0516534526 | |||
| d260f5299f | |||
| 1f93d2d37d | |||
| 55addf2a77 | |||
| 06dec42e83 | |||
| fceee7bc04 | |||
| 8edca6d367 | |||
| 1ab65e69a0 | |||
| 7a62b2d19d | |||
| 030c1ba495 | |||
| 9b6f062c65 |
|
Before Width: | Height: | Size: 80 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 81 KiB |
|
Before Width: | Height: | Size: 63 KiB |
BIN
.github/assets/darkmode.png
vendored
Normal file
|
After Width: | Height: | Size: 35 KiB |
BIN
.github/assets/help.png
vendored
Normal file
|
After Width: | Height: | Size: 40 KiB |
BIN
.github/assets/light.png
vendored
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
.github/assets/margin.png
vendored
Normal file
|
After Width: | Height: | Size: 32 KiB |
54
.github/workflows/ci.yaml
vendored
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
name: build-and-test
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
version: [1.24.9]
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
name: Build
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Set up Go ${{ matrix.os }}
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '${{ matrix.version }}'
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: build
|
||||||
|
run: go build
|
||||||
|
|
||||||
|
test:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
version: [1.24.9]
|
||||||
|
os: [ubuntu-latest]
|
||||||
|
name: Test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
steps:
|
||||||
|
- name: Set up Go ${{ matrix.os }}
|
||||||
|
uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: '${{ matrix.version }}'
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: checkout
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
run: go test -cover ./...
|
||||||
|
|
||||||
|
|
||||||
|
golangci:
|
||||||
|
name: Lintercheck
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/setup-go@v6
|
||||||
|
with:
|
||||||
|
go-version: 1.24
|
||||||
|
- uses: actions/checkout@v5
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v8
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- go mod tidy
|
|
||||||
|
|
||||||
gitea_urls:
|
|
||||||
api: https://codeberg.org/api/v1
|
|
||||||
download: https://codeberg.org
|
|
||||||
|
|
||||||
builds:
|
|
||||||
- env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
goos:
|
|
||||||
- linux
|
|
||||||
- windows
|
|
||||||
- darwin
|
|
||||||
- freebsd
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- formats: [tar.gz]
|
|
||||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
|
||||||
name_template: >-
|
|
||||||
{{ .ProjectName }}_
|
|
||||||
{{- title .Os }}_
|
|
||||||
{{- if eq .Arch "amd64" }}x86_64
|
|
||||||
{{- else if eq .Arch "386" }}i386
|
|
||||||
{{- else }}{{ .Arch }}{{ end }}
|
|
||||||
{{- if .Arm }}v{{ .Arm }}{{ end }}_{{ .Tag }}
|
|
||||||
# use zip for windows archives
|
|
||||||
format_overrides:
|
|
||||||
- goos: windows
|
|
||||||
formats: [zip]
|
|
||||||
- goos: linux
|
|
||||||
formats: [tar.gz,binary]
|
|
||||||
files:
|
|
||||||
- src: "*.md"
|
|
||||||
strip_parent: true
|
|
||||||
- src: "docs/*"
|
|
||||||
strip_parent: true
|
|
||||||
- src: Makefile.dist
|
|
||||||
dst: Makefile
|
|
||||||
wrap_in_directory: true
|
|
||||||
|
|
||||||
changelog:
|
|
||||||
sort: asc
|
|
||||||
filters:
|
|
||||||
exclude:
|
|
||||||
- "^docs:"
|
|
||||||
- "^test:"
|
|
||||||
groups:
|
|
||||||
- title: Improved
|
|
||||||
regexp: '^.*?(feat|add|new)(\([[:word:]]+\))??!?:.+$'
|
|
||||||
order: 0
|
|
||||||
- title: Fixed
|
|
||||||
regexp: '^.*?(bug|fix)(\([[:word:]]+\))??!?:.+$'
|
|
||||||
order: 1
|
|
||||||
- title: Changed
|
|
||||||
order: 999
|
|
||||||
|
|
||||||
release:
|
|
||||||
header: "# Release Notes"
|
|
||||||
footer: >-
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Full Changelog: [{{ .PreviousTag }}...{{ .Tag }}](https://codeberg.org/scip/epuppy/compare/{{ .PreviousTag }}...{{ .Tag }})
|
|
||||||
@@ -22,6 +22,7 @@ steps:
|
|||||||
event: [push]
|
event: [push]
|
||||||
image: golang:${goversion}
|
image: golang:${goversion}
|
||||||
commands:
|
commands:
|
||||||
|
#- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
|
||||||
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
|
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.5.0
|
||||||
- golangci-lint --version
|
- golangci-lint --version
|
||||||
- golangci-lint run ./...
|
- golangci-lint run ./...
|
||||||
|
|||||||
@@ -4,12 +4,21 @@ labels:
|
|||||||
platform: linux/amd64
|
platform: linux/amd64
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
goreleaser:
|
build:
|
||||||
image: goreleaser/goreleaser
|
|
||||||
when:
|
when:
|
||||||
event: [tag]
|
event: [tag]
|
||||||
environment:
|
image: golang:1.24
|
||||||
GITEA_TOKEN:
|
|
||||||
from_secret: DEPLOY_TOKEN
|
|
||||||
commands:
|
commands:
|
||||||
- goreleaser release --clean --verbose
|
- go get
|
||||||
|
- ./mkrel.sh epuppy v1-${CI_COMMIT_SHA:0:8}
|
||||||
|
#- ./mkrel.sh epuppy ${CI_COMMIT_TAG}
|
||||||
|
|
||||||
|
publish:
|
||||||
|
when:
|
||||||
|
event: [tag]
|
||||||
|
image: woodpeckerci/plugin-release
|
||||||
|
settings:
|
||||||
|
files:
|
||||||
|
- 'releases/epuppy-*-v1-${CI_COMMIT_SHA:0:8}'
|
||||||
|
api_key:
|
||||||
|
from_secret: DEPLOY_TOKEN
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
# -*-make-*-
|
|
||||||
|
|
||||||
.PHONY: install all
|
|
||||||
|
|
||||||
tool = epuppy
|
|
||||||
PREFIX = /usr/local
|
|
||||||
UID = root
|
|
||||||
GID = 0
|
|
||||||
|
|
||||||
all:
|
|
||||||
@echo "Type 'sudo make install' to install the tool."
|
|
||||||
@echo "To change prefix, type 'sudo make install PREFIX=/opt'"
|
|
||||||
|
|
||||||
install:
|
|
||||||
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
|
||||||
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
|
|
||||||
install -d -o $(UID) -g $(GID) $(PREFIX)/share/doc
|
|
||||||
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
|
||||||
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/
|
|
||||||
install -o $(UID) -g $(GID) -m 444 *.md Documentation.txt $(PREFIX)/share/doc/
|
|
||||||
44
README.md
@@ -1,6 +1,6 @@
|
|||||||
[](https://ci.codeberg.org/repos/15473)
|
[](https://ci.codeberg.org/repos/15473)
|
||||||
[](https://codeberg.org/scip/epuppy/raw/branch/main/LICENSE)
|
[](https://github.com/tlinden/epuppy/blob/master/LICENSE)
|
||||||
[](https://goreportcard.com/report/codeberg.org/scip/epuppy)
|
[](https://goreportcard.com/report/github.com/tlinden/epuppy)
|
||||||
|
|
||||||
|
|
||||||
# epuppy - terminal epub reader
|
# epuppy - terminal epub reader
|
||||||
@@ -20,21 +20,17 @@ long run.
|
|||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
### Viewing an ebook in dark mode
|
- Viewing an ebook in dark mode
|
||||||
|

|
||||||
|
|
||||||

|
- Viewing an ebook in light mode
|
||||||
|

|
||||||
|
|
||||||
### Viewing an ebook in light mode
|
- You can interactively adjust text width
|
||||||
|

|
||||||
|
|
||||||

|
- Showing the help
|
||||||
|

|
||||||
### You can interactively adjust text width
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### Showing the help
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@@ -46,7 +42,7 @@ progress.
|
|||||||
Sometimes you may be unhappy with the colors. Depending on your
|
Sometimes you may be unhappy with the colors. Depending on your
|
||||||
terminal style you can enable dark mode with `-D`, light mode is the
|
terminal style you can enable dark mode with `-D`, light mode is the
|
||||||
default. You can also configure custom colors in a config file in
|
default. You can also configure custom colors in a config file in
|
||||||
`$HOME/.config/epuppy/config.toml`:
|
`$HOME/.config/epuppy/confit.toml`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
# color setting for dark mode
|
# color setting for dark mode
|
||||||
@@ -96,16 +92,6 @@ Options:
|
|||||||
-v --version show program version
|
-v --version show program version
|
||||||
```
|
```
|
||||||
|
|
||||||
## Reading mobi files
|
|
||||||
|
|
||||||
`epuppy` doesn't support mobi files, but you can install
|
|
||||||
[mobitool](https://github.com/bfabiszewski/libmobi/) and use it to
|
|
||||||
convert mobi files to epub. The ubuntu package is `libmobi-tools`. To convert, execute:
|
|
||||||
|
|
||||||
```default
|
|
||||||
mobitool -e somebook.epub
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The tool does not have any dependencies. Just download the binary for
|
The tool does not have any dependencies. Just download the binary for
|
||||||
@@ -115,10 +101,10 @@ your platform from the releases page and you're good to go.
|
|||||||
|
|
||||||
You can use [stew](https://github.com/marwanhawari/stew) to install epuppy:
|
You can use [stew](https://github.com/marwanhawari/stew) to install epuppy:
|
||||||
```default
|
```default
|
||||||
stew install https://codeberg.org/scip/epuppy
|
stew install tlinden/epuppy
|
||||||
```
|
```
|
||||||
|
|
||||||
Or go to the [latest release page](https://codeberg.org/scip/epuppy/releases/)
|
Or go to the [latest release page](https://github.com/TLINDEN/epuppy/releases/latest)
|
||||||
and look for your OS and platform. There are two options to install the binary:
|
and look for your OS and platform. There are two options to install the binary:
|
||||||
|
|
||||||
Directly download the binary for your platform,
|
Directly download the binary for your platform,
|
||||||
@@ -158,7 +144,7 @@ sudo make install
|
|||||||
|
|
||||||
# Report bugs
|
# Report bugs
|
||||||
|
|
||||||
[Please open an issue](https://codeberg.org/scip/epuppy/issues). Thanks!
|
[Please open an issue](https://github.com/TLINDEN/epuppy/issues). Thanks!
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
Copyright © 2025-2026 Thomas von Dein
|
Copyright © 2025 Thomas von Dein
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -27,13 +27,12 @@ import (
|
|||||||
"github.com/knadh/koanf/parsers/toml"
|
"github.com/knadh/koanf/parsers/toml"
|
||||||
"github.com/knadh/koanf/providers/file"
|
"github.com/knadh/koanf/providers/file"
|
||||||
"github.com/knadh/koanf/providers/posflag"
|
"github.com/knadh/koanf/providers/posflag"
|
||||||
"github.com/knadh/koanf/providers/structs"
|
|
||||||
"github.com/knadh/koanf/v2"
|
"github.com/knadh/koanf/v2"
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version string = `v0.0.8`
|
Version string = `v0.0.7`
|
||||||
Usage string = `This is epuppy, a terminal ui ebook viewer.
|
Usage string = `This is epuppy, a terminal ui ebook viewer.
|
||||||
|
|
||||||
Usage: epuppy [options] <epub file>
|
Usage: epuppy [options] <epub file>
|
||||||
@@ -43,7 +42,6 @@ Options:
|
|||||||
-s --store-progress remember reading position
|
-s --store-progress remember reading position
|
||||||
-n --line-numbers add line numbers
|
-n --line-numbers add line numbers
|
||||||
-c --config <file> use config <file>
|
-c --config <file> use config <file>
|
||||||
--create-config create a default config file
|
|
||||||
-i --cover-image display cover image
|
-i --cover-image display cover image
|
||||||
-t --txt dump readable content to STDOUT
|
-t --txt dump readable content to STDOUT
|
||||||
-x --xml dump source xml to STDOUT
|
-x --xml dump source xml to STDOUT
|
||||||
@@ -53,31 +51,6 @@ Options:
|
|||||||
-v --version show program version`
|
-v --version show program version`
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
DefaultDark = ColorSetting{
|
|
||||||
Title: "#ff4500",
|
|
||||||
Chapter: "#ff4500",
|
|
||||||
Body: "#cdb79e",
|
|
||||||
}
|
|
||||||
|
|
||||||
DefaultLight = ColorSetting{
|
|
||||||
Title: "#ff0000",
|
|
||||||
Chapter: "#8b0000",
|
|
||||||
Body: "#696969",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// used for config writing, it's a subset of the Config struct
|
|
||||||
// add fields as you add user configurable fields to Config
|
|
||||||
type UserConfig struct {
|
|
||||||
StoreProgress bool `koanf:"store-progress"`
|
|
||||||
Darkmode bool `koanf:"dark"`
|
|
||||||
LineNumbers bool `koanf:"line-numbers"`
|
|
||||||
NoColor bool `koanf:"no-color"`
|
|
||||||
ColorDark ColorSetting `koanf:"colordark"`
|
|
||||||
ColorLight ColorSetting `koanf:"colorlight"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Showversion bool `koanf:"version"` // -v
|
Showversion bool `koanf:"version"` // -v
|
||||||
Debug bool `koanf:"debug"` // -d
|
Debug bool `koanf:"debug"` // -d
|
||||||
@@ -92,14 +65,12 @@ type Config struct {
|
|||||||
ColorLight ColorSetting `koanf:"colorlight"` // comes from config file only
|
ColorLight ColorSetting `koanf:"colorlight"` // comes from config file only
|
||||||
ShowHelp bool `koanf:"help"`
|
ShowHelp bool `koanf:"help"`
|
||||||
ShowCover bool `koanf:"cover-image"` // -i
|
ShowCover bool `koanf:"cover-image"` // -i
|
||||||
CreateConfig bool `koanf:"create-config"` // --create-config
|
|
||||||
Colors Colors // generated from user config file or internal defaults, respects dark mode
|
Colors Colors // generated from user config file or internal defaults, respects dark mode
|
||||||
Document string
|
Document string
|
||||||
InitialProgress int // lines
|
InitialProgress int // lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitConfig(output io.Writer) (*Config, error) {
|
func InitConfig(output io.Writer) (*Config, error) {
|
||||||
conf := &Config{}
|
|
||||||
var kloader = koanf.New(".")
|
var kloader = koanf.New(".")
|
||||||
|
|
||||||
// setup custom usage
|
// setup custom usage
|
||||||
@@ -122,7 +93,6 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
flagset.BoolP("no-color", "N", false, "disable colors")
|
flagset.BoolP("no-color", "N", false, "disable colors")
|
||||||
flagset.BoolP("cover-image", "i", false, "show cover image")
|
flagset.BoolP("cover-image", "i", false, "show cover image")
|
||||||
flagset.BoolP("help", "h", false, "show help")
|
flagset.BoolP("help", "h", false, "show help")
|
||||||
flagset.BoolP("create-config", "", false, "create a config file with default settings")
|
|
||||||
flagset.StringP("config", "c", "", "read config from file")
|
flagset.StringP("config", "c", "", "read config from file")
|
||||||
|
|
||||||
if err := flagset.Parse(os.Args[1:]); err != nil {
|
if err := flagset.Parse(os.Args[1:]); err != nil {
|
||||||
@@ -134,13 +104,14 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
var configfiles []string
|
var configfiles []string
|
||||||
|
|
||||||
configfile, _ := flagset.GetString("config")
|
configfile, _ := flagset.GetString("config")
|
||||||
|
home, _ := os.UserHomeDir()
|
||||||
|
|
||||||
if configfile != "" {
|
if configfile != "" {
|
||||||
configfiles = []string{configfile}
|
configfiles = []string{configfile}
|
||||||
} else {
|
} else {
|
||||||
configfiles = []string{
|
configfiles = []string{
|
||||||
"/etc/epuppy.toml", "/usr/local/etc/epuppy.toml", // unix variants
|
"/etc/epuppy.toml", "/usr/local/etc/epuppy.toml", // unix variants
|
||||||
filepath.Join(conf.GetConfigDir(), "config.toml"),
|
filepath.Join(home, ".config", "epuppy", "config.toml"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +132,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetch values
|
// fetch values
|
||||||
|
conf := &Config{}
|
||||||
if err := kloader.Unmarshal("", &conf); err != nil {
|
if err := kloader.Unmarshal("", &conf); err != nil {
|
||||||
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
return nil, fmt.Errorf("error unmarshalling: %w", err)
|
||||||
}
|
}
|
||||||
@@ -169,7 +141,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
if len(flagset.Args()) > 0 {
|
if len(flagset.Args()) > 0 {
|
||||||
conf.Document = flagset.Args()[0]
|
conf.Document = flagset.Args()[0]
|
||||||
} else {
|
} else {
|
||||||
if !conf.Showversion && !conf.ShowHelp && !conf.CreateConfig {
|
if !conf.Showversion && !conf.ShowHelp {
|
||||||
flagset.Usage()
|
flagset.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@@ -180,7 +152,18 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup color config
|
// setup color config
|
||||||
conf.Colors = SetColorconfig(DefaultDark, DefaultLight, conf)
|
conf.Colors = SetColorconfig(
|
||||||
|
ColorSetting{ // Dark
|
||||||
|
Title: "#ff4500",
|
||||||
|
Chapter: "#ff4500",
|
||||||
|
Body: "#cdb79e",
|
||||||
|
},
|
||||||
|
ColorSetting{ // Light
|
||||||
|
Title: "#ff0000",
|
||||||
|
Chapter: "#8b0000",
|
||||||
|
Body: "#696969",
|
||||||
|
},
|
||||||
|
conf)
|
||||||
|
|
||||||
// disable colors if requested by command line
|
// disable colors if requested by command line
|
||||||
if conf.NoColor {
|
if conf.NoColor {
|
||||||
@@ -190,41 +173,7 @@ func InitConfig(output io.Writer) (*Config, error) {
|
|||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) GetConfigDir() string {
|
func (c *Config) GetConfigDir() string {
|
||||||
home, _ := os.UserHomeDir()
|
home, _ := os.UserHomeDir()
|
||||||
return filepath.Join(home, ".config", "epuppy")
|
return filepath.Join(home, ".config", "epuppy")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) WriteConfigFile() (string, error) {
|
|
||||||
cfgfile := filepath.Join(conf.GetConfigDir(), "config.toml")
|
|
||||||
|
|
||||||
if FileExists(cfgfile) {
|
|
||||||
return "", fmt.Errorf("config file %s already exists", cfgfile)
|
|
||||||
}
|
|
||||||
|
|
||||||
var kloader = koanf.New(".")
|
|
||||||
|
|
||||||
userconf := UserConfig{
|
|
||||||
StoreProgress: conf.StoreProgress,
|
|
||||||
Darkmode: conf.Darkmode,
|
|
||||||
LineNumbers: conf.LineNumbers,
|
|
||||||
NoColor: conf.NoColor,
|
|
||||||
ColorDark: DefaultDark,
|
|
||||||
ColorLight: DefaultLight,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := kloader.Load(structs.Provider(userconf, "koanf"), nil); err != nil {
|
|
||||||
return "", fmt.Errorf("error loading config struct: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
toml, err := kloader.Marshal(toml.Parser())
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error unmarshalling config: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := WriteFile(cfgfile, toml); err != nil {
|
|
||||||
return "", fmt.Errorf("error writing config file %s: %w", cfgfile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("new config file %s created.", cfgfile), nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"codeberg.org/scip/epuppy/pkg/epub"
|
|
||||||
"github.com/alecthomas/repr"
|
"github.com/alecthomas/repr"
|
||||||
|
"github.com/tlinden/epuppy/pkg/epub"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Prepare(conf *Config) (*Ebook, error) {
|
func Prepare(conf *Config) (*Ebook, error) {
|
||||||
|
|||||||
14
cmd/root.go
@@ -52,20 +52,6 @@ func Execute(output io.Writer) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.CreateConfig {
|
|
||||||
msg, err := conf.WriteConfigFile()
|
|
||||||
if err != nil {
|
|
||||||
return Die(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err = fmt.Fprintln(output, msg)
|
|
||||||
if err != nil {
|
|
||||||
return Die(fmt.Errorf("failed to print to output: %s", err))
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if conf.StoreProgress {
|
if conf.StoreProgress {
|
||||||
progress, err := GetProgress(conf)
|
progress, err := GetProgress(conf)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
30
cmd/store.go
@@ -102,37 +102,9 @@ func Mkdir(dir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: check https://github.com/gosimple/slug
|
||||||
func Slug(input string) string {
|
func Slug(input string) string {
|
||||||
slug := slugify.ReplaceAllString(input, "-")
|
slug := slugify.ReplaceAllString(input, "-")
|
||||||
slug = suffix.ReplaceAllString(slug, "")
|
slug = suffix.ReplaceAllString(slug, "")
|
||||||
return nonprintable.ReplaceAllString(slug, "")
|
return nonprintable.ReplaceAllString(slug, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileExists(filename string) bool {
|
|
||||||
info, err := os.Stat(filename)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
// return false on any error
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return !info.IsDir()
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteFile(filename string, content []byte) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
fd, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to open file %s for writing: %w", filename, err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err := fd.Close(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
_, err = fd.Write(content)
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|||||||
4
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module codeberg.org/scip/epuppy
|
module github.com/tlinden/epuppy
|
||||||
|
|
||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
@@ -44,12 +44,10 @@ require (
|
|||||||
github.com/blacktop/go-termimg v0.1.20 // indirect
|
github.com/blacktop/go-termimg v0.1.20 // indirect
|
||||||
github.com/charmbracelet/x/mosaic v0.0.0-20250702191427-5bdfc8f2e4ff // indirect
|
github.com/charmbracelet/x/mosaic v0.0.0-20250702191427-5bdfc8f2e4ff // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||||
github.com/fatih/structs v1.1.0 // indirect
|
|
||||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/knadh/koanf/maps v0.1.2 // indirect
|
github.com/knadh/koanf/maps v0.1.2 // indirect
|
||||||
github.com/knadh/koanf/providers/structs v1.0.0 // indirect
|
|
||||||
github.com/makeworld-the-better-one/dither/v2 v2.4.0 // indirect
|
github.com/makeworld-the-better-one/dither/v2 v2.4.0 // indirect
|
||||||
github.com/mattn/go-sixel v0.0.5 // indirect
|
github.com/mattn/go-sixel v0.0.5 // indirect
|
||||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||||
|
|||||||
4
go.sum
@@ -33,8 +33,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
|
||||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
|
||||||
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k=
|
||||||
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
|
||||||
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs=
|
||||||
@@ -50,8 +48,6 @@ github.com/knadh/koanf/providers/file v1.2.0 h1:hrUJ6Y9YOA49aNu/RSYzOTFlqzXSCpmY
|
|||||||
github.com/knadh/koanf/providers/file v1.2.0/go.mod h1:bp1PM5f83Q+TOUu10J/0ApLBd9uIzg+n9UgthfY+nRA=
|
github.com/knadh/koanf/providers/file v1.2.0/go.mod h1:bp1PM5f83Q+TOUu10J/0ApLBd9uIzg+n9UgthfY+nRA=
|
||||||
github.com/knadh/koanf/providers/posflag v1.0.1 h1:EnMxHSrPkYCFnKgBUl5KBgrjed8gVFrcXDzaW4l/C6Y=
|
github.com/knadh/koanf/providers/posflag v1.0.1 h1:EnMxHSrPkYCFnKgBUl5KBgrjed8gVFrcXDzaW4l/C6Y=
|
||||||
github.com/knadh/koanf/providers/posflag v1.0.1/go.mod h1:3Wn3+YG3f4ljzRyCUgIwH7G0sZ1pMjCOsNBovrbKmAk=
|
github.com/knadh/koanf/providers/posflag v1.0.1/go.mod h1:3Wn3+YG3f4ljzRyCUgIwH7G0sZ1pMjCOsNBovrbKmAk=
|
||||||
github.com/knadh/koanf/providers/structs v1.0.0 h1:DznjB7NQykhqCar2LvNug3MuxEQsZ5KvfgMbio+23u4=
|
|
||||||
github.com/knadh/koanf/providers/structs v1.0.0/go.mod h1:kjo5TFtgpaZORlpoJqcbeLowM2cINodv8kX+oFAeQ1w=
|
|
||||||
github.com/knadh/koanf/v2 v2.3.0 h1:Qg076dDRFHvqnKG97ZEsi9TAg2/nFTa9hCdcSa1lvlM=
|
github.com/knadh/koanf/v2 v2.3.0 h1:Qg076dDRFHvqnKG97ZEsi9TAg2/nFTa9hCdcSa1lvlM=
|
||||||
github.com/knadh/koanf/v2 v2.3.0/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28=
|
github.com/knadh/koanf/v2 v2.3.0/go.mod h1:gRb40VRAbd4iJMYYD5IxZ6hfuopFcXBpc9bbQpZwo28=
|
||||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||||
|
|||||||
2
main.go
@@ -19,7 +19,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"codeberg.org/scip/epuppy/cmd"
|
"github.com/tlinden/epuppy/cmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
75
mkrel.sh
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Copyright © 2025 Thomas von Dein
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
|
# get list with: go tool dist list
|
||||||
|
DIST="darwin/amd64
|
||||||
|
freebsd/amd64
|
||||||
|
linux/amd64
|
||||||
|
netbsd/amd64
|
||||||
|
openbsd/amd64
|
||||||
|
windows/amd64
|
||||||
|
freebsd/arm64
|
||||||
|
linux/arm64
|
||||||
|
netbsd/arm64
|
||||||
|
openbsd/arm64
|
||||||
|
windows/arm64"
|
||||||
|
|
||||||
|
tool="$1"
|
||||||
|
version="$2"
|
||||||
|
|
||||||
|
if test -z "$version"; then
|
||||||
|
echo "Usage: $0 <tool name> <release version>"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf releases
|
||||||
|
mkdir -p releases
|
||||||
|
|
||||||
|
|
||||||
|
for D in $DIST; do
|
||||||
|
os=${D/\/*/}
|
||||||
|
arch=${D/*\//}
|
||||||
|
binfile="releases/${tool}-${os}-${arch}-${version}"
|
||||||
|
|
||||||
|
if test "$os" = "windows"; then
|
||||||
|
binfile="${binfile}.exe"
|
||||||
|
fi
|
||||||
|
|
||||||
|
tardir="${tool}-${os}-${arch}-${version}"
|
||||||
|
tarfile="releases/${tool}-${os}-${arch}-${version}.tar.gz"
|
||||||
|
set -x
|
||||||
|
GOOS=${os} GOARCH=${arch} go build -tags osusergo,netgo -ldflags "-extldflags=-static" -o ${binfile}
|
||||||
|
mkdir -p ${tardir}
|
||||||
|
cp ${binfile} README.md LICENSE ${tardir}/
|
||||||
|
echo 'tool = epuppy
|
||||||
|
PREFIX = /usr/local
|
||||||
|
UID = root
|
||||||
|
GID = 0
|
||||||
|
|
||||||
|
install:
|
||||||
|
install -d -o $(UID) -g $(GID) $(PREFIX)/bin
|
||||||
|
install -d -o $(UID) -g $(GID) $(PREFIX)/man/man1
|
||||||
|
install -o $(UID) -g $(GID) -m 555 $(tool) $(PREFIX)/sbin/
|
||||||
|
install -o $(UID) -g $(GID) -m 444 $(tool).1 $(PREFIX)/man/man1/' > ${tardir}/Makefile
|
||||||
|
tar cpzf ${tarfile} ${tardir}
|
||||||
|
sha256sum ${binfile} | cut -d' ' -f1 > ${binfile}.sha256
|
||||||
|
sha256sum ${tarfile} | cut -d' ' -f1 > ${tarfile}.sha256
|
||||||
|
rm -rf ${tardir}
|
||||||
|
set +x
|
||||||
|
done
|
||||||
|
|
||||||
@@ -8,12 +8,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cleanenTitles = regexp.MustCompile(`&[a-z]+;`)
|
cleanentitles = regexp.MustCompile(`&[a-z]+;`)
|
||||||
isEmpty = regexp.MustCompile(`(?s)^[\s ]*$`)
|
empty = regexp.MustCompile(`(?s)^[\s ]*$`)
|
||||||
cleanNewlines = regexp.MustCompile(`[\r\n\s]+`)
|
newlines = regexp.MustCompile(`[\r\n\s]+`)
|
||||||
cleanSVG = regexp.MustCompile(`(<svg.+</svg>|<!\[CDATA\[.+\]\]>)`)
|
cleansvg = regexp.MustCompile(`(<svg.+</svg>|<!\[CDATA\[.+\]\]>)`)
|
||||||
cleanMarkup = regexp.MustCompile(`<[^<>]+>`)
|
cleanmarkup = regexp.MustCompile(`<[^<>]+>`)
|
||||||
cleanMobiPageBreaks = regexp.MustCompile(`<mbp:pagebreak/>`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Content nav-point content
|
// Content nav-point content
|
||||||
@@ -26,30 +25,15 @@ type Content struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse XML, look for title and <p>.*</p> stuff
|
// parse XML, look for title and <p>.*</p> stuff
|
||||||
func (c *Content) Extract(content []byte) error {
|
func (c *Content) String(content []byte) error {
|
||||||
rawXML := cleanSVG.ReplaceAllString(
|
doc, err := xmlquery.Parse(
|
||||||
cleanenTitles.ReplaceAllString(string(content), " "), "")
|
strings.NewReader(
|
||||||
|
cleansvg.ReplaceAllString(
|
||||||
var doc *xmlquery.Node
|
cleanentitles.ReplaceAllString(string(content), " "), "")))
|
||||||
var err error
|
|
||||||
|
|
||||||
doc, err = xmlquery.Parse(strings.NewReader(rawXML))
|
|
||||||
if err != nil {
|
|
||||||
if strings.Contains(err.Error(), `namespace mbp is missing`) {
|
|
||||||
fixedmbp := strings.NewReader(
|
|
||||||
cleanMobiPageBreaks.ReplaceAllString(
|
|
||||||
rawXML, `<span style="page-break-after: always" />`))
|
|
||||||
|
|
||||||
doc, err = xmlquery.Parse(fixedmbp)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Title == "" {
|
if c.Title == "" {
|
||||||
// extract the title
|
// extract the title
|
||||||
for _, item := range xmlquery.Find(doc, "//title") {
|
for _, item := range xmlquery.Find(doc, "//title") {
|
||||||
@@ -63,9 +47,9 @@ func (c *Content) Extract(content []byte) error {
|
|||||||
txt := strings.Builder{}
|
txt := strings.Builder{}
|
||||||
var have_p bool
|
var have_p bool
|
||||||
for _, item := range xmlquery.Find(doc, "//p") {
|
for _, item := range xmlquery.Find(doc, "//p") {
|
||||||
if !isEmpty.MatchString(item.InnerText()) {
|
if !empty.MatchString(item.InnerText()) {
|
||||||
have_p = true
|
have_p = true
|
||||||
txt.WriteString(cleanNewlines.ReplaceAllString(item.InnerText(), " ") + "\n\n")
|
txt.WriteString(newlines.ReplaceAllString(item.InnerText(), " ") + "\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,9 +57,9 @@ func (c *Content) Extract(content []byte) error {
|
|||||||
// try <div></div>, which some ebooks use, so get all divs,
|
// try <div></div>, which some ebooks use, so get all divs,
|
||||||
// remove markup and paragraphify the parts
|
// remove markup and paragraphify the parts
|
||||||
for _, item := range xmlquery.Find(doc, "//div") {
|
for _, item := range xmlquery.Find(doc, "//div") {
|
||||||
if !isEmpty.MatchString(item.InnerText()) {
|
if !empty.MatchString(item.InnerText()) {
|
||||||
cleaned := cleanMarkup.ReplaceAllString(item.InnerText(), "")
|
cleaned := cleanmarkup.ReplaceAllString(item.InnerText(), "")
|
||||||
txt.WriteString(cleanNewlines.ReplaceAllString(cleaned, " ") + "\n\n")
|
txt.WriteString(newlines.ReplaceAllString(cleaned, " ") + "\n\n")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,8 +112,6 @@ func (bk *Book) getSections() error {
|
|||||||
|
|
||||||
// we have ncx points from the TOC, try those
|
// we have ncx points from the TOC, try those
|
||||||
if len(bk.Ncx.Points) > 0 {
|
if len(bk.Ncx.Points) > 0 {
|
||||||
known := map[string]int{}
|
|
||||||
|
|
||||||
for _, block := range bk.Ncx.Points {
|
for _, block := range bk.Ncx.Points {
|
||||||
sect := Section{
|
sect := Section{
|
||||||
File: "OEBPS/" + block.Content.Src,
|
File: "OEBPS/" + block.Content.Src,
|
||||||
@@ -130,13 +128,7 @@ func (bk *Book) getSections() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, haveFile := known[sect.File]; !haveFile {
|
|
||||||
// sometimes epub's have many sections but they all
|
|
||||||
// point to the same file. To avoid duplicate content
|
|
||||||
// we ignore sections (thus files) we have already seen.
|
|
||||||
sections = append(sections, sect)
|
sections = append(sections, sect)
|
||||||
known[sect.File] = 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(sections) < manifestcount {
|
if len(sections) < manifestcount {
|
||||||
@@ -197,7 +189,7 @@ func (bk *Book) readSectionContent() error {
|
|||||||
ct := Content{Src: section.File, Title: section.Title}
|
ct := Content{Src: section.File, Title: section.Title}
|
||||||
|
|
||||||
if types.MatchString(section.MediaType) {
|
if types.MatchString(section.MediaType) {
|
||||||
if err := ct.Extract(content); err != nil {
|
if err := ct.String(content); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||