mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-24 13:27:31 +00:00
feat: make tag listing more in line with other booru software
This commit is contained in:
parent
3ed594ab88
commit
e73d3d0dda
@ -70,12 +70,14 @@ func postGet(c *gin.Context) {
|
|||||||
ImagePath: "/data/" + post.Blob.FilePath,
|
ImagePath: "/data/" + post.Blob.FilePath,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
tagObjs := services.GetTagFilter(tagStrings)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
||||||
CurrentPage: page,
|
CurrentPage: page,
|
||||||
TotalPage: totalPage,
|
TotalPage: totalPage,
|
||||||
PostCount: postPages,
|
PostCount: postPages,
|
||||||
Posts: postResult,
|
Posts: postResult,
|
||||||
Tags: tagStrings,
|
Tags: tagObjs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,5 +31,5 @@ type PostPaginationResponse struct {
|
|||||||
TotalPage int `json:"totalPage"`
|
TotalPage int `json:"totalPage"`
|
||||||
PostCount int `json:"postCount"`
|
PostCount int `json:"postCount"`
|
||||||
Posts []PostListItem `json:"posts"`
|
Posts []PostListItem `json:"posts"`
|
||||||
Tags []string `json:"tags"`
|
Tags []TagListItem `json:"tags"`
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,24 @@ func GetTagAll() []models.TagListItem {
|
|||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTagFilter(tagString []string) []models.TagListItem {
|
||||||
|
tagObjs, _ := ParseReadTags(tagString)
|
||||||
|
var tagIds []string
|
||||||
|
for _, val := range tagObjs {
|
||||||
|
tagIds = append(tagIds, val.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
var tags []models.TagListItem
|
||||||
|
database.DB.Model(&tagObjs).
|
||||||
|
Joins("join tag_types on tag_types.id = tags.tag_type_id").
|
||||||
|
Joins("left join post_tags on post_tags.tag_id = tags.id").
|
||||||
|
Select("tags.id as tag_id, tags.name as tag_name, tag_types.name as tag_type, count(post_tags.post_id) as post_count").
|
||||||
|
Group("tags.id, tags.name, tag_types.name").
|
||||||
|
Order("post_count DESC").
|
||||||
|
Find(&tags, tagIds)
|
||||||
|
return tags
|
||||||
|
}
|
||||||
|
|
||||||
func GetTagAutocomplete() []string {
|
func GetTagAutocomplete() []string {
|
||||||
var tags []string
|
var tags []string
|
||||||
result := database.DB.Model(&database.Tag{}).
|
result := database.DB.Model(&database.Tag{}).
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
const data = await getPostSearchTag({ page, q: searchTerms.join("+") });
|
const data = await getPostSearchTag({ page, q: searchTerms.join("+") });
|
||||||
if (data.posts) {
|
if (data.posts) {
|
||||||
posts = data.posts;
|
posts = data.posts;
|
||||||
tags = data.tags;
|
tags = data.tags.sort((a, b) => b.postCount - a.postCount);
|
||||||
totalPages = data.totalPage;
|
totalPages = data.totalPage;
|
||||||
pagination = paginate(page, totalPages);
|
pagination = paginate(page, totalPages);
|
||||||
} else {
|
} else {
|
||||||
@ -34,17 +34,6 @@
|
|||||||
pagination = paginate(page, totalPages);
|
pagination = paginate(page, totalPages);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$: {
|
|
||||||
let catTags = tags.reduce(
|
|
||||||
(acc, o) => ((acc[o] = (acc[o] || 0) + 1), acc),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
categorizedTags = Object.entries(catTags).map(([k, v]) => ({
|
|
||||||
tag: k,
|
|
||||||
num: v,
|
|
||||||
}));
|
|
||||||
categorizedTags = categorizedTags.sort((a, b) => b.num - a.num);
|
|
||||||
}
|
|
||||||
let queryParams;
|
let queryParams;
|
||||||
|
|
||||||
const onTagChange = (value) => {
|
const onTagChange = (value) => {
|
||||||
@ -112,12 +101,12 @@
|
|||||||
<div class="panel-block column">
|
<div class="panel-block column">
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
<ul class="menu-list">
|
<ul class="menu-list">
|
||||||
{#each categorizedTags as tag (tag)}
|
{#each tags as tag (tag)}
|
||||||
<li>
|
<li>
|
||||||
<TagLinkNumbered
|
<TagLinkNumbered
|
||||||
class=""
|
class=""
|
||||||
tag={tag.tag}
|
tag={tag.tagType+":"+tag.tagName}
|
||||||
num={tag.num}
|
num={tag.postCount}
|
||||||
/>
|
/>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
|
Loading…
Reference in New Issue
Block a user