SEO for collection page.

This commit is contained in:
2025-07-31 16:23:55 +08:00
parent 4ae7a19cc9
commit 63ebbebb02
2 changed files with 28 additions and 1 deletions

View File

@@ -33,6 +33,11 @@ export default function CollectionPage() {
return; return;
} }
if (app.getPreFetchData()?.collection?.id === idInt) {
setCollection(app.getPreFetchData().collection);
return;
}
network.getCollection(idInt).then((res) => { network.getCollection(idInt).then((res) => {
if (res.success) { if (res.success) {
setCollection(res.data!); setCollection(res.data!);
@@ -43,7 +48,7 @@ export default function CollectionPage() {
}); });
} }
}); });
}, [resourcesKey]); }, [id]);
const toBeDeletedRID = useRef<number | null>(null); const toBeDeletedRID = useRef<number | null>(null);

View File

@@ -133,6 +133,28 @@ func serveIndexHtml(c fiber.Ctx) error {
preFetchData = url.PathEscape(string(preFetchDataJson)) preFetchData = url.PathEscape(string(preFetchDataJson))
} }
} }
} else if strings.HasPrefix(path, "/collections/") {
collectionIDStr := strings.TrimPrefix(path, "/collections/")
collectionID, err := strconv.Atoi(collectionIDStr)
if err == nil {
coll, err := service.GetCollectionByID(uint(collectionID))
if err == nil {
title = "Collection: " + coll.Title
description = utils.ArticleToDescription(coll.Article, 256)
if len(coll.Images) > 0 {
preview = fmt.Sprintf("%s/api/image/%d", serverBaseURL, coll.Images[0].ID)
} else {
preview = fmt.Sprintf("%s/api/avatar/%d", serverBaseURL, coll.User.ID)
}
if len(coll.Images) > 0 {
preview = fmt.Sprintf("%s/api/image/%d", serverBaseURL, coll.Images[0].ID)
}
preFetchDataJson, _ := json.Marshal(map[string]interface{}{
"collection": coll,
})
preFetchData = url.PathEscape(string(preFetchDataJson))
}
}
} }
content = strings.ReplaceAll(content, "{{SiteName}}", siteName) content = strings.ReplaceAll(content, "{{SiteName}}", siteName)