diff --git a/core/http/url.go b/core/http/url.go index f8e5e91..0bb1a88 100644 --- a/core/http/url.go +++ b/core/http/url.go @@ -117,9 +117,10 @@ func GetTagDetailURL(unescapedTag string) string { } func GetSearchArtworksURL(s map[string]string) string { - base := "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&ratio=%s&p=%s" + // Long. + base := "https://www.pixiv.net/ajax/search/%s/%s?order=%s&mode=%s&ratio=%s&s_mode=%s&wlt=%s&wgt=%s&hlt=%s&hgt=%s&tool=%s&scd=%s&ecd=%s&p=%s" - return fmt.Sprintf(base, s["Category"], s["Name"], s["Order"], s["Mode"], s["Ratio"], s["Page"]) + return fmt.Sprintf(base, s["Category"], s["Name"], s["Order"], s["Mode"], s["Ratio"], s["Smode"], s["Wlt"], s["Wgt"], s["Hlt"], s["Hgt"], s["Tool"], s["Scd"], s["Ecd"], s["Page"]) } func GetLandingURL(mode string) string { diff --git a/core/webapi/tag.go b/core/webapi/tag.go index 6e91633..2fdf6bc 100644 --- a/core/webapi/tag.go +++ b/core/webapi/tag.go @@ -35,36 +35,43 @@ type SearchResult struct { } type SearchPageSettings struct { - Name string // Tag to search for + Name string // Tag to search for Category string // Filter by type, could be illusts or mangas - Order string // Sort by date - Mode string // Safe, R18 or both - Ratio string // Landscape, portrait, or squared - Page string // Page number + Order string // Sort by date + Mode string // Safe, R18 or both + Ratio string // Landscape, portrait, or squared + Page string // Page number // To implement - SearchMode string // Exact match, partial match, or match with title - Wlt string // Minimum image width - Wgt string // Maximum image width - Hlt string // Minimum image height - Hgt string // Maximum image height - Tool string // Filter by production tools (ex. Photoshop) - Scd string // After this date - Ecd string // Before this date + Smode string // Exact match, partial match, or match with title + Wlt string // Minimum image width + Wgt string // Maximum image width + Hlt string // Minimum image height + Hgt string // Maximum image height + Tool string // Filter by production tools (ex. Photoshop) + Scd string // After this date + Ecd string // Before this date } func (s SearchPageSettings) ReturnMap() map[string]string { - return map[string]string { - "Name": s.Name, + return map[string]string{ + "Name": s.Name, "Category": s.Category, - "Order": s.Order, - "Mode": s.Mode, - "Ratio": s.Ratio, - "Page": s.Page, // This field should always be the last + "Order": s.Order, + "Mode": s.Mode, + "Ratio": s.Ratio, + "Smode": s.Smode, + "Wlt": s.Wlt, + "Wgt": s.Wgt, + "Hlt": s.Hlt, + "Hgt": s.Hgt, + "Scd": s.Scd, + "Ecd": s.Ecd, + "Tool": s.Tool, + "Page": s.Page, } } - func GetTagData(c *fiber.Ctx, name string) (TagDetail, error) { var tag TagDetail diff --git a/doc/dev/user-customization.md b/doc/dev/user-customization.md index 3f2a02c..10b5a38 100644 --- a/doc/dev/user-customization.md +++ b/doc/dev/user-customization.md @@ -17,3 +17,7 @@ Let the host supply multiple tokens at once to avoid overuse. ## artwork - [ ] native AI/R15/R18/R18-G... artwork filtering We can filter them out using values supplied by Pixiv for each artworks. + +## search +- [ ] add an option to do potentially very extensive searches +Sort by bookmarks diff --git a/main.go b/main.go index 1b97c84..924707d 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,6 @@ import ( "fmt" "log" "net" - "net/http" "os" "os/exec" "runtime" @@ -265,12 +264,8 @@ func main() { server.Get("/tags/:name", pages.TagPage) server.Post("/tags/:name", pages.TagPage) - server.Post("/tags", - func(c *fiber.Ctx) error { - name := c.FormValue("name") - - return c.Redirect("/tags/"+name, http.StatusFound) - }) + server.Get("/tags", pages.TagPage) + server.Post("/tags", pages.AdvancedTagPost) // Legacy illust URL server.Get("/member_illust.php", func(c *fiber.Ctx) error { diff --git a/pages/tag.go b/pages/tag.go index 89ea38e..5d15ac7 100644 --- a/pages/tag.go +++ b/pages/tag.go @@ -1,6 +1,7 @@ package pages import ( + "net/http" "net/url" "strconv" @@ -10,7 +11,7 @@ import ( ) func TagPage(c *fiber.Ctx) error { - param := c.Params("name") + param := c.Params("name", c.Query("name")) name, err := url.PathUnescape(param) if err != nil { return err @@ -30,6 +31,13 @@ func TagPage(c *fiber.Ctx) error { Order: c.Query("order", "date_d"), Mode: c.Query("mode", "safe"), Ratio: c.Query("ratio", ""), + Wlt: c.Query("wlt", ""), + Wgt: c.Query("wgt", ""), + Hlt: c.Query("hlt", ""), + Hgt: c.Query("hgt", ""), + Tool: c.Query("tool", ""), + Scd: c.Query("scd", ""), + Ecd: c.Query("ecd", ""), Page: page, } @@ -46,3 +54,24 @@ func TagPage(c *fiber.Ctx) error { return c.Render("tag", fiber.Map{"Title": "Results for " + name, "Tag": tag, "Data": result, "Queries": urlc, "TrueTag": param, "Page": pageInt}) } + +func AdvancedTagPost(c *fiber.Ctx) error { + return c.RedirectToRoute("/tags", fiber.Map{ + "queries": map[string]string{ + "name": c.Query("name"), + "category": c.Query("category", "artworks"), + "order": c.Query("order", "date_d"), + "mode": c.Query("mode", "safe"), + "ratio": c.Query("ratio"), + "page": c.Query("page", "1"), + "wlt": c.Query("wlt", c.FormValue("wlt")), + "wgt": c.Query("wgt", c.FormValue("wgt")), + "hlt": c.Query("hlt", c.FormValue("hlt")), + "hgt": c.Query("hgt", c.FormValue("hgt")), + "tool": c.Query("tool", c.FormValue("tool")), + "scd": c.Query("scd", c.FormValue("scd")), + "ecd": c.Query("ecd", c.FormValue("ecd")), + }, + }, http.StatusFound) + +} diff --git a/serve/template.go b/serve/template.go index 20cefd0..ead219f 100644 --- a/serve/template.go +++ b/serve/template.go @@ -304,13 +304,22 @@ func GetTemplateFunctions() template.FuncMap { "URLC": func(obj site.URLConstructor, name string) string { url := fmt.Sprintf("/%s", obj.Path) first := true + exists := false for k, v := range obj.Hash { k = lowercaseFirstChar(k) if k == name { + // Reserve this + exists = true continue } + + if v == "" { + // If the value is empty, ignore to not clutter the URL + continue + } + if first { url += "?" first = false @@ -321,14 +330,16 @@ func GetTemplateFunctions() template.FuncMap { } // This is to move the matched query to the end of the URL - var t string - if first { - t = "?" - } else { - t = "&" - } - url += fmt.Sprintf("%s%s=", t, name) + if exists { + var t string + if first { + t = "?" + } else { + t = "&" + } + url += fmt.Sprintf("%s%s=", t, name) + } return url }, } diff --git a/views/pages/tag.jet.html b/views/pages/tag.jet.html index c0f6851..52724a5 100644 --- a/views/pages/tag.jet.html +++ b/views/pages/tag.jet.html @@ -26,6 +26,7 @@ {{ end }} + {{ Queries.Hash.Name }}
-