From ccbe2eaa93315da27cbbd94cd31898dacdc2ae71 Mon Sep 17 00:00:00 2001 From: VnPower Date: Sun, 14 May 2023 19:30:03 +0700 Subject: [PATCH] Feature: basic artwork page --- entity/models.go | 25 ++++++++++++++--------- handler/illust.go | 38 ++++++++++++++++++++++++++++++++--- main.go | 10 +++++++++- template/artwork.html | 43 ++++++++++++++++++++++++++++++++++++++++ template/css/style.css | 31 +++++++++++++++++++++++++++++ template/css/style.scss | 38 +++++++++++++++++++++++++++++++++++ template/favicon.ico | Bin 0 -> 99878 bytes 7 files changed, 172 insertions(+), 13 deletions(-) create mode 100644 template/artwork.html create mode 100644 template/favicon.ico diff --git a/entity/models.go b/entity/models.go index 9e9bdcc..261512b 100644 --- a/entity/models.go +++ b/entity/models.go @@ -1,16 +1,23 @@ package entity +import ( + "html/template" + "time" +) + type Illust struct { - ID int `json:"id"` - Title string `json:"title"` - Caption string `json:"caption"` - Images map[string]string `json:"image_urls"` - Artist UserBrief `json:"user"` + ID int `json:"id"` + Title string `json:"title"` + Caption template.HTML `json:"caption"` + Images map[string]string `json:"image_urls"` + Artist UserBrief `json:"user"` + Date time.Time `json:"create_date"` + Pages int `json:"page_count"` + Views int `json:"total_view"` + Bookmarks int `json:"total_bookmarks"` + SingleImage map[string]string `json:"meta_single_page"` + MultipleImage []map[string]map[string]string `json:"meta_pages"` // Tags Tag[]; - Date string `json:"create_date"` - Pages int `json:"page_count"` - Views int `json:"total_view"` - Bookmarks int `json:"total_bookmarks"` } type Spotlight struct { diff --git a/handler/illust.go b/handler/illust.go index 3cbbf3d..a22c157 100644 --- a/handler/illust.go +++ b/handler/illust.go @@ -56,13 +56,45 @@ func GetNewestIllust(c *gin.Context) []entity.Illust { return illusts } +func GetRelatedIllust(c *gin.Context) []entity.Illust { + id := c.Param("id") + URL := "https://hibi.cocomi.cf/api/pixiv/related?id=" + id + var illusts []entity.Illust + + s := Request(URL) + g := GetInnerJSON(s, "illusts") + + err := json.Unmarshal([]byte(g), &illusts) + if err != nil { + panic("Failed to parse JSON") + } + + return illusts +} + +func GetIllustByID(c *gin.Context) entity.Illust { + id := c.Param("id") + URL := "https://hibi.cocomi.cf/api/pixiv/illust?id=" + id + var illust entity.Illust + + s := Request(URL) + g := GetInnerJSON(s, "illust") + + err := json.Unmarshal([]byte(g), &illust) + if err != nil { + panic(err) + } + + return illust +} + func GetSpotlightArticle(c *gin.Context) []entity.Spotlight { - // URL := "https://hibi.cocomi.cf/api/pixiv/spotlights?lang=en" - URL := "https://now.pixiv.pics/api/pixivision?lang=en" + URL := "https://hibi.cocomi.cf/api/pixiv/spotlights?lang=en" + // URL := "https://now.pixiv.pics/api/pixivision?lang=en" var articles []entity.Spotlight s := Request(URL) - g := GetInnerJSON(s, "articles") + g := GetInnerJSON(s, "spotlight_articles") err := json.Unmarshal([]byte(g), &articles) if err != nil { diff --git a/main.go b/main.go index 7fd1f40..162334e 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,12 @@ func inc(n int) int { return n + 1 } +func artwork_page(c *gin.Context) { + illust := handler.GetIllustByID(c) + related := handler.GetRelatedIllust(c) + c.HTML(http.StatusOK, "artwork.html", gin.H{"Illust": illust, "Related": related}) +} + func index_page(c *gin.Context) { recommended := handler.GetRecommendedIllust(c) ranking := handler.GetRankingIllust(c, "day") @@ -30,9 +36,11 @@ func main() { server.SetFuncMap(template.FuncMap{ "inc": inc, }) + server.StaticFile("/favicon.ico", "./template/favicon.ico") server.Static("css/", "./template/css") server.LoadHTMLGlob("template/*.html") server.GET("/", index_page) + server.GET("artworks/:id", artwork_page) - server.Run(":8000") + server.Run(":8080") } diff --git a/template/artwork.html b/template/artwork.html new file mode 100644 index 0000000..0960812 --- /dev/null +++ b/template/artwork.html @@ -0,0 +1,43 @@ +{{ template "header.html" }} +
+
+
+
+ + + # + +
+ {{ with .Illust }} +

{{ .Title }}

+

{{ .Caption }}

+

Tags

+
+ {{ .Views }} views | {{ .Bookmarks }} bookmarks +
+ {{ .Date }} + + {{ .Artist.Name }} + {{ .Artist.Name }} +
...
+
+

Comments

+ {{ end }} +
+
+ {{ range .Related }} +
+ + {{ .Title }} + + +

{{ .Title }}

+ {{ .Artist.Name }} + {{ .Artist.Name }} +
+ {{ end }} +
+{{ template "footer.html" }} diff --git a/template/css/style.css b/template/css/style.css index e57675a..a35a55c 100644 --- a/template/css/style.css +++ b/template/css/style.css @@ -127,4 +127,35 @@ body { text-overflow: ellipsis; } +.artwork-page { + background: #333; +} +.artwork-page .artwork-content { + margin: 0 20px; + font-size: 0.8rem; +} +.artwork-page .artwork-content a { + color: #3d7699; + text-decoration: none; +} +.artwork-page .artwork-content a:hover { + text-decoration: underline; +} +.artwork-page .artwork-artist-avatar { + width: 50px; + height: 50px; + object-position: center top; +} +.artwork-page .artwork-images { + display: flex; + justify-content: center; + width: 100%; +} +.artwork-page .artwork-images .artwork-image-page { + margin: 10px auto; + height: 578px; + width: auto; + max-width: 100%; +} + /*# sourceMappingURL=style.css.map */ diff --git a/template/css/style.scss b/template/css/style.scss index aa83d6c..52b509b 100644 --- a/template/css/style.scss +++ b/template/css/style.scss @@ -1,6 +1,7 @@ $bg: #181a1b; $fg: #e8e6e3; $bg-alt: #262a2b; +$blue: #3d7699; * { box-sizing: border-box; @@ -147,3 +148,40 @@ body { } } } + +.artwork-page { + background: #333; + + .artwork-content { + margin: 0 20px; + font-size: 0.8rem; + + a { + color: $blue; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } + } + + .artwork-artist-avatar { + width: 50px; + height: 50px; + object-position: center top; + } + + .artwork-images { + display: flex; + justify-content: center; + width: 100%; + + .artwork-image-page { + margin: 10px auto; + height: 578px; + width: auto; + max-width: 100%; + } + } +} diff --git a/template/favicon.ico b/template/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..77dc9698e38d135a9c9511cca5a014b8cd7f2994 GIT binary patch literal 99878 zcmeHQO{i5>6h4>aWuoFhDk|&}D$aW0BpN;CSw0LCG0=%P2r($FK{Y7o=`3i}4+b`B zQVj~i1`Q%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