diff --git a/handler/pixiv.go b/handler/pixiv.go index d5c2065..a480480 100644 --- a/handler/pixiv.go +++ b/handler/pixiv.go @@ -35,6 +35,7 @@ const ( UserInformationURL = "https://www.pixiv.net/ajax/user/%s?full=1" UserArtworksURL = "https://www.pixiv.net/ajax/user/%s/profile/all" UserArtworksFullURL = "https://www.pixiv.net/ajax/user/%s/profile/illusts?work_category=illustManga&is_first_page=0&lang=en%s" + FrequentTagsURL = "https://www.pixiv.net/ajax/tags/frequent/illust?%s" ) func (p *PixivClient) SetHeader(header map[string]string) { @@ -146,6 +147,28 @@ func (p *PixivClient) GetArtworkImages(id string) ([]models.Image, error) { return images, nil } +func (p *PixivClient) GetFrequentTags(ids string) ([]models.FrequentTag, error) { + s, _ := p.TextRequest(fmt.Sprintf(FrequentTagsURL, ids)) + + var pr models.PixivResponse + var tags []models.FrequentTag + // Parse Pixiv response body + err := json.Unmarshal([]byte(s), &pr) + if err != nil { + return nil, err + } + if pr.Error { + return nil, errors.New(fmt.Sprintf("Pixiv returned error message: %s", pr.Message)) + } + + err = json.Unmarshal([]byte(pr.Body), &tags) + if err != nil { + return nil, err + } + + return tags, nil +} + func (p *PixivClient) GetArtworkByID(id string) (*models.Illust, error) { s, _ := p.TextRequest(fmt.Sprintf(ArtworkInformationURL, id)) @@ -322,20 +345,16 @@ func (p *PixivClient) GetRelatedArtworks(id string) ([]models.IllustShort, error return body.Illusts, nil } -func (p *PixivClient) GetUserArtworks(id string, page int) ([]models.IllustShort, error) { - ids, err := p.GetUserArtworksID(id, page) - if err != nil { - return nil, err - } +func (p *PixivClient) GetUserArtworks(id string, ids string) ([]models.IllustShort, error) { - url := fmt.Sprintf(UserArtworksFullURL, id, *ids) + url := fmt.Sprintf(UserArtworksFullURL, id, ids) var pr models.PixivResponse var works []models.IllustShort s, _ := p.TextRequest(url) - err = json.Unmarshal([]byte(s), &pr) + err := json.Unmarshal([]byte(s), &pr) if err != nil { return nil, err } @@ -370,9 +389,14 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err var user *models.User var pr models.PixivResponse + ids, err := p.GetUserArtworksID(id, page) + if err != nil { + return nil, err + } + s, _ := p.TextRequest(fmt.Sprintf(UserInformationURL, id)) - err := json.Unmarshal([]byte(s), &pr) + err = json.Unmarshal([]byte(s), &pr) if err != nil { return nil, err @@ -395,7 +419,7 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err user = body.User // Artworks - works, _ := p.GetUserArtworks(id, page) + works, _ := p.GetUserArtworks(id, *ids) user.Artworks = works // Background image @@ -406,6 +430,9 @@ func (p *PixivClient) GetUserInformation(id string, page int) (*models.User, err // Artworks count // user.ArtworksCount, _ = p.GetUserArtworksCount(id) + // Frequent tags + user.FrequentTags, err = p.GetFrequentTags(*ids) + return user, nil } diff --git a/models/models.go b/models/models.go index 74ab424..1deab8e 100644 --- a/models/models.go +++ b/models/models.go @@ -87,6 +87,11 @@ type Tag struct { TranslatedName string `json:"translation"` } +type FrequentTag struct { + Name string `json:"tag"` + TranslatedName string `json:"tag_translation"` +} + type Illust struct { ID string `json:"id"` Title string `json:"title"` @@ -139,6 +144,7 @@ type User struct { Comment template.HTML `json:"commentHtml"` Artworks []IllustShort `json:"artworks"` ArtworksCount int + FrequentTags []FrequentTag } type RankedArtwork struct { diff --git a/template/css/style.css b/template/css/style.css index e0bda4f..4e3facb 100644 --- a/template/css/style.css +++ b/template/css/style.css @@ -395,6 +395,7 @@ body { background-color: #262a2b; display: inline-block; padding: 5px 10px; + margin-bottom: 4px; text-decoration: none; color: #d8d4cf; font-weight: bold; diff --git a/template/css/style.scss b/template/css/style.scss index f9670c1..1a6200f 100644 --- a/template/css/style.scss +++ b/template/css/style.scss @@ -463,6 +463,7 @@ body { background-color: $bg-alt; display: inline-block; padding: 5px 10px; + margin-bottom: 4px; text-decoration: none; color: $fg; font-weight: bold; diff --git a/template/user.jet.html b/template/user.jet.html index 3fefe82..5adde33 100644 --- a/template/user.jet.html +++ b/template/user.jet.html @@ -8,11 +8,7 @@
- avatar + avatar

{{ User.Name }}

{{ User.Following }} Following | {{ User.MyPixiv }} MyPixiv @@ -20,6 +16,11 @@

{{ raw: User.Comment }}

+
+ {{ range User.FrequentTags }} + #{{ .Name }} + {{ end }} +

Illustrations and Mangas

{{ include "small-tn" User.Artworks }} @@ -30,11 +31,7 @@ Previous {{ else }} First - Previous + Previous {{ end }} {{ Page }} @@ -43,16 +40,8 @@ Next Last {{ else }} - Next - Last + Next + Last {{ end }}