Merge pull request #426 from mostfunkyduck/develop
Fixes problem where all links were breaking in gopher
This commit is contained in:
commit
23818c6104
1 changed files with 10 additions and 0 deletions
10
gopher.go
10
gopher.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/prologic/go-gopher"
|
"github.com/prologic/go-gopher"
|
||||||
|
@ -28,6 +29,11 @@ func initGopher(apper Apper) {
|
||||||
gopher.ListenAndServe(fmt.Sprintf(":%d", apper.App().Config().Server.GopherPort), nil)
|
gopher.ListenAndServe(fmt.Sprintf(":%d", apper.App().Config().Server.GopherPort), nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
||||||
|
func stripHostProtocol(app *App) string {
|
||||||
|
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
|
||||||
|
}
|
||||||
|
|
||||||
func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
|
func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
|
||||||
parts := strings.Split(r.Selector, "/")
|
parts := strings.Split(r.Selector, "/")
|
||||||
if app.cfg.App.SingleUser {
|
if app.cfg.App.SingleUser {
|
||||||
|
@ -51,6 +57,8 @@ func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
|
||||||
|
|
||||||
for _, c := range *colls {
|
for _, c := range *colls {
|
||||||
w.WriteItem(&gopher.Item{
|
w.WriteItem(&gopher.Item{
|
||||||
|
Host: stripHostProtocol(app),
|
||||||
|
Port: app.cfg.Server.GopherPort,
|
||||||
Type: gopher.DIRECTORY,
|
Type: gopher.DIRECTORY,
|
||||||
Description: c.DisplayTitle(),
|
Description: c.DisplayTitle(),
|
||||||
Selector: "/" + c.Alias + "/",
|
Selector: "/" + c.Alias + "/",
|
||||||
|
@ -99,6 +107,8 @@ func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request
|
||||||
|
|
||||||
for _, p := range *posts {
|
for _, p := range *posts {
|
||||||
w.WriteItem(&gopher.Item{
|
w.WriteItem(&gopher.Item{
|
||||||
|
Port: app.cfg.Server.GopherPort,
|
||||||
|
Host: stripHostProtocol(app),
|
||||||
Type: gopher.FILE,
|
Type: gopher.FILE,
|
||||||
Description: p.CreatedDate() + " - " + p.DisplayTitle(),
|
Description: p.CreatedDate() + " - " + p.DisplayTitle(),
|
||||||
Selector: baseSel + p.Slug.String,
|
Selector: baseSel + p.Slug.String,
|
||||||
|
|
Loading…
Add table
Reference in a new issue