Add all available filters to the search page

This commit is contained in:
VnPower
2024-06-07 22:03:19 +07:00
parent 4e0e03bb59
commit f38cf895a4
7 changed files with 115 additions and 41 deletions
+3 -2
View File
@@ -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 {
+27 -20
View File
@@ -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
+4
View File
@@ -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
+2 -7
View File
@@ -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 {
+30 -1
View File
@@ -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)
}
+18 -7
View File
@@ -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
},
}
+31 -4
View File
@@ -26,6 +26,7 @@
</a>
{{ end }}
</div>
{{ Queries.Hash.Name }}
<div class="switcher">
<div class="switch-title">Category</div>
@@ -47,10 +48,6 @@
<a href='{{URL}}safe#checkpoint' class="switch-button">Safe</a>
<a href='{{URL}}r18#checkpoint' class="switch-button">R-18</a>
</div>
<details>
<summary>
<h2>Advanced settings</h2>
</summary>
<div class="switcher">
<div class="switch-title">Ratio</div>
{{ URL := URLC(Queries, "ratio") }}
@@ -59,6 +56,36 @@
<a href='{{URL}}0#checkpoint' class="switch-button">Square</a>
<a href='{{URL}}0.5#checkpoint' class="switch-button">Landscape</a>
</div>
<div class="switcher">
<div class="switch-title">Search mode</div>
{{ URL := URLC(Queries, "smode") }}
<a href='{{URL}}#checkpoint' class="switch-button">None</a>
<a href='{{URL}}s_tag_full#checkpoint' class="switch-button">Exact (tags)</a>
<a href='{{URL}}s_tag#checkpoint' class="switch-button">Partial (tags)</a>
<a href='{{URL}}s_tc#checkpoint' class="switch-button">Title/Caption</a>
</div>
<details>
<summary>
<h2>Advanced settings</h2>
</summary>
{{ URL := URLC(Queries, "") }}
<form action="{{ URL }}&name={{ Queries.Hash.Name }}" method="post">
<label for="wlt">Minimum image width</label>
<input type="text" name="wlt" value="{{ Queries.Hash.Wlt }}" />
<label for="wgt">Maximum image width</label>
<input type="text" name="wgt" value="{{ Queries.Hash.Wgt }}" />
<label for="hlt">Minimum image height</label>
<input type="text" name="hlt" value="{{ Queries.Hash.Hlt }}" />
<label for="hgt">Maximum image height</label>
<input type="text" name="hgt" value="{{ Queries.Hash.Hgt }}" />
<label for="scd">Posted after (format: yyyy-mm-dd)</label>
<input type="text" name="scd" value="{{ Queries.Hash.Scd }}" />
<label for="ecd">Posted before (format: yyyy-mm-dd)</label>
<input type="text" name="ecd" value="{{ Queries.Hash.Ecd }}" />
<label for="tool">Tool</label>
<input type="text" name="tool" value="{{ Queries.Hash.Tool }}" />
<input type="submit" value="Set" />
</form>
</details>
{{ if Data.Popular.Recent }}
<h2>Popular artworks</h2>