From 15e716c09740ab9ff49f5ea395730f6f1a589064 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Mon, 3 May 2021 17:45:17 -0500 Subject: [PATCH] Get the main content of forum category index working --- public/style.css | 3 ++ src/rawdata/scss/_forum.scss | 4 ++ src/templates/src/forum_category.html | 13 +++++++ src/templates/src/include/header.html | 16 ++++---- .../src/include/thread_list_item.html | 4 +- src/templates/src/layouts/base.html | 10 +++++ src/templates/src/project.css | 4 ++ src/templates/templates.go | 7 ---- src/templates/types.go | 2 + src/website/forums.go | 38 ++++++++++++++++--- src/website/requesthandling.go | 2 +- src/website/routes.go | 29 +++++++++++--- 12 files changed, 103 insertions(+), 29 deletions(-) diff --git a/public/style.css b/public/style.css index 323a3f6f..fd4862c5 100644 --- a/public/style.css +++ b/public/style.css @@ -8574,6 +8574,9 @@ input[type=submit] { background-color: #f0f0f0; background-color: var(--forum-even-background); } +.thread-list-item .latestpost { + width: 16.5rem; } + .thread { color: black; color: var(--fg-font-color); } diff --git a/src/rawdata/scss/_forum.scss b/src/rawdata/scss/_forum.scss index 1f82ab6b..84fb3075 100644 --- a/src/rawdata/scss/_forum.scss +++ b/src/rawdata/scss/_forum.scss @@ -21,6 +21,10 @@ @include usevar('background-color', 'forum-even-background'); } +.thread-list-item .latestpost { + width: 16.5rem; +} + .thread { @include usevar('color', 'fg-font-color'); diff --git a/src/templates/src/forum_category.html b/src/templates/src/forum_category.html index d658e02c..5921b407 100644 --- a/src/templates/src/forum_category.html +++ b/src/templates/src/forum_category.html @@ -2,6 +2,19 @@ {{ define "content" }}
+
+
+ {{ if .User }} + + New Thread + Mark threads here as read + {{ else }} + Log in to post a new thread + {{ end }} +
+
+ {{ template "pagination.html" .Pagination }} +
+
{{ range .Threads }} {{ template "thread_list_item.html" . }} {{ end }} diff --git a/src/templates/src/include/header.html b/src/templates/src/include/header.html index fb111f5d..0e31e9b0 100644 --- a/src/templates/src/include/header.html +++ b/src/templates/src/include/header.html @@ -9,9 +9,9 @@ Logout {{ else }} Register - +
-
+ {{/* TODO: CSRF */}} @@ -38,24 +38,24 @@
{{ if not .Project.IsHMN }} - {{ end }} {{ if .Project.HasBlog }} - Blog + Blog {{ end }} {{ if .Project.HasForum }} - Forums + Forums {{ end }} {{ if .Project.HasWiki }} - Wiki + Wiki {{ end }} {{ if .Project.HasLibrary }} - Library + Library {{ end }} {{ if .Project.IsHMN }} - Mission + Mission {{ end }} {{/* {% if project.default_annotation_category %} */}} {{ if false }} diff --git a/src/templates/src/include/thread_list_item.html b/src/templates/src/include/thread_list_item.html index 801a1298..df05fe9f 100644 --- a/src/templates/src/include/thread_list_item.html +++ b/src/templates/src/include/thread_list_item.html @@ -4,7 +4,7 @@ This template is intended to display a single thread in the context of a forum, It should be called with ThreadListItem. */}} -
+
{{ end }}
-
+
Last post {{ relativedate .LastDate }}
diff --git a/src/templates/src/layouts/base.html b/src/templates/src/layouts/base.html index a36fe930..1cd00302 100644 --- a/src/templates/src/layouts/base.html +++ b/src/templates/src/layouts/base.html @@ -63,6 +63,16 @@
{{ template "header.html" . }} + {{ with .Breadcrumbs }} +
+ {{ range $i, $e := . -}} + {{- if gt $i 0 -}} + » + {{- end -}} + {{ .Name }} + {{- end }} +
+ {{ end }} {{ block "content" . }}{{ end }} {{ template "footer.html" . }}
diff --git a/src/templates/src/project.css b/src/templates/src/project.css index e61c8167..aabf49cf 100644 --- a/src/templates/src/project.css +++ b/src/templates/src/project.css @@ -42,6 +42,10 @@ a:hover, button:hover, .button:hover, input[type=button]:hover, input[type=submi border: 2px solid var(--link-color); } +.post-list-bg-odd:nth-of-type(odd) { + background-color: {{ .PostListBgColor }}; +} + /* TODO: Manually apply sensible tachyons classes to the elements styled below, then delete all of this CSS. diff --git a/src/templates/templates.go b/src/templates/templates.go index 7dc1683b..543f8295 100644 --- a/src/templates/templates.go +++ b/src/templates/templates.go @@ -80,13 +80,6 @@ var HMNTemplateFuncs = template.FuncMap{ "color2css": func(color noire.Color) template.CSS { return template.CSS(color.HTML()) }, - "currentprojecturl": func(url string) string { - return hmnurl.Url(url, nil) // TODO: Use project subdomain - }, - "currentprojecturlq": func(url string, query string) string { - absUrl := hmnurl.Url(url, nil) - return fmt.Sprintf("%s?%s", absUrl, query) // TODO: Use project subdomain - }, "darken": func(amount float64, color noire.Color) noire.Color { return color.Shade(amount) }, diff --git a/src/templates/types.go b/src/templates/types.go index 65c20da1..ce8e6eb2 100644 --- a/src/templates/types.go +++ b/src/templates/types.go @@ -9,6 +9,7 @@ type BaseData struct { BackgroundImage BackgroundImage Theme string BodyClasses []string + Breadcrumbs []Breadcrumb Project Project User *User @@ -110,6 +111,7 @@ type ThreadListItem struct { type Breadcrumb struct { Name, Url string + Current bool } type Pagination struct { diff --git a/src/website/forums.go b/src/website/forums.go index 26a2956f..00430087 100644 --- a/src/website/forums.go +++ b/src/website/forums.go @@ -2,12 +2,14 @@ package website import ( "context" + "fmt" "math" "net/http" "strconv" "strings" "time" + "git.handmade.network/hmn/hmn/src/hmnurl" "git.handmade.network/hmn/hmn/src/templates" "github.com/jackc/pgx/v4/pgxpool" @@ -20,7 +22,9 @@ import ( type forumCategoryData struct { templates.BaseData - Threads []templates.ThreadListItem + CategoryUrl string + Threads []templates.ThreadListItem + Pagination templates.Pagination } func ForumCategory(c *RequestContext) ResponseData { @@ -162,13 +166,37 @@ func ForumCategory(c *RequestContext) ResponseData { //_ = itSubcats // TODO: Actually query subcategory post data baseData := getBaseData(c) - baseData.Title = "yeet" + baseData.Title = *c.CurrentProject.Name + " Forums" + baseData.Breadcrumbs = []templates.Breadcrumb{ + { + Name: *c.CurrentProject.Name, + Url: hmnurl.ProjectUrl("/", nil, c.CurrentProject.Subdomain()), + }, + { + Name: "Forums", + Url: categoryUrls[currentCatId], + Current: true, + }, + } var res ResponseData - res.WriteTemplate("forum_category.html", forumCategoryData{ - BaseData: baseData, - Threads: threads, + err = res.WriteTemplate("forum_category.html", forumCategoryData{ + BaseData: baseData, + CategoryUrl: categoryUrls[currentCatId], + Threads: threads, + Pagination: templates.Pagination{ + Current: page, + Total: numPages, + + FirstUrl: categoryUrls[currentCatId], + LastUrl: fmt.Sprintf("%s/%d", categoryUrls[currentCatId], numPages), + NextUrl: fmt.Sprintf("%s/%d", categoryUrls[currentCatId], page+1), + PreviousUrl: fmt.Sprintf("%s/%d", categoryUrls[currentCatId], page-1), + }, }, c.Perf) + if err != nil { + panic(err) + } return res } diff --git a/src/website/requesthandling.go b/src/website/requesthandling.go index 845fe05f..6575329d 100644 --- a/src/website/requesthandling.go +++ b/src/website/requesthandling.go @@ -64,7 +64,7 @@ func (rb *RouteBuilder) GET(regexStr string, h Handler) { } func (rb *RouteBuilder) POST(regexStr string, h Handler) { - rb.Handle(http.MethodGet, regexStr, h) + rb.Handle(http.MethodPost, regexStr, h) } func (rb *RouteBuilder) StdHandler(regexStr string, h http.Handler) { diff --git a/src/website/routes.go b/src/website/routes.go index 83ce7dd7..cf5b84da 100644 --- a/src/website/routes.go +++ b/src/website/routes.go @@ -17,6 +17,7 @@ import ( "git.handmade.network/hmn/hmn/src/perf" "git.handmade.network/hmn/hmn/src/templates" "github.com/jackc/pgx/v4/pgxpool" + "github.com/teacat/noire" ) func NewWebsiteRoutes(conn *pgxpool.Pool, perfCollector *perf.PerfCollector) http.Handler { @@ -72,7 +73,7 @@ func NewWebsiteRoutes(conn *pgxpool.Pool, perfCollector *perf.PerfCollector) htt }) mainRoutes.GET(`^/feed(/(?P.+)?)?$`, Feed) - mainRoutes.GET(`^/(?Pforums(/.+?)*)$`, ForumCategory) + mainRoutes.GET(`^/(?Pforums(/[a-zA-Z]+?)*)(/(?P\d+))?$`, ForumCategory) // mainRoutes.GET(`^/(?Pforums(/cat)*)/t/(?P\d+)/p/(?P\d+)$`, ForumPost) mainRoutes.GET("^/assets/project.css$", ProjectCSS) @@ -96,7 +97,7 @@ func getBaseData(c *RequestContext) templates.BaseData { return templates.BaseData{ Project: templates.ProjectToTemplate(c.CurrentProject), User: templateUser, - Theme: "dark", + Theme: "light", } } @@ -128,12 +129,28 @@ func ProjectCSS(c *RequestContext) ResponseData { return ErrorResponse(http.StatusBadRequest, NewSafeError(nil, "You must provide a 'color' parameter.\n")) } + baseData := getBaseData(c) + + bgColor := noire.NewHex(color) + h, s, l := bgColor.HSL() + if baseData.Theme == "dark" { + l = 15 + } else { + l = 95 + } + if s > 20 { + s = 20 + } + bgColor = noire.NewHSL(h, s, l) + templateData := struct { - Color string - Theme string + templates.BaseData + Color string + PostListBgColor string }{ - Color: color, - Theme: "dark", + BaseData: baseData, + Color: color, + PostListBgColor: bgColor.HTML(), } var res ResponseData