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 0000000..77dc969 Binary files /dev/null and b/template/favicon.ico differ