[PR #623] [MERGED] Initial Ebook support #702

Closed
opened 2026-02-25 23:35:11 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-shiori/shiori/pull/623
Author: @Monirzadeh
Created: 6/22/2023
Status: Merged
Merged: 7/9/2023
Merged by: @fmartingr

Base: masterHead: epub


📝 Commits (10+)

  • f17a548 generate ebook
  • 7bf7ca3 serve ebook file
  • 5eb3b9b Update ebook.go not download same image twice anymore
  • 675a641 download ebook request api/ui part
  • f97cce4 fix typo
  • 069a0b2 add stylesheet
  • 033066a update hasEbook status
  • 6ca0731 download link update after ebook generate
  • b2b9986 download ebook with bookmark title
  • f0192f5 Apply suggestions from code review for better error handling

📊 Changes

11 files changed (+829 additions, -5 deletions)

View changed files

internal/core/ebook.go (+252 -0)
internal/core/ebook_test.go (+288 -0)
📝 internal/core/processing.go (+17 -0)
📝 internal/model/model.go (+2 -0)
📝 internal/view/content.html (+3 -0)
📝 internal/view/js/component/bookmark.js (+20 -1)
📝 internal/view/js/page/base.js (+2 -1)
📝 internal/view/js/page/home.js (+68 -2)
📝 internal/webserver/handler-api.go (+107 -1)
📝 internal/webserver/handler-ui.go (+68 -0)
📝 internal/webserver/server.go (+2 -0)

📄 Description

Hi @fmartingr
as we talk in #605 it is a not complete code. Please keep it as draft until meet all needs.
I write UI/API part too, but because I don't know you prefer of how to handle ebook status.

What it's done:

  • generate an EPUB file from a readable version of bookmark.
  • EPUB generation done without any external library. (i prefer less dependency as possible)
  • it can serve EPUB file if file exist. (/bookmark/id/ebook)
  • not download image twice if image url duplicate in bookmark
  • add a generate ebook api
  • add style for nice view.
  • hasEbook define, and page update based on hasEbook.
  • download ebook with bookmark title
  • move to update archive.
  • use io instead of io/outil for move to higher version of go
  • add missing error handling while try to write inside a file
  • update archive regenerate ebook if it exists
  • Error 404 in Api instead of panic
  • if delete a bookmark, it will remove ebook too
  • add link to bookmark content page. Icon not add to bookmark gride like archive etc. because we have book icon for fast download and don't like make first page unneeded element.
  • remove language and id until find good solution for them. If we can find a good solution for to summarize bookmark content, we can use that for description tag too.
  • if it is PDF, not generate ebook.
  • better CSS for ebook. I pick up CSS from here with very small change. I think it should be tested in long term to determine embedded CSS is good enough or not. Thanks @poire-z. @poire-z if you don't like we use this CSS here https://github.com/go-shiori/shiori/pull/623/commits/519e10d6cebe24206ce72d6f843c37a8d4ac1915, please comment me.
  • remove panic in all API that this PR. Just one still exist that I can't replace
  • change function name to GenerateEbook
  • not isFatalErr anymore - do we need to remove isFatalErr in other part of code like ProcessBookmark too?
  • add unit test for GenerateEbook 68% coverage. These parts don't have unit test yet

Maybe in future not plan on this PR

  • add cover to ebook
  • add language tag based on book content (maybe use an external library for that) we can use lingua-go, but somehow it overkills. Or use go-readability tag.
  • delete action. not yet until find good solution in ui.
  • return PDF in ebook download action to eink device. (is useful if eink device can handel pdf). when start working on eink device
  • summarize bookmark content, and use that for description tag.
  • Include font in ebook as font publisher. Why not do that here? It can be complicated for now because of different font for each language.
  • ebook generate by default in settings. I need more time to understand how settings work in Shiori.

Discussion here: https://github.com/go-shiori/shiori/discussions/605


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-shiori/shiori/pull/623 **Author:** [@Monirzadeh](https://github.com/Monirzadeh) **Created:** 6/22/2023 **Status:** ✅ Merged **Merged:** 7/9/2023 **Merged by:** [@fmartingr](https://github.com/fmartingr) **Base:** `master` ← **Head:** `epub` --- ### 📝 Commits (10+) - [`f17a548`](https://github.com/go-shiori/shiori/commit/f17a548ecb15da10810d75b5f2eff32185bb1f1c) generate ebook - [`7bf7ca3`](https://github.com/go-shiori/shiori/commit/7bf7ca3e4a07c409231778f245bb2cab0833b463) serve ebook file - [`5eb3b9b`](https://github.com/go-shiori/shiori/commit/5eb3b9bd98ac9c158caa55d90f196334fd8ffa44) Update ebook.go not download same image twice anymore - [`675a641`](https://github.com/go-shiori/shiori/commit/675a641905f6c425b350cacedeaf9a7915c54153) download ebook request api/ui part - [`f97cce4`](https://github.com/go-shiori/shiori/commit/f97cce44c72433233e949ced7af9b7d54940ad2a) fix typo - [`069a0b2`](https://github.com/go-shiori/shiori/commit/069a0b2368de353b246fe62e03e50096aa1b0061) add stylesheet - [`033066a`](https://github.com/go-shiori/shiori/commit/033066a5f67ef035a9b1315b9cb1c4a07cfe5989) update hasEbook status - [`6ca0731`](https://github.com/go-shiori/shiori/commit/6ca0731298220fcfb8f92aefa49d1c992d9751d7) download link update after ebook generate - [`b2b9986`](https://github.com/go-shiori/shiori/commit/b2b9986520b8db51b8220339485f5c6184ec8f8b) download ebook with bookmark title - [`f0192f5`](https://github.com/go-shiori/shiori/commit/f0192f51fca69d1689dad71d142f78cd90283eec) Apply suggestions from code review for better error handling ### 📊 Changes **11 files changed** (+829 additions, -5 deletions) <details> <summary>View changed files</summary> ➕ `internal/core/ebook.go` (+252 -0) ➕ `internal/core/ebook_test.go` (+288 -0) 📝 `internal/core/processing.go` (+17 -0) 📝 `internal/model/model.go` (+2 -0) 📝 `internal/view/content.html` (+3 -0) 📝 `internal/view/js/component/bookmark.js` (+20 -1) 📝 `internal/view/js/page/base.js` (+2 -1) 📝 `internal/view/js/page/home.js` (+68 -2) 📝 `internal/webserver/handler-api.go` (+107 -1) 📝 `internal/webserver/handler-ui.go` (+68 -0) 📝 `internal/webserver/server.go` (+2 -0) </details> ### 📄 Description Hi @fmartingr as we talk in #605 it is a not complete code. Please keep it as draft until meet all needs. I write UI/API part too, but because I don't know you prefer of how to handle ebook status. ## What it's done: - [x] generate an EPUB file from a readable version of bookmark. - [x] EPUB generation done without any external library. (i prefer less dependency as possible) - [x] it can serve EPUB file if file exist. (/bookmark/id/ebook) - [x] not download image twice if image url duplicate in bookmark - [x] add a generate ebook api - [x] add style for nice view. - [x] `hasEbook` define, and page update based on `hasEbook`. - [x] download ebook with bookmark title - [x] move to update archive. - [x] use `io` instead of `io/outil` for move to higher version of go - [x] add missing error handling while try to write inside a file - [x] update archive regenerate ebook if it exists - [x] Error 404 in Api instead of panic - [x] if delete a bookmark, it will remove ebook too - [x] add link to bookmark content page. Icon not add to bookmark gride like archive etc. because we have book icon for fast download and don't like make first page unneeded element. - [x] remove `language` and `id` until find good solution for them. If we can find a good solution for to summarize bookmark content, we can use that for `description` tag too. - [x] if it is PDF, not generate ebook. - [x] better CSS for ebook. I pick up CSS from [here](https://github.com/poire-z/crengine/blob/2b7a96c2778291d2b136abbff60715a5aa0e0925/cr3gui/data/epub.css) with very small change. I think it should be tested in long term to determine embedded CSS is good enough or not. Thanks @poire-z. @poire-z if you don't like we use this CSS here https://github.com/go-shiori/shiori/pull/623/commits/519e10d6cebe24206ce72d6f843c37a8d4ac1915, please comment me. - [x] remove panic in all API that this PR. ~~Just one still exist that I can't replace~~ - [x] change function name to `GenerateEbook` - [x] [not isFatalErr anymore](https://github.com/go-shiori/shiori/pull/623/commits/eac045ef2378492ea4f967cca04343bb9071a293) - do we need to remove `isFatalErr` in other part of code like `ProcessBookmark` too? - [x] add unit test for `GenerateEbook` 68% coverage. [These parts](https://github.com/go-shiori/shiori/pull/623#discussion_r1257323458) don't have unit test yet ## Maybe in future not plan on this PR - add cover to ebook - add language tag based on book content (maybe use an external library for that) we can use [lingua-go](https://github.com/pemistahl/lingua-go), but somehow it overkills. Or use [go-readability](https://github.com/go-shiori/go-readability) tag. - delete action. not yet until find good solution in ui. - return PDF in ebook download action to eink device. (is useful if eink device can handel pdf). when start working on eink device - summarize bookmark content, and use that for `description` tag. - Include font in ebook as font publisher. Why not do that here? It can be complicated for now because of different font for each language. - ebook generate by default in settings. I need more time to understand how settings work in Shiori. Discussion here: https://github.com/go-shiori/shiori/discussions/605 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-25 23:35:11 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shiori#702
No description provided.