Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
liber
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
liber
Commits
45e7bfb0
Commit
45e7bfb0
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
look for OPF metadata with alternative filenames
parent
f1e244e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
opf.go
+12
-13
12 additions, 13 deletions
opf.go
with
12 additions
and
13 deletions
opf.go
+
12
−
13
View file @
45e7bfb0
...
...
@@ -2,6 +2,7 @@ package liber
import
(
"encoding/xml"
"errors"
"io"
"os"
"path/filepath"
...
...
@@ -75,29 +76,27 @@ func opfOpen(path string) (*Metadata, error) {
return
opfParse
(
file
)
}
func
opfMetadataPath
(
epubPath
string
)
string
{
return
filepath
.
Join
(
filepath
.
Dir
(
epubPath
),
"metadata.opf"
)
}
func
opfCoverPath
(
epubPath
string
)
string
{
return
filepath
.
Join
(
filepath
.
Dir
(
epubPath
),
"cover.jpg"
)
func
replaceExt
(
path
,
ext
string
)
string
{
return
strings
.
TrimSuffix
(
path
,
filepath
.
Ext
(
path
))
+
ext
}
type
opfProvider
struct
{}
func
(
p
*
opfProvider
)
Lookup
(
storage
*
FileStorage
,
path
,
filetype
string
)
(
*
Metadata
,
error
)
{
if
!
storage
.
Exists
(
opfMetadataPath
(
path
))
{
return
nil
,
nil
paths
:=
[]
string
{
filepath
.
Join
(
filepath
.
Dir
(
path
),
"metadata.opf"
),
replaceExt
(
path
,
".opf"
),
}
m
,
err
:=
opfOpen
(
opfMetadataPath
(
storage
.
Abs
(
path
)))
if
err
!=
nil
{
return
nil
,
err
for
_
,
opfpath
:=
range
paths
{
if
m
,
err
:=
opfOpen
(
storage
.
Abs
(
opfpath
));
err
==
nil
{
return
m
,
err
}
}
return
m
,
err
return
nil
,
err
ors
.
New
(
"no OPF metadata found"
)
}
func
(
p
*
opfProvider
)
GetBookCover
(
storage
*
FileStorage
,
path
string
)
(
string
,
error
)
{
coverPath
:=
opfCoverPath
(
path
)
coverPath
:=
filepath
.
Join
(
filepath
.
Dir
(
path
),
"cover.jpg"
)
if
storage
.
Exists
(
coverPath
)
{
return
coverPath
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment