Skip to content

Commit a673fe6

Browse files
committed
add username to top menu
1 parent d27bd20 commit a673fe6

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

compactbro.exe

12.5 MB
Binary file not shown.

compactbro.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@ import (
77
"net/http"
88
"os"
99
"path/filepath"
10-
"github.com/BurntSushi/toml"
11-
"github.com/kirsle/configdir"
1210
"strings"
1311
"time"
12+
13+
"github.com/BurntSushi/toml"
1414
"github.com/eknkc/amber"
15+
"github.com/kirsle/configdir"
1516
"github.com/labstack/echo/v4"
1617
"github.com/labstack/echo/v4/middleware"
1718
"github.com/rdtmaster/go-reddit/v4/reddit"
1819
)
1920

2021
const emptyHTML = template.HTML("")
22+
2123
var (
2224
config CompactConfig
2325
server *echo.Echo
24-
tpls map[string]*template.Template
26+
tpls map[string]*template.Template
2527
client *reddit.Client
2628
)
2729

@@ -72,6 +74,7 @@ func main() {
7274
amber.FuncMap["strNotEmpty"] = strNotEmpty
7375
amber.FuncMap["hasReplies"] = hasReplies
7476
amber.FuncMap["processReplies"] = processReplies
77+
amber.FuncMap["getMe"] = getMe
7578
tpls, err = amber.CompileDir("templates",
7679
amber.DirOptions{Ext: ".amber", Recursive: true},
7780
config.TemplateOptions)
@@ -143,4 +146,4 @@ func main() {
143146
}
144147
}
145148

146-
}
149+
}

templates/header.amber

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ html[xmlns="http://www.w3.org/1999/xhtml"][lang="en"]
3636
[href="/message/all/"]
3737
a#topmenu_toggle.topbar-options[href="#"]
3838
div#top_menu.hidden
39+
div.menuitem
40+
a[href="/u/"+getMe()]#{getMe()}
3941
div.menuitem
4042
a[href="/stop/"] Stop
4143

user.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package main
22

33
import (
4-
"github.com/rdtmaster/go-reddit/v4/reddit"
5-
"fmt"
4+
"net/http"
65
"sort"
6+
"strings"
77
"time"
8-
"net/http"
8+
99
"github.com/labstack/echo/v4"
10-
"strings"
10+
"github.com/rdtmaster/go-reddit/v4/reddit"
1111
)
1212

13+
func getMe() string {
14+
return config.Credentials.Username
15+
}
16+
1317
// This function must be reworked or retested, hard to believe it actually works
1418
func getOverview(c echo.Context, username, after, page, sorting, tpl string) error {
1519

@@ -35,7 +39,6 @@ func getOverview(c echo.Context, username, after, page, sorting, tpl string) err
3539
if err != nil {
3640
return c.String(http.StatusInternalServerError, err.Error())
3741
}
38-
fmt.Println("==== after", after)
3942
a := make([]PostOrComment, len(posts)+len(comments))
4043
i := 0
4144
for _, post := range posts {

0 commit comments

Comments
 (0)