guoziyun 11 ay önce
ebeveyn
işleme
2de95ba253

+ 2 - 2
routes/v2/coloring-page-collection.js

@@ -19,7 +19,7 @@ function process() {
       let uri = req.originalUrl.substring(1);
       let cacheKey = `${CACHE_PREFIX}_${uri}`;
       let htmlData = await redis.getAsync(cacheKey);
-      htmlData = null;
+      // htmlData = null;
       if (!htmlData) {
         if (!coloringData[uri].data) {
           let query = {
@@ -32,7 +32,7 @@ function process() {
           common.organizeData(result.data);
           coloringData[uri].data = result.data;
         }
-        const comments = await models.Comment.find({approved: true, page: coloringData[uri].title}).sort({ createdAt: -1 });
+        const comments = await models.Comment.find({ approved: true, page: coloringData[uri].title }).sort({ createdAt: -1 });
         let data = {
           uri: req.originalUrl,
           data: coloringData[uri],

+ 1 - 1
routes/v2/coloring-pages.js

@@ -13,7 +13,7 @@ router.get('/', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_coloring-pages`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,

+ 34 - 34
routes/v2/detail.js

@@ -21,9 +21,9 @@ router.get('/:id', function (req, res, next) {
     let id = req.params.id;
     utils.validators.validateId(id);
 
-    let cacheKey = `${CACHE_PREFIX}_${req.originalUrl}`;
+    let cacheKey = `${CACHE_PREFIX}_detail_${id}`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       // 详情
       let doc = await models.Art
@@ -60,7 +60,7 @@ router.get('/:id', function (req, res, next) {
       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 = {
         title: `${doc.seoTitle}`,
@@ -118,37 +118,37 @@ router.get('/:id', function (req, res, next) {
  * @returns {Array} - 推荐的3个填色页合集
  */
 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;

+ 1 - 1
routes/v2/gallery.js

@@ -30,7 +30,7 @@ router.get('/', function (req, res, next) {
 
     let cacheKey = `${CACHE_PREFIX}_${req.originalUrl}`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let query = {
         page: req.query.page,

+ 7 - 7
routes/v2/index.js

@@ -20,7 +20,7 @@ router.get('/', function (req, res, next) {  // 限制严格一点
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       // 最新上线
       let latest = await models.Art
@@ -142,7 +142,7 @@ router.get('/about', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/about`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -181,7 +181,7 @@ router.get('/app', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/app`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -219,7 +219,7 @@ router.get('/contact', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/contact`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -258,7 +258,7 @@ router.get('/faq', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/faq`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -297,7 +297,7 @@ router.get('/privacy-policy', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/privacy`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -335,7 +335,7 @@ router.get('/terms-of-service', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_/terms-of-service`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,

+ 8 - 8
routes/v2/tips-tricks.js

@@ -18,7 +18,7 @@ router.get('/', function (req, res, next) {  // 限制严格一点
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_tips-tricks`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -56,7 +56,7 @@ router.get('/benefit-of-coloring-pages', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_benefit-of-coloring-pages`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -95,7 +95,7 @@ router.get('/choose-the-right-coloring-tools', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_choose-the-right-coloring-tools`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -133,7 +133,7 @@ router.get('/color-combinations-guide', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_color-combinations-guide`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -172,7 +172,7 @@ router.get('/coloring-techniques-for-beginners', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_coloring-techniques-for-beginners`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -212,7 +212,7 @@ router.get('/how-to-display-your-coloring-masterpieces', function (req, res, nex
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_display-your-coloring-masterpieces`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -251,7 +251,7 @@ router.get('/how-to-color-online', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_how-to-color-online`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,
@@ -289,7 +289,7 @@ router.get('/how-to-color-mandala-coloring-page', function (req, res, next) {
   (async function () {
     let cacheKey = `${CACHE_PREFIX}_how-to-color-online`;
     let htmlData = await redis.getAsync(cacheKey);
-    htmlData = null;
+    // htmlData = null;
     if (!htmlData) {
       let data = {
         uri: req.originalUrl,

+ 1 - 1
routes/v2/video-coloring-page.js

@@ -12,7 +12,7 @@ const CACHE_EXPIRES = 600;
 router.get('/', (req, res, next) => {
   (async function () {
     let uri = req.originalUrl.substring(1);
-    let cacheKey = `${CACHE_PREFIX}_${uri}`;
+    let cacheKey = `${CACHE_PREFIX}_video-coloring-pages`;
     let htmlData = await redis.getAsync(cacheKey);
     htmlData = null;
     if (!htmlData) {

+ 1 - 1
test/fatherday.html

@@ -240,7 +240,7 @@
 
   <div class="container">
     <div class="breadcrumb">
-      <a href="/">Home</a> &gt; <a href="/coloring-pages/">Coloring Pages</a> &gt; Father's Day Coloring Pages
+      <a href="/">Home</a> &gt; <a href="/coloring-pages">Coloring Pages</a> &gt; Father's Day Coloring Pages
     </div>
   </div>
 

+ 1 - 1
test/flower-coloring-page.html

@@ -379,7 +379,7 @@
 
   <div class="container">
     <div class="breadcrumb">
-      <a href="/">Home</a> &gt; <a href="/coloring-pages/">Coloring Pages</a> &gt; Flower Coloring Pages
+      <a href="/">Home</a> &gt; <a href="/coloring-pages">Coloring Pages</a> &gt; Flower Coloring Pages
     </div>
 
     <div class="hero-section">