From 60437bbb011b65936d74a91078deb3456f54fb1c Mon Sep 17 00:00:00 2001 From: VnPower Date: Thu, 6 Jun 2024 10:04:27 +0700 Subject: [PATCH] Build the URL once and not overcomplicate stuff --- core/http/constructurl.go | 13 +++---------- pages/discovery.go | 2 +- pages/tag.go | 18 +++++++++--------- views/pages/discovery.jet.html | 7 ++++--- views/pages/tag.jet.html | 30 +++++++++++++++++------------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/core/http/constructurl.go b/core/http/constructurl.go index 0614b93..d57b518 100644 --- a/core/http/constructurl.go +++ b/core/http/constructurl.go @@ -8,24 +8,20 @@ import ( type URLConstructor struct { path string hash map[string]string - fragment string } func lowercaseFirstChar(s string) string { return strings.ToLower(s[0:1]) + s[1:] } -func (obj *URLConstructor) Replace(name, value string) string { +func (obj *URLConstructor) Replace(name string) string { url := fmt.Sprintf("/%s", obj.path) first := true - var matchedV string - for k, v := range obj.hash { k = lowercaseFirstChar(k) if k == name { - matchedV = value continue } if first { @@ -44,17 +40,14 @@ func (obj *URLConstructor) Replace(name, value string) string { } else { t = "&" } - url += fmt.Sprintf("%s%s=%s", t, name, matchedV) - - url += obj.fragment + url += fmt.Sprintf("%s%s=", t, name) return url } -func NewURLConstruct(path string, obj map[string]string, fragment string) URLConstructor { +func NewURLConstruct(path string, obj map[string]string) URLConstructor { return URLConstructor{ path: path, hash: obj, - fragment: fragment, } } diff --git a/pages/discovery.go b/pages/discovery.go index 42cf519..88b0675 100644 --- a/pages/discovery.go +++ b/pages/discovery.go @@ -14,7 +14,7 @@ func DiscoveryPage(c *fiber.Ctx) error { return err } - urlc := site.NewURLConstruct("discovery", map[string]string{"mode": mode}, "#checkpoint") + urlc := site.NewURLConstruct("discovery", map[string]string{"mode": mode}) return c.Render("discovery", fiber.Map{ "Artworks": works, diff --git a/pages/tag.go b/pages/tag.go index b7393cd..0b2e1a9 100644 --- a/pages/tag.go +++ b/pages/tag.go @@ -4,8 +4,8 @@ import ( "net/url" "strconv" - core "codeberg.org/vnpower/pixivfe/v2/core/webapi" site "codeberg.org/vnpower/pixivfe/v2/core/http" + core "codeberg.org/vnpower/pixivfe/v2/core/webapi" "github.com/gofiber/fiber/v2" ) @@ -24,13 +24,13 @@ func TagPage(c *fiber.Ctx) error { // Because of the large amount of queries available for this route, // I made a struct type just to manage the queries - queries := core.SearchPageSettings { - Name: name, + queries := core.SearchPageSettings{ + Name: name, Category: c.Query("category", "artworks"), - Order: c.Query("order", "date_d"), - Mode: c.Query("mode", "safe"), - Ratio: c.Query("ratio", ""), - Page: page, + Order: c.Query("order", "date_d"), + Mode: c.Query("mode", "safe"), + Ratio: c.Query("ratio", ""), + Page: page, } tag, err := core.GetTagData(c, name) @@ -42,8 +42,8 @@ func TagPage(c *fiber.Ctx) error { return err } - urlc := site.NewURLConstruct("tags", queries.ReturnMap(), "") + urlc := site.NewURLConstruct("tags", queries.ReturnMap()) return c.Render("tag", fiber.Map{"Title": "Results for " + name, "Tag": tag, "Data": result, "Queries": queries.ReturnMap(), "TrueTag": param, "Page": pageInt, "URLC": urlc.Replace}) - + } diff --git a/views/pages/discovery.jet.html b/views/pages/discovery.jet.html index a74f764..cd88ac7 100644 --- a/views/pages/discovery.jet.html +++ b/views/pages/discovery.jet.html @@ -7,9 +7,10 @@
Filter
- All - Safe - R-18 + {{ URL := URLC("mode") }} + All + Safe + R-18
{{ include "components/small-tn" Artworks }} diff --git a/views/pages/tag.jet.html b/views/pages/tag.jet.html index 534a674..4bf8f87 100644 --- a/views/pages/tag.jet.html +++ b/views/pages/tag.jet.html @@ -29,27 +29,31 @@
Type
- All - Illustrations - Manga + {{ URL := URLC("category") }} + All + Illustrations + Manga
Order
- Newest - Oldest + {{ URL := URLC("order") }} + Newest + Oldest
Filter
- All - Safe - R-18 + {{ URL := URLC("mode") }} + All + Safe + R-18
Ratio
- All - Portrait - Square - Landscape + {{ URL := URLC("ratio") }} + All + Portrait + Square + Landscape
{{ if Data.Popular.Recent }}

Popular artworks

@@ -70,7 +74,7 @@