Skip to content

Commit e10c19d

Browse files
committedFeb 20, 2025·
Add version info to marshalled WebPub metadata
1 parent a89c47e commit e10c19d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
 

‎pkg/manifest/metadata.go

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manifest
22

33
import (
44
"encoding/json"
5+
"runtime/debug"
56
"strings"
67
"time"
78

@@ -452,6 +453,11 @@ func (m *Metadata) UnmarshalJSON(b []byte) error {
452453
return nil
453454
}
454455

456+
// If you really don't want the version info in your manifest, you can blank this value.
457+
var ToolkitVersionKey = "https://github.com/readium/go-toolkit/releases"
458+
459+
const toolkitRepo = "github.com/readium/go-toolkit"
460+
455461
func (m Metadata) MarshalJSON() ([]byte, error) {
456462
j := make(map[string]interface{})
457463
if m.OtherMetadata != nil {
@@ -460,6 +466,22 @@ func (m Metadata) MarshalJSON() ([]byte, error) {
460466
}
461467
}
462468

469+
if ToolkitVersionKey != "" {
470+
if info, ok := debug.ReadBuildInfo(); ok {
471+
if info.Main.Path == toolkitRepo {
472+
// This is the toolkit itself
473+
j[ToolkitVersionKey] = info.Main.Version
474+
} else {
475+
// This is a module that uses the toolkit
476+
for _, dep := range info.Deps {
477+
if dep.Path == toolkitRepo {
478+
j[ToolkitVersionKey] = dep.Version
479+
}
480+
}
481+
}
482+
}
483+
}
484+
463485
if m.Presentation != nil {
464486
j["presentation"] = m.Presentation
465487
}

0 commit comments

Comments
 (0)
Please sign in to comment.