Feature: basic artwork page

This commit is contained in:
VnPower 2023-05-14 19:30:03 +07:00
parent fd09649e83
commit ccbe2eaa93
Signed by: vnpower
GPG key ID: 881DE3DEB966106C
7 changed files with 172 additions and 13 deletions

View file

@ -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 {

View file

@ -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 {

10
main.go
View file

@ -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")
}

43
template/artwork.html Normal file
View file

@ -0,0 +1,43 @@
{{ template "header.html" }}
<div class="container">
<div class="artwork-page">
<div class="artwork-content">
<div class="artwork-images">
<!-- -->
<a href="#">
<img src="https://px2.rainchan.win/img-master/img/2023/05/14/10/00/17/108109545_p0_master1200.jpg" alt="#"
class="artwork-image-page" target="_blank" />
</a>
</div>
{{ with .Illust }}
<h2>{{ .Title }}</h3>
<p>{{ .Caption }}</p>
<p>Tags</p>
<br />
<span>{{ .Views }} views | {{ .Bookmarks }} bookmarks</span>
<br />
<small>{{ .Date }}</small>
<a href="#" class="artwork-thumbnail-artist flex"><img src="{{ .Artist.Avatar.medium }}"
alt="{{ .Artist.Name }}" class="artwork-artist-avatar border-rounded" />
{{ .Artist.Name }}</a>
<div class="thumbnail-container">...</div>
<hr />
<h2>Comments</h2>
{{ end }}
</div>
</div>
{{ range .Related }}
<div class="artwork-thumbnail-small artwork-thumbnail">
<a href="#">
<img src="{{ .Images.square_medium }}" alt="{{ .Title }}" class="artwork-master-image" />
</a>
<h3 class="artwork-thumbnail-title no-margin">{{ .Title }}</h3>
<a href="#" class="artwork-thumbnail-artist flex"><img src="{{ .Artist.Avatar.medium }}" alt="{{ .Artist.Name }}"
class="artwork-thumbnail-artist-avatar border-rounded" />
{{ .Artist.Name }}</a>
</div>
{{ end }}
</div>
{{ template "footer.html" }}

View file

@ -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 */

View file

@ -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%;
}
}
}

BIN
template/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 98 KiB