From 506be822134c51300ab589256ad66a7e7eac3ae1 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 8 Mar 2026 16:17:23 +0300 Subject: Add EPUB descriptions to OPF files --- src/epub.rs | 4 +++- src/models.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/epub.rs b/src/epub.rs index 4f31784..62e7c8d 100644 --- a/src/epub.rs +++ b/src/epub.rs @@ -1,6 +1,6 @@ use crate::{ models::{Chapter, EpubResponse, FileEntry}, - xml::build_epub_chapter, + xml::{build_epub_chapter, write_modified_opf}, }; use anyhow::{Context, Result}; use ogrim::xml; @@ -122,6 +122,8 @@ pub fn create_epub_archive( &url_path_to_local, &mut zip, )?; + } else if entry.ourn == opf_entry.ourn { + write_modified_opf(buf_reader, &mut zip, &epub_data.descriptions.plain)?; } else { copy(&mut buf_reader, &mut zip)?; } diff --git a/src/models.rs b/src/models.rs index 991224c..5f92d03 100644 --- a/src/models.rs +++ b/src/models.rs @@ -14,6 +14,7 @@ pub struct Paginated { pub struct EpubResponse { pub publication_date: String, pub title: String, + pub descriptions: Descriptions, pub chapters: String, // This is a URL to the chapters list pub files: String, // This is a URL to the resource files pub spine: String, // This is a URL to the spine list @@ -21,6 +22,13 @@ pub struct EpubResponse { pub language: String, } +/// Sub-model of EpubResponse - descriptions. +#[derive(Debug, Deserialize)] +pub struct Descriptions { + #[serde(rename = "text/plain")] + pub plain: String, +} + /// Model for chapters API. #[derive(Debug, Deserialize)] pub struct Chapter { -- cgit v1.2.3-70-g09d2