mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
Feature: daily ranking
This commit is contained in:
+25
-6
@@ -35,12 +35,31 @@ func GetRecommendedIllust(c *gin.Context) []entity.Illust {
|
||||
return illusts
|
||||
}
|
||||
|
||||
func getJson(url string, target interface{}) error {
|
||||
r, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
func GetRankingIllust(c *gin.Context, mode string) []entity.Illust {
|
||||
if mode == "" {
|
||||
mode = "day"
|
||||
}
|
||||
defer r.Body.Close()
|
||||
URL := "https://hibi.cocomi.cf/api/pixiv/rank?mode=" + mode
|
||||
var illusts []entity.Illust
|
||||
illusts = append(illusts, entity.Illust{}) // Placeholder to shift the index
|
||||
|
||||
return json.NewDecoder(r.Body).Decode(target)
|
||||
resp, err := http.Get(URL)
|
||||
|
||||
if err != nil {
|
||||
panic("Failed to request")
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
panic("Failed to parse body")
|
||||
}
|
||||
s := string(body)
|
||||
g := gjson.Get(s, "illusts").String()
|
||||
|
||||
err = json.Unmarshal([]byte(g), &illusts)
|
||||
if err != nil {
|
||||
panic("Failed to parse Json.")
|
||||
}
|
||||
|
||||
return illusts
|
||||
}
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"pixivfe/handler"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func test(c *gin.Context) {
|
||||
data := handler.GetRecommendedIllust(c)
|
||||
c.HTML(http.StatusOK, "index.html", data)
|
||||
func inc(n int) int {
|
||||
return n + 1
|
||||
}
|
||||
|
||||
func index_page(c *gin.Context) {
|
||||
recommended := handler.GetRecommendedIllust(c)
|
||||
ranking := handler.GetRankingIllust(c, "")
|
||||
c.HTML(http.StatusOK, "index.html", gin.H{"Recommended": recommended, "Rankings": ranking})
|
||||
}
|
||||
|
||||
func main() {
|
||||
server := gin.Default()
|
||||
server.SetFuncMap(template.FuncMap{
|
||||
"inc": inc,
|
||||
})
|
||||
server.Static("css/", "./template/css")
|
||||
server.LoadHTMLGlob("template/*.html")
|
||||
// Listen and Servr in 0.0.0.0:8080
|
||||
server.GET("/", test)
|
||||
server.GET("/", index_page)
|
||||
|
||||
server.Run(":8080")
|
||||
}
|
||||
|
||||
+8
-6
@@ -25,7 +25,7 @@
|
||||
<div class="container">
|
||||
<h1>Recommended works</h1>
|
||||
<div class="thumbnail-container">
|
||||
{{ range . }}
|
||||
{{ range .Recommended }}
|
||||
<div class="artwork-thumbnail-small artwork-thumbnail">
|
||||
<a href="#">
|
||||
<img
|
||||
@@ -47,19 +47,20 @@
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<h1>Rankings</h1>
|
||||
<h1>Today's rankings</h1>
|
||||
<div class="thumbnail-container">
|
||||
{{ range $i, $_ := .Rankings }}
|
||||
<div class="artwork-thumbnail-large artwork-thumbnail">
|
||||
<div class="artwork-rank-circle">1</div>
|
||||
<div class="artwork-rank-circle">{{ $i | inc}}</div>
|
||||
<a href="#">
|
||||
<img
|
||||
src="https://px2.rainchan.win/c/360x360_70/img-master/img/2023/05/07/17/30/45/107910958_p0_square1200.jpg"
|
||||
alt="asd"
|
||||
src="{{ .Images.square_medium }}"
|
||||
alt="{{ .Title }}"
|
||||
class="artwork-master-image"
|
||||
/>
|
||||
</a>
|
||||
|
||||
<h3 class="artwork-thumbnail-title no-margin">Title</h3>
|
||||
<h3 class="artwork-thumbnail-title no-margin">{{ .Title }}</h3>
|
||||
<a href="#" class="artwork-thumbnail-artist flex"
|
||||
><img
|
||||
src="https://px2.rainchan.win/c/360x360_70/img-master/img/2023/05/07/17/30/45/107910958_p0_square1200.jpg"
|
||||
@@ -69,6 +70,7 @@
|
||||
VnPower</a
|
||||
>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<h1>Pixivision</h1>
|
||||
|
||||
Reference in New Issue
Block a user