mirror of
https://codeberg.org/VnPower/PixivFE
synced 2024-12-06 19:16:23 +01:00
pixivision tag: display total number of articles
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
<div class="custom-card-body p-4">
|
||||
<!-- <div class="d-flex flex-wrap justify-content-between align-items-start"> -->
|
||||
<h2 class="display-6 fw-bold me-2">{{ .Tag.Title }}</h2>
|
||||
<p class="lead"><span class="fw-bold">{{ len(.Tag.Articles) }}</span> <span class="fw-medium text-muted">articles</span></p>
|
||||
<p class="lead"><span class="fw-bold">{{ .Tag.Total }}</span> <span class="fw-medium text-muted">articles</span></p>
|
||||
<!-- </div> -->
|
||||
<!-- mb-0 to remove the extra bottom margin Bootstrap adds to p class="lead" -->
|
||||
<p class="lead mb-0">{{ .Tag.Description }}</p>
|
||||
|
||||
+18
-3
@@ -2,14 +2,15 @@ package core
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"html"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
||||
"codeberg.org/vnpower/pixivfe/v2/i18n"
|
||||
)
|
||||
|
||||
@@ -86,6 +87,7 @@ type PixivisionTag struct {
|
||||
Title string
|
||||
Description string
|
||||
Articles []PixivisionArticle
|
||||
Total int // The total number of articles
|
||||
}
|
||||
|
||||
// PixivisionCategory represents a category page on Pixivision
|
||||
@@ -195,7 +197,20 @@ func PixivisionGetTag(r *http.Request, id string, page string, lang ...string) (
|
||||
}
|
||||
|
||||
tag.Title = doc.Find(".tdc__header h1").Text()
|
||||
tag.Description = doc.Find(".tdc__description").Text()
|
||||
|
||||
// Extract and process the description
|
||||
fullDescription := doc.Find(".tdc__description").Text()
|
||||
parts := strings.Split(fullDescription, "pixivision") // split once the boilerplate about "pixivision currently has ..." starts
|
||||
tag.Description = strings.TrimSpace(parts[0])
|
||||
|
||||
// Extract total number of articles if available
|
||||
if len(parts) > 1 {
|
||||
re := regexp.MustCompile(`(\d+)\s+article\(s\)`)
|
||||
matches := re.FindStringSubmatch(parts[1])
|
||||
if len(matches) > 1 {
|
||||
tag.Total, _ = strconv.Atoi(matches[1])
|
||||
}
|
||||
}
|
||||
|
||||
// Parse each article in the tag page
|
||||
doc.Find("._article-card").Each(func(i int, s *goquery.Selection) {
|
||||
|
||||
Reference in New Issue
Block a user