mirror of
https://github.com/writeas/writefreely
synced 2025-02-01 04:46:47 +01:00
Merge pull request #458 from writefreely/improve-gopher
Fix Gopher links and add blog info
This commit is contained in:
commit
a7c4a318f3
11
gopher.go
11
gopher.go
@ -14,6 +14,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -31,8 +32,13 @@ func initGopher(apper Apper) {
|
|||||||
|
|
||||||
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
// Utility function to strip the URL from the hostname provided by app.cfg.App.Host
|
||||||
func stripHostProtocol(app *App) string {
|
func stripHostProtocol(app *App) string {
|
||||||
|
u, err := url.Parse(app.cfg.App.Host)
|
||||||
|
if err != nil {
|
||||||
|
// Fall back to host, with scheme stripped
|
||||||
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
|
return string(regexp.MustCompile("^.*://").ReplaceAll([]byte(app.cfg.App.Host), []byte("")))
|
||||||
}
|
}
|
||||||
|
return u.Hostname()
|
||||||
|
}
|
||||||
|
|
||||||
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, "/")
|
||||||
@ -100,6 +106,11 @@ func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request
|
|||||||
}
|
}
|
||||||
c.hostName = app.cfg.App.Host
|
c.hostName = app.cfg.App.Host
|
||||||
|
|
||||||
|
w.WriteInfo(c.DisplayTitle())
|
||||||
|
if c.Description != "" {
|
||||||
|
w.WriteInfo(c.Description)
|
||||||
|
}
|
||||||
|
|
||||||
posts, err := app.db.GetPosts(app.cfg, c, 0, false, false, false)
|
posts, err := app.db.GetPosts(app.cfg, c, 0, false, false, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user