const models = require('../models'); const translate = require('../config/translate'); const meta = require('../config/meta'); let tags = [ "animal", "scenery", "people", "life", "plant", "girl", "flower", "fantasy", "data_good", "mandala", "food", "special_date", "nature", "cat", "landscape", "dog", "countryside", "forest", "ban", "flowers", "bird", "river", "mountains", "snow", "recommend", "winter", "house", "village", "heart", "Christmas", "garden", "butterfly", "fashion", "summer", "farm", "boy", "place", "sea", "culture", "car", "horse", "lake", "autumn", "tree", "building", "wild", "woman", "room", "park", "ocean", "meadow", "rabbit", "family", "patterns", "home", "mountain", "halloween", "bridge", "friends", "city", "baby", "sunset", "simple", "boat", "window", "plants", "man", "trees", "fruit", "rose", "vacation", "evening", "castle", "snowman", "street", "tiger", "grass", "lady", "child", "vintage", "holiday", "pasture", "deer", "sweet", "night", "beach", "travel", "dress", "fish", "couple", "view", "fairy", "harvest", "yard", "sky", "toys", "wildflowers", "love", "pumpkin", "water", "transportation", "birds", "rocks", "famous", "downtown", "ice", "bear", "spring", "road", "wolf", "unicorn", "lion", "stone", "magic", "cake", "book", "furniture", "children", "fox", "cartoon", "duck", "owl", "squirrel", "sport", "angel", "cub", "decorations", "pond", "sheep", "fence", "interior", "coastline", "beauty", "chicken", "train", "mermaid", "history", "moon", "picnic", "bedroom", "blooming", "sunflower", "mystery", "lovers", "stairs", "walk", "jungle", "livingroom", "thanksgiving", "kingdom", "mother and daughter", "domestic", "mother", "lotus", "dragon", "panda", "pet", "cottage", "tea", "coast", ] function getRandomDarkColor() { // 生成 0 到 127 之间的随机整数,因为较深的颜色分量值较低 const r = Math.floor(Math.random() * 222); const g = Math.floor(Math.random() * 222); const b = Math.floor(Math.random() * 222); // 将 RGB 值转换为十六进制字符串 const toHex = (num) => { const hex = num.toString(16); return hex.length === 1 ? `0${hex}` : hex; }; // 返回 RGB 十六进制颜色字符串 return `#${toHex(r)}${toHex(g)}${toHex(b)}`; } tags = tags.map(e => { return { tag: e, color: getRandomDarkColor() } }); let tagSeoMap = {}; async function getTagSeoTitle(tag, lang) { let item = tagSeoMap[tag]; if (!item) { let doc = await models.TagSeo.findOne({ tag }).lean(); if (doc) { try { doc.seoTitle = JSON.parse(doc.seoTitle); doc.seoDescription = JSON.parse(doc.seoDescription); tagSeoMap[tag] = doc; item = doc; } catch (e) { console.error(e.message); } } } if (item) { return tagSeoMap[tag].seoTitle[lang]; } else { return `${tag} coloring pages | ${translate.printableColoringPage[lang]}`; } } async function getTagSeoDescription(tag, lang) { let item = tagSeoMap[tag]; if (!item) { let doc = await models.TagSeo.findOne({ tag }).lean(); if (doc) { try { doc.seoTitle = JSON.parse(doc.seoTitle); doc.seoDescription = JSON.parse(doc.seoDescription); tagSeoMap[tag] = doc; item = doc; } catch (e) { console.error(e.message); } } } if (item) { return tagSeoMap[tag].seoDescription[lang]; } else { return meta.tagDescription[lang]; } } module.exports = { tags, getTagSeoTitle, getTagSeoDescription };