Skip to content

Commit

Permalink
rework pagination (#79)
Browse files Browse the repository at this point in the history
* rework pagination

* fix "no messages found" message in post display

* simplify retrieving archived threads

* allow logging discord REST requests
  • Loading branch information
samhza authored Nov 24, 2022
1 parent 40fb063 commit 913815e
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 532 deletions.
360 changes: 210 additions & 150 deletions discord.go

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,35 @@ import (
"os/signal"
"time"

_ "net/http/pprof"

"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
"github.com/diamondburned/arikawa/v3/utils/httputil/httpdriver"
"github.com/naoina/toml"
)

//go:embed resources
var embedfs embed.FS

type config struct {
BotToken string
ListenAddr string
Resources string
SiteURL string
ServiceName string
ServerHostedIn string
ReloadTemplates bool
BotToken string
ListenAddr string
Resources string
SiteURL string
ServiceName string
ServerHostedIn string
ReloadTemplates bool
TraceDiscordREST bool
}

type TraceClient struct {
httpdriver.Client
}

func (c TraceClient) Do(req httpdriver.Request) (httpdriver.Response, error) {
then := time.Now()
resp, err := c.Client.Do(req)
log.Printf("Discord REST: %s in %s", req.GetPath(), time.Since(then))
return resp, err
}

func main() {
Expand Down Expand Up @@ -81,6 +92,9 @@ func main() {
defer done()

state := state.New("Bot " + config.BotToken)
if config.TraceDiscordREST {
state.Client.Client.Client = TraceClient{state.Client.Client.Client}
}
state.AddIntents(0 |
gateway.IntentGuildMessages |
gateway.IntentGuilds |
Expand All @@ -104,8 +118,8 @@ func main() {
httpserver := &http.Server{
Addr: config.ListenAddr,
Handler: server,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
httperr := make(chan error, 1)
Expand Down
2 changes: 1 addition & 1 deletion resources/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ nav .tags select {
color:#111;
}

.nav_buttons {
.more {
display:block;
position: relative;
height: 3em;
Expand Down
21 changes: 16 additions & 5 deletions resources/templates/forum.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
<option value="">All</option>
{{range .Forum.AvailableTags}}
{{$selected := false}}
{{if eq .ID $.TagFilter}}
{{$selected = true}}
{{end}}

<option value="{{.ID}}" {{if $selected}}selected{{end}}>{{.Name}}</option>
{{end}}
Expand All @@ -30,7 +27,14 @@
</form>
</nav>

{{ template "navbuttons" . }}
<div class="more">
{{if .Prev}}
<a class="prevbtn btn" href="/{{.Guild.ID}}/{{.Forum.ID}}/page/{{.Prev}}">Previous</a><br>
{{end}}
{{if .Next}}
<a class="nextbtn btn" href="/{{.Guild.ID}}/{{.Forum.ID}}/page/{{.Next}}">Next</a><br>
{{end}}
</div>

<div class='tabular-list post-list'>
<div class='header'>Title</div>
Expand Down Expand Up @@ -71,6 +75,13 @@

</div>

{{ template "navbuttons" . }}
<div class="more">
{{if .Prev}}
<a class="prevbtn btn" href="/{{.Guild.ID}}/{{.Forum.ID}}/page/{{.Prev}}">Previous</a><br>
{{end}}
{{if .Next}}
<a class="nextbtn btn" href="/{{.Guild.ID}}/{{.Forum.ID}}/page/{{.Next}}">Next</a><br>
{{end}}
</div>

{{ template "footer.gohtml" .}}
5 changes: 2 additions & 3 deletions resources/templates/index.gohtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{{ template "header.gohtml" }}
<title>dforum</title>
<meta name="description" content="A service for making discord forums indexable by google.">
<span class='top'>
<h1><a href="/">dforum</a></h1>
</span>

<h1><a href="/">dforum</a></h1>

<p>this website will display the forums in any server you invite the corresponding bot to in a such a way that Google and other search engines can index and show them. we hope to host as many servers as we can so that we can usher in a new era of online forums, without locking this information behind a service that you have to sign up for (which also has a less then adequate search feature).</p>
<p>the site is also (hopefully) simple enough that you can print the contents of it to another site, and thus if you want your own url for this stuff you can simply include the site from your own site, via whatever language you plan on using.</p>
Expand Down
18 changes: 0 additions & 18 deletions resources/templates/nav.gohtml

This file was deleted.

26 changes: 13 additions & 13 deletions resources/templates/post.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{{$image = $firstPost.Author.AvatarURL}}
{{end}}
{{else}}
<em>wind blowing noises</em><br><em>some dipshit deleted the top post in their thread and not the thread itself...how sad...</em>
<em>No messages found</em>
{{end}}

<title>{{$title}}</title>
Expand All @@ -37,14 +37,14 @@
<meta property="og:url" content="{{.URL}}/{{.Guild.ID}}/{{.Forum.ID}}/{{.Post.ID}}">
<meta property="og:image" content="{{$image}}">

<span class='nav_buttons'>
{{if .PrevID }}
<a class="prevbtn btn" href="?cur=d{{.PrevID}}">Previous</a><br>
<div class='more'>
{{if .Prev }}
<a class="prevbtn btn" href="?before={{.Prev}}">Previous</a><br>
{{end}}
{{if .NextID }}
<a class="nextbtn btn" href="?cur=a{{.NextID}}">Next</a><br>
{{if .Next }}
<a class="nextbtn btn" href="?after={{.Next}}">Next</a><br>
{{end}}
</span>
</div>

<div>
{{range .MessageGroups}}
Expand Down Expand Up @@ -99,12 +99,12 @@
</div>
{{end}}
</div>
<span class='nav_buttons'>
{{if .PrevID }}
<a class="prevbtn btn" href="?cur=d{{.PrevID}}">Previous</a><br>
<div class='more'>
{{if .Prev }}
<a class="prevbtn btn" href="?before={{.Prev}}">Previous</a><br>
{{end}}
{{if .NextID }}
<a class="nextbtn btn" href="?cur=a{{.NextID}}">Next</a><br>
{{if .Next }}
<a class="nextbtn btn" href="?after={{.Next}}">Next</a><br>
{{end}}
</span>
{{ template "footer.gohtml" .}}
{{ template "footer.gohtml" .}}
Loading

0 comments on commit 913815e

Please sign in to comment.