EpubPostProcessor 0.0.1

dotnet tool install --global EpubPostProcessor --version 0.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local EpubPostProcessor --version 0.0.1
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=EpubPostProcessor&version=0.0.1
                    
nuke :add-package EpubPostProcessor --version 0.0.1
                    

EPUB post-processor

A .NET 8 command-line tool that turns a publisher-generated EPUB (for example, from Leanpub) into multiple storefront editions, rewriting links according to YAML configuration files. The original EPUB is never modified.

Installation

Install with the .NET 8 SDK (the tool targets the .NET 8 runtime):

dotnet tool install --global EpubPostProcessor

Update an existing installation:

dotnet tool update --global EpubPostProcessor

When working from a source checkout, you can instead use dotnet run --project src/EpubPostProcessor -- in place of epub-post-processor in the examples below.

Batch usage

epub-post-processor rewrite \
  --source path-to-derinkuyu.epub \
  --output-directory ./dist \
  --config amazon.yaml kobo.yaml apple-books.yaml

Directories are also accepted. This generates every storefront edition from the immediate .yaml and .yml files in the directory:

epub-post-processor rewrite \
  --source path-to-derinkuyu.epub \
  --output-directory ./dist \
  --config ./storefronts

You can mix directories and individual files in the same invocation, or supply multiple directories. For example, --config ./storefronts special-release.yaml processes every YAML file from ./storefronts followed by special-release.yaml. Directory discovery is non-recursive and uses case-insensitive extensions; non-YAML files and subdirectories are ignored. Files found in each directory are processed alphabetically by filename. Empty directories (with no matching YAML files) fail, rather than silently producing nothing. Explicit file paths still work regardless of extension. Duplicate output targets, including a file listed both directly and through a directory, are rejected as before.

You can also repeat --config instead of supplying multiple paths after one option:

epub-post-processor rewrite \
  -s path-to-derinkuyu.epub -o ./dist \
  -c amazon.yaml -c kobo.yaml -c apple-books.yaml

The output directory is created if necessary. Each configuration produces one output named <story>-<store>.epub, for example:

dist/
  path-to-derinkuyu-amazon.epub
  path-to-derinkuyu-kobo.epub
  path-to-derinkuyu-apple-books.epub

A single configuration works identically to a batch of several; the previous --output single-file CLI has been removed.

Configuration

An amazon.yaml file might contain:

story: Path to Derinkuyu
store: amazon
rewrite:
  links:
    - match: '^https://leanpub\.com/no-direction/?$'
      replacement: 'https://www.amazon.com/dp/YOUR_ASIN'
      expected: 2
    - match: '^https://example\.com/books/(.+)$'
      replacement: 'https://www.amazon.com/$1'

A kobo.yaml file for the same EPUB would have the same story and use store: kobo with its own replacements.

Both story and store are required. They identify the book and storefront and determine the output filename. Spaces are converted to hyphens and names are lowercase in filenames; other than spaces and hyphens, only ASCII letters and digits are accepted. All configurations in a batch must name the same story, since they process one source EPUB. Two configurations producing the same destination name are rejected.

The rewrite: section remains extensible for future transformation types (such as ISBN or metadata rewrites); unknown top-level and rewrite categories are currently ignored. Unknown fields inside a link rule fail validation.

Each match is a .NET regular expression applied to the decoded href value of an XHTML anchor. replacement supports .NET replacement groups such as $1. expected is optional: absent means at least one link must match, present means exactly that number of matches must occur. Two rules may not match the same link.

Other options

  • --dry-run: validate all configurations and display match totals without writing an EPUB or creating the output directory.
  • --verbose: display each matched link and its replacement, grouped by output.
  • --force: overwrite existing output EPUBs; without it, existing files cause an error.
  • --help: display full command-line help.
  • Short aliases: -s (--source), -o (--output-directory), -c (--config). --output-dir is another alias for --output-directory.

The processor validates every configuration and all regex match counts before publishing any edition. EPUBs are staged in temporary files in the destination directory before being committed. During commit, existing EPUBs are backed up and restored if a later commit fails. Invalid configurations, missing links, and malformed XHTML do not cause partial batches to be published.

Only XHTML/HTML anchors' href attributes are rewritten; other ZIP entries retain their original uncompressed bytes. XHTML may be reserialized. The mimetype entry remains first and uncompressed as required by EPUB packaging rules.

Tests

dotnet test tests/EpubPostProcessor.Tests/EpubPostProcessor.Tests.csproj

Integration tests generate and process real EPUB ZIP files on disk, including EPUB metadata, container files, XHTML with nested formatting and escaped URL attributes, and binary image assets. No mocks are used. GitHub Actions runs the tests on every PR and also packs, installs, and smoke-tests the tool from the locally produced NuGet package.

Releasing (maintainers)

Releases are published to NuGet.org by GitHub Actions when a stable semantic version tag (vMAJOR.MINOR.PATCH) is pushed. Tag a tested commit on master, for example:

git switch master
git pull --ff-only
git tag v1.0.0
git push origin v1.0.0

The workflow uses the tag (without the v) as the package version, runs tests, packs and smoke-tests the package, and publishes that exact artifact. Ordinary branch builds and PRs never publish. NuGet versions cannot be overwritten; choose a new version for each release.

One-time Trusted Publishing setup:

  1. In GitHub repository settings, create an Actions environment named nuget. Consider restricting its deployment tags to v*.
  2. In Settings > Secrets and variables > Actions > Variables, create the repository variable NUGET_USER with the NuGet.org profile username (not the email address).
  3. In NuGet.org, open your account's Trusted Publishing settings and add a GitHub policy for the package EpubPostProcessor. Use repository owner MaxGuernseyIII, repository epub-post-processor, workflow file build.yml, and environment nuget. Allow publishing new packages for the first release and new versions for later releases. Scope the policy to this package ID.
  4. Push the first release tag while the policy is active. For private repositories, NuGet may require a successful first publish within seven days to permanently activate the policy; the activation window can be restarted if it expires.

No long-lived NuGet API key is required. See NuGet Trusted Publishing.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.0.1 75 11/26/2026