forked from Ivasoft/opds-proxy
init
This commit is contained in:
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
||||
module github.com/evan-buss/kobo-opds-proxy
|
||||
|
||||
go 1.22
|
||||
|
||||
require github.com/opds-community/libopds2-go v0.0.0-20170628075933-9c163cf60f6e // indirect
|
||||
2
go.sum
Normal file
2
go.sum
Normal file
@@ -0,0 +1,2 @@
|
||||
github.com/opds-community/libopds2-go v0.0.0-20170628075933-9c163cf60f6e h1:kjurmIVxVypqhb5CUAG9jLhYL1TLsUE47KfoEm7cdlE=
|
||||
github.com/opds-community/libopds2-go v0.0.0-20170628075933-9c163cf60f6e/go.mod h1:U/OpXIq9O6FgLfzvun31PZt8iIlbG93BieaxjOEIAd0=
|
||||
11
html/feed.html
Normal file
11
html/feed.html
Normal file
@@ -0,0 +1,11 @@
|
||||
{{define "content"}}
|
||||
{{range .Feed.Links}}
|
||||
{{template "link" .}}
|
||||
<a href="{{.Href}}">{{.Title}}</a>
|
||||
{{end}}
|
||||
|
||||
{{range .Feed.Entries}}
|
||||
{{$link := index .Links 0}}
|
||||
<a href="{{$link.Href}}">{{.Title}}</a>
|
||||
{{end}}
|
||||
{{end}}
|
||||
27
html/html.go
Normal file
27
html/html.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package html
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io"
|
||||
"github.com/opds-community/libopds2-go/opds1"
|
||||
)
|
||||
|
||||
var (
|
||||
feed = parse("feed.html")
|
||||
)
|
||||
|
||||
func parse(file string) *template.Template {
|
||||
return template.Must(template.New("layout.html").ParseFiles("html/layout.html", "html/" + file))
|
||||
}
|
||||
|
||||
type FeedParams struct {
|
||||
Feed *opds1.Feed
|
||||
}
|
||||
|
||||
func Feed(w io.Writer, p FeedParams, partial string) error {
|
||||
if (partial == "" ) {
|
||||
partial = "layout.html"
|
||||
}
|
||||
|
||||
return feed.ExecuteTemplate(w, partial, p)
|
||||
}
|
||||
11
html/layout.html
Normal file
11
html/layout.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>{{block "title" .}}Kobo OPDS Proxy{{end}}</title>
|
||||
<link rel="stylesheet" href="./static/style.css">
|
||||
</head>
|
||||
<body>
|
||||
{{block "content" .}}{{end}}
|
||||
</body>
|
||||
</html>
|
||||
39
main.go
Normal file
39
main.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"github.com/opds-community/libopds2-go/opds1"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"github.com/evan-buss/kobo-opds-proxy/html"
|
||||
)
|
||||
|
||||
func main() {
|
||||
router := http.NewServeMux()
|
||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
feed := parseFeed()
|
||||
html.Feed(w, html.FeedParams{feed}, "")
|
||||
})
|
||||
|
||||
router.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.ServeFile(w, r, r.URL.Path[1:])
|
||||
})
|
||||
|
||||
log.Panic(http.ListenAndServe(":8080", router))
|
||||
}
|
||||
|
||||
func parseFeed() *opds1.Feed {
|
||||
var feed opds1.Feed
|
||||
|
||||
bytes, err := os.ReadFile("/home/evan/Downloads/opds.atom")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = xml.Unmarshal(bytes, &feed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &feed
|
||||
}
|
||||
20
static/style.css
Normal file
20
static/style.css
Normal file
@@ -0,0 +1,20 @@
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
|
||||
font-family: sans-serif;
|
||||
line-height: 1.6;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: start;
|
||||
flex-flow: column nowrap;
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
}
|
||||
Reference in New Issue
Block a user