diff --git a/main.go b/main.go
index a11fc21..cdd4cdc 100644
--- a/main.go
+++ b/main.go
@@ -7,9 +7,7 @@ import (
"log"
"net"
"net/http"
- "os"
- "github.com/gorilla/sessions"
"github.com/julienschmidt/httprouter"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/extension"
@@ -19,7 +17,6 @@ var watch = flag.Bool("w", false, "watch for file changes")
var addr = flag.String("addr", ":80", "http service address")
var md goldmark.Markdown
var templates map[string]*template.Template
-var store = sessions.NewCookieStore([]byte(os.Getenv("SESSIONSECRET")))
type AddHeaderTransport struct {
T http.RoundTripper
@@ -54,7 +51,7 @@ func init() {
md = goldmark.New(goldmark.WithExtensions(extension.Linkify))
templates = make(map[string]*template.Template)
if !*watch {
- for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html"} {
+ for _, name := range []string{"index.html", "login.html", "frontpage.html", "root.html", "settings.html"} {
t := template.New(name).Funcs(funcMap)
glob, err := t.ParseGlob("templates/*")
if err != nil {
@@ -81,36 +78,7 @@ func middleware(n httprouter.Handle) httprouter.Handle {
func main() {
flag.Parse()
log.Println("serve", *addr)
- router := httprouter.New()
- router.ServeFiles("/:host/static/*filepath", http.Dir("public"))
- router.GET("/", GetRoot)
- router.POST("/", PostRoot)
- router.GET("/:host/", middleware(GetFrontpage))
- router.GET("/:host/search", middleware(Search))
- router.POST("/:host/search", middleware(UserOp))
- router.GET("/:host/inbox", middleware(Inbox))
- router.GET("/:host/login", middleware(GetLogin))
- router.POST("/:host/login", middleware(SignUpOrLogin))
- router.POST("/:host/", middleware(UserOp))
- router.GET("/:host/icon.jpg", middleware(GetIcon))
- router.GET("/:host/c/:community", middleware(GetFrontpage))
- router.POST("/:host/c/:community", middleware(UserOp))
- router.GET("/:host/c/:community/search", middleware(Search))
- router.GET("/:host/post/:postid", middleware(GetPost))
- router.POST("/:host/post/:postid", middleware(UserOp))
- router.GET("/:host/comment/:commentid", middleware(GetComment))
- router.GET("/:host/comment/:commentid/:op", middleware(GetComment))
- router.POST("/:host/comment/:commentid", middleware(UserOp))
- router.GET("/:host/u/:username", middleware(GetUser))
- router.GET("/:host/u/:username/message", middleware(GetMessageForm))
- router.POST("/:host/u/:username/message", middleware(SendMessage))
- router.POST("/:host/u/:username", middleware(UserOp))
- router.GET("/:host/u/:username/search", middleware(Search))
- router.GET("/:host/create_post", middleware(GetCreatePost))
- router.POST("/:host/create_post", middleware(UserOp))
- router.GET("/:host/create_community", middleware(GetCreateCommunity))
- router.POST("/:host/create_community", middleware(UserOp))
-
+ router := GetRouter()
err := http.ListenAndServe(*addr, router)
if err != nil {
log.Fatal("ListenAndServe: ", err)
diff --git a/routes.go b/routes.go
index 3198353..af4575b 100644
--- a/routes.go
+++ b/routes.go
@@ -11,6 +11,7 @@ import (
"io"
"net/http"
"net/url"
+ "os"
"regexp"
"strconv"
"strings"
@@ -24,6 +25,12 @@ import (
)
var funcMap = template.FuncMap{
+ "host": func(host string) string {
+ if l := os.Getenv("LEMMY_DOMAIN"); l != "" {
+ return l
+ }
+ return host
+ },
"proxy": func(s string) string {
u, err := url.Parse(s)
if err != nil {
@@ -68,7 +75,7 @@ var funcMap = template.FuncMap{
}
return false
},
- "host": func(p Post) string {
+ "domain": func(p Post) string {
if p.Post.URL.IsValid() {
l, err := url.Parse(p.Post.URL.String())
if err != nil {
@@ -111,8 +118,10 @@ var funcMap = template.FuncMap{
}
converted := buf.String()
converted = strings.Replace(converted, ` 0 {
-// state.GetComment()
-// state.GetPost()
-// state.GetCommunity()
-// return
-// }
-//
-// if state.UserName != "" {
-// state.GetUser()
-// return
-// }
-//
-// if state.PostID == 0 {
-// state.GetPosts()
-// } else {
-// state.GetPost()
-// state.GetComments()
-// }
-//
-// if state.CommunityName != "" {
-// state.GetCommunity()
-// }
-//
-//}
-
func (state *State) LemmyError(domain string) error {
var nodeInfo NodeInfo
res, err := state.HTTPClient.Get("https://" + domain + "/nodeinfo/2.0.json")
@@ -255,6 +220,9 @@ func (state *State) GetSite() {
}
func (state *State) GetComment(commentid int) {
+ if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
+ state.Sort = "Hot"
+ }
state.CommentID = commentid
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
ParentID: types.NewOptional(state.CommentID),
@@ -284,6 +252,9 @@ func (state *State) GetComment(commentid int) {
}
}
func (state *State) GetComments() {
+ if state.Sort != "Hot" && state.Sort != "Top" && state.Sort != "Old" && state.Sort != "New" {
+ state.Sort = "Hot"
+ }
cresp, err := state.Client.Comments(context.Background(), types.GetComments{
PostID: types.NewOptional(state.PostID),
Sort: types.NewOptional(types.CommentSortType(state.Sort)),
@@ -293,6 +264,7 @@ func (state *State) GetComments() {
})
if err != nil {
state.Status = http.StatusInternalServerError
+ fmt.Println(err)
return
}
state.CommentCount = len(cresp.Comments)
diff --git a/templates/comment.html b/templates/comment.html
index f646bb4..604d4db 100644
--- a/templates/comment.html
+++ b/templates/comment.html
@@ -1,8 +1,8 @@
This is your home
-When you find a community that you like, click the join button
-Click here to find communities or check out what's popular
-{{ else if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }} +{{ if or (and (not .Op) (not .Activities) (not .Comments) (not .Posts) (not .Communities)) (and (not .Comments) .PostID) (and (not .Activities) (not .Query) .User) }}