|
@@ -21,9 +21,9 @@ router.get('/:id', function (req, res, next) {
|
|
|
let id = req.params.id;
|
|
let id = req.params.id;
|
|
|
utils.validators.validateId(id);
|
|
utils.validators.validateId(id);
|
|
|
|
|
|
|
|
- let cacheKey = `${CACHE_PREFIX}_${req.originalUrl}`;
|
|
|
|
|
|
|
+ let cacheKey = `${CACHE_PREFIX}_detail_${id}`;
|
|
|
let htmlData = await redis.getAsync(cacheKey);
|
|
let htmlData = await redis.getAsync(cacheKey);
|
|
|
- htmlData = null;
|
|
|
|
|
|
|
+ // htmlData = null;
|
|
|
if (!htmlData) {
|
|
if (!htmlData) {
|
|
|
// 详情
|
|
// 详情
|
|
|
let doc = await models.Art
|
|
let doc = await models.Art
|
|
@@ -60,7 +60,7 @@ router.get('/:id', function (req, res, next) {
|
|
|
const recmCollections = recommendColoringPages(doc, coloringList);
|
|
const recmCollections = recommendColoringPages(doc, coloringList);
|
|
|
|
|
|
|
|
// 评论
|
|
// 评论
|
|
|
- const comments = await models.Comment.find({approved: true, page: doc._id}).sort({ createdAt: -1 });
|
|
|
|
|
|
|
+ const comments = await models.Comment.find({ approved: true, page: doc._id }).sort({ createdAt: -1 });
|
|
|
|
|
|
|
|
let data = {
|
|
let data = {
|
|
|
title: `${doc.seoTitle}`,
|
|
title: `${doc.seoTitle}`,
|
|
@@ -118,37 +118,37 @@ router.get('/:id', function (req, res, next) {
|
|
|
* @returns {Array} - 推荐的3个填色页合集
|
|
* @returns {Array} - 推荐的3个填色页合集
|
|
|
*/
|
|
*/
|
|
|
function recommendColoringPages(currentPage, collections) {
|
|
function recommendColoringPages(currentPage, collections) {
|
|
|
- // 计算每个候选页与当前页的标签匹配度
|
|
|
|
|
- const scoredPages = collections.map(page => {
|
|
|
|
|
- const matchedTags = page.tags.filter(tag =>
|
|
|
|
|
- currentPage.tags.some(currentTag =>
|
|
|
|
|
- currentTag.toLowerCase() === tag.toLowerCase()
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
- return {
|
|
|
|
|
- ...page,
|
|
|
|
|
- score: matchedTags.length,
|
|
|
|
|
- matchedTags
|
|
|
|
|
- };
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 按匹配度降序排序
|
|
|
|
|
- scoredPages.sort((a, b) => b.score - a.score);
|
|
|
|
|
-
|
|
|
|
|
- // 收集匹配度大于0的推荐
|
|
|
|
|
- const tagMatchedRecommendations = scoredPages.filter(page => page.score > 0);
|
|
|
|
|
-
|
|
|
|
|
- // 如果标签匹配的推荐不足3个,从剩余的合集中随机选取补足
|
|
|
|
|
- if (tagMatchedRecommendations.length < 3) {
|
|
|
|
|
- const remainingPages = scoredPages.filter(page => page.score === 0);
|
|
|
|
|
- // 打乱剩余页面顺序
|
|
|
|
|
- const shuffledRemaining = remainingPages.sort(() => 0.5 - Math.random());
|
|
|
|
|
- // 补足到3个推荐
|
|
|
|
|
- return [...tagMatchedRecommendations, ...shuffledRemaining].slice(0, 3);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果标签匹配的推荐超过3个,取前3个
|
|
|
|
|
- return tagMatchedRecommendations.slice(0, 3);
|
|
|
|
|
|
|
+ // 计算每个候选页与当前页的标签匹配度
|
|
|
|
|
+ const scoredPages = collections.map(page => {
|
|
|
|
|
+ const matchedTags = page.tags.filter(tag =>
|
|
|
|
|
+ currentPage.tags.some(currentTag =>
|
|
|
|
|
+ currentTag.toLowerCase() === tag.toLowerCase()
|
|
|
|
|
+ )
|
|
|
|
|
+ );
|
|
|
|
|
+ return {
|
|
|
|
|
+ ...page,
|
|
|
|
|
+ score: matchedTags.length,
|
|
|
|
|
+ matchedTags
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // 按匹配度降序排序
|
|
|
|
|
+ scoredPages.sort((a, b) => b.score - a.score);
|
|
|
|
|
+
|
|
|
|
|
+ // 收集匹配度大于0的推荐
|
|
|
|
|
+ const tagMatchedRecommendations = scoredPages.filter(page => page.score > 0);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果标签匹配的推荐不足3个,从剩余的合集中随机选取补足
|
|
|
|
|
+ if (tagMatchedRecommendations.length < 3) {
|
|
|
|
|
+ const remainingPages = scoredPages.filter(page => page.score === 0);
|
|
|
|
|
+ // 打乱剩余页面顺序
|
|
|
|
|
+ const shuffledRemaining = remainingPages.sort(() => 0.5 - Math.random());
|
|
|
|
|
+ // 补足到3个推荐
|
|
|
|
|
+ return [...tagMatchedRecommendations, ...shuffledRemaining].slice(0, 3);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 如果标签匹配的推荐超过3个,取前3个
|
|
|
|
|
+ return tagMatchedRecommendations.slice(0, 3);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
module.exports = router;
|
|
module.exports = router;
|