Compare commits
2 Commits
2ca44b60d4
...
f536b16e17
Author | SHA1 | Date | |
---|---|---|---|
|
f536b16e17 | ||
|
0d420f70d8 |
@ -126,6 +126,7 @@ func main() {
|
||||
gmiParams.Logger = logger.WithNamespace("gmi")
|
||||
gmiParams.PostStore = postStore
|
||||
gmiParams.PostAssetStore = postAssetStore
|
||||
gmiParams.HTTPPublicURL = httpParams.PublicURL
|
||||
|
||||
logger.Info(ctx, "starting gmi api")
|
||||
gmiAPI, err := gmi.New(gmiParams)
|
||||
|
@ -30,6 +30,8 @@ type Params struct {
|
||||
PublicURL *url.URL
|
||||
ListenAddr string
|
||||
CertificatesPath string
|
||||
|
||||
HTTPPublicURL *url.URL
|
||||
}
|
||||
|
||||
// SetupCfg implement the cfg.Cfger interface.
|
||||
|
@ -7,7 +7,9 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"mime"
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -35,6 +37,7 @@ type rendererGetPostSeriesNextPreviousRes struct {
|
||||
type renderer struct {
|
||||
url *url.URL
|
||||
postStore post.Store
|
||||
httpPublicURL *url.URL
|
||||
}
|
||||
|
||||
func (r renderer) GetPosts(page, count int) (rendererGetPostsRes, error) {
|
||||
@ -98,7 +101,9 @@ func (r renderer) PostBody(p post.StoredPost) (string, error) {
|
||||
return filepath.Join("/posts", id)
|
||||
},
|
||||
StaticURL: func(path string) string {
|
||||
return filepath.Join("/static", path)
|
||||
httpPublicURL := *r.httpPublicURL
|
||||
httpPublicURL.Path = filepath.Join(httpPublicURL.Path, "/static", path)
|
||||
return httpPublicURL.String()
|
||||
},
|
||||
Image: func(args ...string) (string, error) {
|
||||
|
||||
@ -191,10 +196,12 @@ func (a *api) tplHandler() (gemini.Handler, error) {
|
||||
) {
|
||||
|
||||
tplPath := strings.TrimPrefix(r.URL.Path, "/")
|
||||
mimeType := mime.TypeByExtension(path.Ext(r.URL.Path))
|
||||
|
||||
ctx = mctx.Annotate(ctx,
|
||||
"url", r.URL,
|
||||
"tplPath", tplPath,
|
||||
"mimeType", mimeType,
|
||||
)
|
||||
|
||||
tpl := allTpls.Lookup(tplPath)
|
||||
@ -204,11 +211,16 @@ func (a *api) tplHandler() (gemini.Handler, error) {
|
||||
return
|
||||
}
|
||||
|
||||
if mimeType != "" {
|
||||
rw.SetMediaType(mimeType)
|
||||
}
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
err := tpl.Execute(buf, renderer{
|
||||
url: r.URL,
|
||||
postStore: a.params.PostStore,
|
||||
httpPublicURL: a.params.HTTPPublicURL,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
14
src/gmi/tpl/wtfpl.txt
Normal file
14
src/gmi/tpl/wtfpl.txt
Normal file
@ -0,0 +1,14 @@
|
||||
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