Compare commits
No commits in common. "f536b16e170a5efb5b3bdd720e48100d5d0f83ba" and "2ca44b60d4cdbd6158604b5c25f80a9139f8c716" have entirely different histories.
f536b16e17
...
2ca44b60d4
@ -126,7 +126,6 @@ func main() {
|
|||||||
gmiParams.Logger = logger.WithNamespace("gmi")
|
gmiParams.Logger = logger.WithNamespace("gmi")
|
||||||
gmiParams.PostStore = postStore
|
gmiParams.PostStore = postStore
|
||||||
gmiParams.PostAssetStore = postAssetStore
|
gmiParams.PostAssetStore = postAssetStore
|
||||||
gmiParams.HTTPPublicURL = httpParams.PublicURL
|
|
||||||
|
|
||||||
logger.Info(ctx, "starting gmi api")
|
logger.Info(ctx, "starting gmi api")
|
||||||
gmiAPI, err := gmi.New(gmiParams)
|
gmiAPI, err := gmi.New(gmiParams)
|
||||||
|
@ -30,8 +30,6 @@ type Params struct {
|
|||||||
PublicURL *url.URL
|
PublicURL *url.URL
|
||||||
ListenAddr string
|
ListenAddr string
|
||||||
CertificatesPath string
|
CertificatesPath string
|
||||||
|
|
||||||
HTTPPublicURL *url.URL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupCfg implement the cfg.Cfger interface.
|
// SetupCfg implement the cfg.Cfger interface.
|
||||||
|
@ -7,9 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"mime"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -35,9 +33,8 @@ type rendererGetPostSeriesNextPreviousRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type renderer struct {
|
type renderer struct {
|
||||||
url *url.URL
|
url *url.URL
|
||||||
postStore post.Store
|
postStore post.Store
|
||||||
httpPublicURL *url.URL
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r renderer) GetPosts(page, count int) (rendererGetPostsRes, error) {
|
func (r renderer) GetPosts(page, count int) (rendererGetPostsRes, error) {
|
||||||
@ -101,9 +98,7 @@ func (r renderer) PostBody(p post.StoredPost) (string, error) {
|
|||||||
return filepath.Join("/posts", id)
|
return filepath.Join("/posts", id)
|
||||||
},
|
},
|
||||||
StaticURL: func(path string) string {
|
StaticURL: func(path string) string {
|
||||||
httpPublicURL := *r.httpPublicURL
|
return filepath.Join("/static", path)
|
||||||
httpPublicURL.Path = filepath.Join(httpPublicURL.Path, "/static", path)
|
|
||||||
return httpPublicURL.String()
|
|
||||||
},
|
},
|
||||||
Image: func(args ...string) (string, error) {
|
Image: func(args ...string) (string, error) {
|
||||||
|
|
||||||
@ -196,12 +191,10 @@ func (a *api) tplHandler() (gemini.Handler, error) {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
tplPath := strings.TrimPrefix(r.URL.Path, "/")
|
tplPath := strings.TrimPrefix(r.URL.Path, "/")
|
||||||
mimeType := mime.TypeByExtension(path.Ext(r.URL.Path))
|
|
||||||
|
|
||||||
ctx = mctx.Annotate(ctx,
|
ctx = mctx.Annotate(ctx,
|
||||||
"url", r.URL,
|
"url", r.URL,
|
||||||
"tplPath", tplPath,
|
"tplPath", tplPath,
|
||||||
"mimeType", mimeType,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
tpl := allTpls.Lookup(tplPath)
|
tpl := allTpls.Lookup(tplPath)
|
||||||
@ -211,16 +204,11 @@ func (a *api) tplHandler() (gemini.Handler, error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if mimeType != "" {
|
|
||||||
rw.SetMediaType(mimeType)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
err := tpl.Execute(buf, renderer{
|
err := tpl.Execute(buf, renderer{
|
||||||
url: r.URL,
|
url: r.URL,
|
||||||
postStore: a.params.PostStore,
|
postStore: a.params.PostStore,
|
||||||
httpPublicURL: a.params.HTTPPublicURL,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
||||||
Version 2, December 2004
|
|
||||||
|
|
||||||
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
|
||||||
|
|
||||||
Everyone is permitted to copy and distribute verbatim or modified
|
|
||||||
copies of this license document, and changing it is allowed as long
|
|
||||||
as the name is changed.
|
|
||||||
|
|
||||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user