Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced epub.js by foliate-js #86

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A personal documents server, Coreander indexes the documents (EPUBs and PDFs wit
* Web interface available in english, spanish and french, more languages can be easily added.
* New documents added or removed to/from the library folder are automatically indexed (Linux only).
* [Send to email supported](#send-to-email).
* Read indexed epubs and PDFs from Coreander's interface thanks to [epub.js](http://futurepress.org/) and [pdf.js](https://mozilla.github.io/pdf.js/).
* Read indexed epubs and PDFs from Coreander's interface thanks to [foliate-js](https://github.com/johnfactotum/foliate-js).
* Restrictable access only to registered users.
* Upload documents through the web interface.

Expand Down
2 changes: 1 addition & 1 deletion internal/metadata/epub.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func words(documentFullPath string) (int, error) {

func extractCover(r *zip.ReadCloser, coverFile string, coverMaxWidth int) ([]byte, error) {
for _, f := range r.File {
if f.Name != fmt.Sprintf("OEBPS/%s", coverFile) && f.Name != fmt.Sprintf("OPS/%s", coverFile) {
if f.Name != fmt.Sprintf("OEBPS/%s", coverFile) && f.Name != fmt.Sprintf("OPS/%s", coverFile) && f.Name != coverFile {
continue
}
rc, err := f.Open()
Expand Down
5 changes: 1 addition & 4 deletions internal/webserver/controller/document/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ func (d *Controller) Reader(c *fiber.Ctx) error {
return fiber.ErrNotFound
}

template := "epub-reader"
if strings.ToLower(filepath.Ext(document.ID)) == ".pdf" {
template = "pdf-reader"
}
template := "reader"

title := fmt.Sprintf("%s | Coreander", document.Title)
authors := strings.Join(document.Authors, ", ")
Expand Down
233 changes: 233 additions & 0 deletions internal/webserver/embedded/css/reader.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
:root {
--active-bg: rgba(0, 0, 0, .05);
}
@supports (color-scheme: light dark) {
@media (prefers-color-scheme: dark) {
:root {
--active-bg: rgba(255, 255, 255, .1);
}
}
}
html {
height: 100%;
}
body {
margin: 0 auto;
height: 100%;
font: menu;
font-family: system-ui, sans-serif;
}
#spinner-container {
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
.icon {
display: block;
fill: none;
stroke: currentcolor;
stroke-width: 2px;
}
.empty-state-icon {
margin: auto;
}
.toolbar {
box-sizing: border-box;
position: absolute;
z-index: 1;
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
height: 48px;
padding: 6px;
transition: opacity 250ms ease;
visibility: hidden;
}
.toolbar button {
padding: 3px;
border-radius: 6px;
background: none;
border: 0;
color: GrayText;
}
.toolbar button:hover {
background: rgba(0, 0, 0, .1);
color: currentcolor;
}
#header-bar {
top: 0;
}
#nav-bar {
bottom: 0;
}
#progress-slider {
flex-grow: 1;
margin: 0 12px;
visibility: hidden;
}
#side-bar {
visibility: hidden;
box-sizing: border-box;
position: absolute;
z-index: 2;
top: 0;
left: 0;
height: 100%;
width: 320px;
transform: translateX(-320px);
display: flex;
flex-direction: column;
background: Canvas;
color: CanvasText;
box-shadow: 0 0 0 1px rgba(0, 0, 0, .2), 0 0 40px rgba(0, 0, 0, .2);
transition: visibility 0s linear 300ms, transform 300ms ease;
}
#side-bar.show {
visibility: visible;
transform: translateX(0);
transition-delay: 0s;
}
#dimming-overlay {
visibility: hidden;
position: fixed;
z-index: 2;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, .2);
opacity: 0;
transition: visibility 0s linear 300ms, opacity 300ms ease;
}
#dimming-overlay.show {
visibility: visible;
opacity: 1;
transition-delay: 0s;
}
#side-bar-header {
padding: 1rem;
display: flex;
border-bottom: 1px solid rgba(0, 0, 0, .1);
align-items: center;
}
#side-bar-cover {
height: 10vh;
min-height: 60px;
max-height: 180px;
border-radius: 3px;
border: 0;
background: lightgray;
box-shadow: 0 0 1px rgba(0, 0, 0, .1), 0 0 16px rgba(0, 0, 0, .1);
margin-inline-end: 1rem;
}
#side-bar-cover:not([src]) {
display: none;
}
#side-bar-title {
margin: .5rem 0;
font-size: inherit;
}
#side-bar-author {
margin: .5rem 0;
font-size: small;
color: GrayText;
}
#toc-view {
padding: .5rem;
overflow-y: scroll;
}
#toc-view li, #toc-view ol {
margin: 0;
padding: 0;
list-style: none;
}
#toc-view a, #toc-view span {
display: block;
border-radius: 6px;
padding: 8px;
margin: 2px 0;
}
#side-bar a {
color: CanvasText;
text-decoration: none;
}
#toc-view a:hover {
background: var(--active-bg);
}
#toc-view span {
color: GrayText;
}
#toc-view svg {
margin-inline-start: -24px;
padding-inline-start: 5px;
padding-inline-end: 6px;
fill: CanvasText;
cursor: default;
transition: transform .2s ease;
opacity: .5;
}
#toc-view svg:hover {
opacity: 1;
}
#toc-view [aria-current] {
font-weight: bold;
background: var(--active-bg);
}
#toc-view [aria-expanded="false"] svg {
transform: rotate(-90deg);
}
#toc-view [aria-expanded="false"] + [role="group"] {
display: none;
}
.menu-container {
position: relative;
}
.menu, .menu ul {
list-style: none;
padding: 0;
margin: 0;
}
.menu {
visibility: hidden;
position: absolute;
right: 0;
background: Canvas;
color: CanvasText;
border-radius: 6px;
box-shadow: 0 0 0 1px rgba(0, 0, 0, .2), 0 0 16px rgba(0, 0, 0, .1);
padding: 6px;
cursor: default;
}
.menu.show {
visibility: visible;
}
.menu li {
padding: 6px 12px;
padding-left: 24px;
border-radius: 6px;
}
.menu li:hover {
background: var(--active-bg);
}
.menu li[aria-checked="true"] {
background-position: center left;
background-repeat: no-repeat;
background-image: url('data:image/svg+xml;utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224%22%20height%3D%2224%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%223%22%2F%3E%3C%2Fsvg%3E');
}
.popover {
background: Canvas;
color: CanvasText;
border-radius: 6px;
box-shadow: 0 0 0 1px rgba(0, 0, 0, .2), 0 0 16px rgba(0, 0, 0, .1), 0 0 32px rgba(0, 0, 0, .1);
}
.popover-arrow-down {
fill: Canvas;
filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, .2));
}
.popover-arrow-up {
fill: Canvas;
filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .2));
}
1 change: 0 additions & 1 deletion internal/webserver/embedded/js/epub.min.js

This file was deleted.

21 changes: 21 additions & 0 deletions internal/webserver/embedded/js/foliate-js/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 John Factotum

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading